Skip to content

Commit 4b7a26a

Browse files
author
jan
committed
Add button to update the json files
1 parent 7065845 commit 4b7a26a

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed

io.sloeber.core/src/io/sloeber/arduinoFramework/api/BoardsManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.nio.file.Files;
1717
import java.nio.file.Paths;
1818
import java.nio.file.StandardCopyOption;
19+
import java.time.Instant;
1920
import java.util.ArrayList;
2021
import java.util.Arrays;
2122
import java.util.Collection;
@@ -871,9 +872,12 @@ public static IArduinoPackage getPackageByProvider(String packager) {
871872
public static void update(boolean reloadFromInternet) {
872873
synchronized (packageIndices) {
873874
myIsUpdating =true;
874-
if (myIsDirty) {
875+
if (myIsDirty || reloadFromInternet) {
875876
downloadJsons(reloadFromInternet);
876877
readJsons();
878+
if(reloadFromInternet) {
879+
ConfigurationPreferences.setLatestUpdateTime(Instant.now());
880+
}
877881

878882
}
879883

io.sloeber.core/src/io/sloeber/core/Activator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ private static synchronized void startup_BoardsManager(IProgressMonitor monitor)
478478
// boolean needsUpdate = currentTime>(requestedDelay+latestUpdate);
479479
if(needsUpdate) {
480480
BoardsManager.update(true );
481-
ConfigurationPreferences.setLatestUpdateTime(currentTime);
482481
}else {
483482
BoardsManager.update(false );
484483
}

io.sloeber.core/src/io/sloeber/core/api/ConfigurationPreferences.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ private static Instant getInstant(String key, Instant defaultValue) {
129129
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(NODE_ARDUINO);
130130
long ret = myScope.getLong(key, 0);
131131
if(ret==0) {
132+
setInstant( key, defaultValue);
132133
return defaultValue;
133134
}
134135
return Instant.ofEpochSecond(ret);

io.sloeber.ui/src/io/sloeber/ui/Messages.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,16 @@ public class Messages extends NLS {
7272

7373
public static String PreferencePage_Internal_Behaviour_Group_Title;
7474

75+
public static String PreferencePage_json_Download_date;
76+
7577
public static String PreferencePage_months;
7678

7779
public static String PreferencePage_Network_Group_Title;
7880

7981
public static String PreferencePage_UI_Behaviour_Group_Title;
8082

83+
public static String PreferencePage_Update_json_files_now;
84+
8185
public static String PreferencePage_update_interval;
8286

8387
public static String PreferencePage_weeks;

io.sloeber.ui/src/io/sloeber/ui/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ PlatformSelectionPage_hide_third_party_url=Hide 3th party json files
88
PreferencePage_centuries=centuries
99
PreferencePage_days=days
1010
PreferencePage_Internal_Behaviour_Group_Title=Internal behaviour
11+
PreferencePage_json_Download_date=json download date
1112
PreferencePage_months=months
1213
PreferencePage_Network_Group_Title=Stuff that needs a network
1314
PreferencePage_UI_Behaviour_Group_Title=UI behaviour
15+
PreferencePage_Update_json_files_now=update json files now
1416
PreferencePage_update_interval=Update json files every
1517
PreferencePage_weeks=weeks
1618
PreferencePage_years=years

io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import java.io.File;
66
import java.time.Duration;
7+
import java.time.Instant;
8+
import java.time.ZoneId;
9+
import java.time.format.DateTimeFormatter;
710
import java.util.ArrayList;
811

912
import org.eclipse.core.runtime.IPath;
@@ -19,6 +22,8 @@
1922
import org.eclipse.jface.resource.FontRegistry;
2023
import org.eclipse.jface.resource.JFaceResources;
2124
import org.eclipse.swt.SWT;
25+
import org.eclipse.swt.events.SelectionEvent;
26+
import org.eclipse.swt.events.SelectionListener;
2227
import org.eclipse.swt.graphics.Font;
2328
import org.eclipse.swt.layout.GridData;
2429
import org.eclipse.swt.layout.GridLayout;
@@ -342,11 +347,44 @@ protected void createFieldEditors() {
342347
gd17.horizontalSpan=2;
343348
nuberLabel.setLayoutData(gd17);
344349

350+
351+
Label lastJsonUpdateTimeLabel = new Label(netWorkbox, SWT.BEGINNING);
352+
lastJsonUpdateTimeLabel.setText(Messages.PreferencePage_json_Download_date);
353+
GridData gd19 = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
354+
gd19.horizontalSpan=2;
355+
lastJsonUpdateTimeLabel.setLayoutData(gd19);
356+
Label lastJsonUpdateTime = new Label(netWorkbox, SWT.BEGINNING);
357+
lastJsonUpdateTime.setText(getLatestJsonUpdateTime());
358+
Button updateJsonFileNowButton =new Button(netWorkbox, SWT.PUSH | SWT.LEFT );
359+
updateJsonFileNowButton.setText(Messages.PreferencePage_Update_json_files_now);
360+
updateJsonFileNowButton.addSelectionListener(new SelectionListener() {
361+
362+
@Override
363+
public void widgetSelected(SelectionEvent e) {
364+
BoardsManager.update(true);
365+
lastJsonUpdateTime.setText(getLatestJsonUpdateTime());
366+
}
367+
368+
@Override
369+
public void widgetDefaultSelected(SelectionEvent e) {
370+
// TODO Auto-generated method stub
371+
372+
}
373+
});
374+
375+
345376
myBonjourCheckBox.setSelection(ConfigurationPreferences.useBonjour());
346377
setJsonDurationComposites(ConfigurationPreferences.getJsonUpdateDelay());
347378

348379
}
349380

381+
private static String getLatestJsonUpdateTime() {
382+
DateTimeFormatter formatter =
383+
DateTimeFormatter.ofPattern( "uuuu-MM-dd HH-mm" ) //$NON-NLS-1$
384+
.withZone(ZoneId.systemDefault());
385+
Instant instant =ConfigurationPreferences.getLatestJsonUpdateTime();
386+
return formatter.format(instant);
387+
}
350388
/**
351389
* testStatus test whether the provided information is OK. Here the code
352390
* checks whether there is a hardware\arduino\board.txt file under the

0 commit comments

Comments
 (0)