Skip to content

Commit fe6e4fb

Browse files
committed
automatic refresh added
1 parent b0f9305 commit fe6e4fb

File tree

3 files changed

+113
-14
lines changed

3 files changed

+113
-14
lines changed

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/EspressifToolStartup.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.text.MessageFormat;
88

9-
import org.eclipse.jface.dialogs.MessageDialog;
109
import org.eclipse.swt.SWT;
1110
import org.eclipse.swt.widgets.Display;
1211
import org.eclipse.swt.widgets.MessageBox;
@@ -41,13 +40,14 @@
4140
*/
4241
public class EspressifToolStartup implements IStartup
4342
{
43+
private EimJsonUiChangeHandler eimJsonUiChangeHandler;
4444
@Override
4545
public void earlyStartup()
4646
{
4747
Preferences preferences = org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE
4848
.getNode(UIPlugin.PLUGIN_ID);
4949
ToolInitializer toolInitializer = new ToolInitializer(preferences);
50-
50+
eimJsonUiChangeHandler = new EimJsonUiChangeHandler(preferences);
5151
if (!toolInitializer.isEimInstalled())
5252
{
5353
notifyMissingTools();
@@ -72,16 +72,13 @@ public void earlyStartup()
7272
}
7373

7474
stateChecker.updateLastSeenTimestamp();
75-
EimJsonWatchService.getInstance().addEimJsonChangeListener(new EimJsonUiChangeHandler(preferences));
75+
EimJsonWatchService.getInstance().addEimJsonChangeListener(eimJsonUiChangeHandler);
7676
}
7777

7878
private void showEimJsonStateChangeNotification()
7979
{
80-
Display.getDefault().asyncExec(() -> {
81-
MessageDialog.openInformation(Display.getDefault().getActiveShell(),
82-
com.espressif.idf.ui.tools.Messages.EimJsonChangedMsgTitle,
83-
com.espressif.idf.ui.tools.Messages.EimJsonStateChangedMsgDetail);
84-
});
80+
int response = eimJsonUiChangeHandler.displayMessageToUser();
81+
eimJsonUiChangeHandler.handleUserResponse(response);
8582
}
8683

8784
private void notifyMissingTools()

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ EspIdfManagerReloadBtnToolTip=Reload from disk
77
IDFToolsHandler_ToolsManagerConsole=Espressif IDF Tools Console
88
IDFGuideLinkLabel_Text=Select the version of ESP-IDF you want to use. Click the radio button in Active column next to the version you want. For help in choosing the correct version, visit <a>ESP-IDF Version Guide</a>.
99
EimJsonChangedMsgTitle=ESP-IDF Installation Changed
10-
EimJsonChangedMsgDetail=It looks like the ESP-IDF tools are modified. The Espressif IDE cannot guarantee the consistency. Kindly refresh the installation via ESP-IDF Manager.
10+
EimJsonChangedMsgDetail=It looks like the ESP-IDF tools are modified. The Espressif IDE cannot guarantee the consistency. Do you want to refresh installation?
1111
EimJsonStateChangedMsgDetail=It looks like the ESP-IDF installation was modified since last start. The Espressif IDE cannot guarantee the consistency. Kindly refresh the installation via ESP-IDF Manager.
1212

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/watcher/EimJsonUiChangeHandler.java

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@
44
*******************************************************************************/
55
package com.espressif.idf.ui.tools.watcher;
66

7+
import java.io.IOException;
78
import java.nio.file.Path;
89

9-
import org.eclipse.jface.dialogs.MessageDialog;
10+
import org.eclipse.swt.SWT;
1011
import org.eclipse.swt.widgets.Display;
12+
import org.eclipse.swt.widgets.MessageBox;
13+
import org.eclipse.swt.widgets.Shell;
14+
import org.eclipse.ui.IWorkbenchWindow;
15+
import org.eclipse.ui.PartInitException;
16+
import org.eclipse.ui.console.MessageConsoleStream;
17+
import org.eclipse.ui.ide.IDE;
1118
import org.osgi.service.prefs.Preferences;
1219

20+
import com.espressif.idf.core.logging.Logger;
21+
import com.espressif.idf.core.tools.EimIdfConfiguratinParser;
22+
import com.espressif.idf.core.tools.SetupToolsInIde;
23+
import com.espressif.idf.core.tools.vo.EimJson;
1324
import com.espressif.idf.core.tools.watcher.EimJsonChangeListener;
1425
import com.espressif.idf.core.tools.watcher.EimJsonStateChecker;
26+
import com.espressif.idf.ui.IDFConsole;
27+
import com.espressif.idf.ui.handlers.EclipseHandler;
1528
import com.espressif.idf.ui.tools.Messages;
29+
import com.espressif.idf.ui.tools.manager.ESPIDFManagerEditor;
30+
import com.espressif.idf.ui.tools.manager.EimEditorInput;
1631

1732
/**
1833
* eim_idf.json file ui change handler to notify user for changes.
@@ -23,7 +38,8 @@
2338
public class EimJsonUiChangeHandler implements EimJsonChangeListener
2439
{
2540
private Preferences preferences;
26-
41+
private EimJson eimJson;
42+
2743
public EimJsonUiChangeHandler(Preferences preferences)
2844
{
2945
this.preferences = preferences;
@@ -32,13 +48,99 @@ public EimJsonUiChangeHandler(Preferences preferences)
3248
@Override
3349
public void onJsonFileChanged(Path file)
3450
{
35-
Display.getDefault().asyncExec(() -> {
36-
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.EimJsonChangedMsgTitle,
37-
Messages.EimJsonChangedMsgDetail);
51+
int response = displayMessageToUser();
52+
handleUserResponse(response);
53+
}
54+
55+
public int displayMessageToUser()
56+
{
57+
final int[] response = new int[] {-1};
58+
Display display = Display.getDefault();
59+
display.syncExec(() -> {
60+
Shell shell = display.getActiveShell();
61+
if (shell == null)
62+
{
63+
shell = new Shell(display);
64+
}
65+
MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
66+
messageBox.setText(Messages.EimJsonChangedMsgTitle);
67+
messageBox.setMessage(Messages.EimJsonChangedMsgDetail);
68+
response[0] = messageBox.open();
3869
});
70+
71+
return response[0];
72+
}
3973

74+
public void handleUserResponse(int response)
75+
{
76+
if (response == SWT.YES)
77+
{
78+
try
79+
{
80+
loadEimJson();
81+
if (eimJson.getIdfInstalled().size() == 1)
82+
{
83+
// only one entry in eimJson so we can simply refresh the IDE environment with that.
84+
setupToolsInIde();
85+
}
86+
else
87+
{
88+
// multiple entries in json so launch manager for user to handle this
89+
launchEspIdfManager();
90+
}
91+
}
92+
catch (IOException | PartInitException e)
93+
{
94+
Logger.log(e);
95+
}
96+
}
97+
4098
EimJsonStateChecker checker = new EimJsonStateChecker(preferences);
4199
checker.updateLastSeenTimestamp();
42100
}
101+
102+
private void loadEimJson() throws IOException
103+
{
104+
EimIdfConfiguratinParser eimIdfConfiguratinParser = new EimIdfConfiguratinParser();
105+
eimJson = eimIdfConfiguratinParser.getEimJson(true);
106+
}
107+
108+
109+
110+
private void setupToolsInIde()
111+
{
112+
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(eimJson.getIdfInstalled().get(0), eimJson, getConsoleStream(true), getConsoleStream(false));
113+
setupToolsInIde.schedule();
114+
}
115+
116+
private void launchEspIdfManager() throws PartInitException
117+
{
118+
Display.getDefault().asyncExec(() -> {
119+
IWorkbenchWindow activeww = EclipseHandler.getActiveWorkbenchWindow();
120+
if (activeww != null && activeww.getActivePage() != null)
121+
{
122+
try
123+
{
124+
IDE.openEditor(activeww.getActivePage(), new EimEditorInput(eimJson),
125+
ESPIDFManagerEditor.EDITOR_ID, true);
126+
}
127+
catch (PartInitException e)
128+
{
129+
Logger.log("Failed to open ESP-IDF Manager Editor.");
130+
Logger.log(e);
131+
}
132+
}
133+
else
134+
{
135+
Logger.log("Cannot open ESP-IDF Manager Editor. No active workbench window yet.");
136+
}
137+
});
43138

139+
}
140+
141+
private MessageConsoleStream getConsoleStream(boolean errorStream)
142+
{
143+
IDFConsole idfConsole = new IDFConsole();
144+
return idfConsole.getConsoleStream(Messages.IDFToolsHandler_ToolsManagerConsole, null, errorStream, true);
145+
}
44146
}

0 commit comments

Comments
 (0)