Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void run()
try
{
watchService.close();
Logger.log("File Watch Service close"); //$NON-NLS-1$
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.text.MessageFormat;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
Expand Down Expand Up @@ -41,13 +40,17 @@
*/
public class EspressifToolStartup implements IStartup
{
private EimJsonUiChangeHandler eimJsonUiChangeHandler;
@Override
public void earlyStartup()
{
Preferences preferences = org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE
.getNode(UIPlugin.PLUGIN_ID);
ToolInitializer toolInitializer = new ToolInitializer(preferences);

EimJsonStateChecker stateChecker = new EimJsonStateChecker(preferences);
eimJsonUiChangeHandler = new EimJsonUiChangeHandler(preferences);
stateChecker.updateLastSeenTimestamp();
EimJsonWatchService.getInstance().addEimJsonChangeListener(eimJsonUiChangeHandler);
if (!toolInitializer.isEimInstalled())
{
notifyMissingTools();
Expand All @@ -65,23 +68,16 @@ public void earlyStartup()
promptUserToOpenToolManager(eimJson);
}

EimJsonStateChecker stateChecker = new EimJsonStateChecker(preferences);
if (stateChecker.wasModifiedSinceLastRun())
{
showEimJsonStateChangeNotification();
}

stateChecker.updateLastSeenTimestamp();
EimJsonWatchService.getInstance().addEimJsonChangeListener(new EimJsonUiChangeHandler(preferences));
}

private void showEimJsonStateChangeNotification()
{
Display.getDefault().asyncExec(() -> {
MessageDialog.openInformation(Display.getDefault().getActiveShell(),
com.espressif.idf.ui.tools.Messages.EimJsonChangedMsgTitle,
com.espressif.idf.ui.tools.Messages.EimJsonStateChangedMsgDetail);
});
int response = eimJsonUiChangeHandler.displayMessageToUser();
eimJsonUiChangeHandler.handleUserResponse(response);
}

private void notifyMissingTools()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class Messages extends NLS
public static String EimJsonChangedMsgDetail;
public static String EimJsonStateChangedMsgDetail;

public static String MsgYes;
public static String MsgNo;

static
{
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ EspIdfManagerReloadBtnToolTip=Reload from disk
IDFToolsHandler_ToolsManagerConsole=Espressif IDF Tools Console
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>.
EimJsonChangedMsgTitle=ESP-IDF Installation Changed
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.
EimJsonChangedMsgDetail=It seems that the ESP-IDF tools have been modified. If you just installed ESP-IDF we recommend refereshing via ESP-IDF Manager . Would you like to proceed with the update?
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.

MsgYes=Yes
MsgNo=No
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,31 @@
*******************************************************************************/
package com.espressif.idf.ui.tools.watcher;

import java.io.IOException;
import java.nio.file.Path;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.ui.ide.IDE;
import org.osgi.service.prefs.Preferences;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.tools.EimIdfConfiguratinParser;
import com.espressif.idf.core.tools.SetupToolsInIde;
import com.espressif.idf.core.tools.vo.EimJson;
import com.espressif.idf.core.tools.watcher.EimJsonChangeListener;
import com.espressif.idf.core.tools.watcher.EimJsonStateChecker;
import com.espressif.idf.ui.IDFConsole;
import com.espressif.idf.ui.handlers.EclipseHandler;
import com.espressif.idf.ui.tools.Messages;
import com.espressif.idf.ui.tools.SetupToolsJobListener;
import com.espressif.idf.ui.tools.manager.ESPIDFManagerEditor;
import com.espressif.idf.ui.tools.manager.EimEditorInput;
import com.espressif.idf.ui.tools.manager.pages.ESPIDFMainTablePage;

/**
* eim_idf.json file ui change handler to notify user for changes.
Expand All @@ -23,6 +39,7 @@
public class EimJsonUiChangeHandler implements EimJsonChangeListener
{
private Preferences preferences;
private EimJson eimJson;

public EimJsonUiChangeHandler(Preferences preferences)
{
Expand All @@ -32,13 +49,102 @@ public EimJsonUiChangeHandler(Preferences preferences)
@Override
public void onJsonFileChanged(Path file)
{
Display.getDefault().asyncExec(() -> {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.EimJsonChangedMsgTitle,
Messages.EimJsonChangedMsgDetail);
int response = displayMessageToUser();
handleUserResponse(response);
}

public int displayMessageToUser()
{
final int[] response = new int[] { -1 };
Display display = Display.getDefault();
display.syncExec(() -> {
Shell shell = display.getActiveShell();
if (shell == null)
{
shell = new Shell(display);
}
Comment on lines +60 to +65
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Display.getDefault().getActiveShell() should work here considering that workbench has been already initilized, do you see any issue here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use EclipseUtil.getShell()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolipakakondal yes since the handler can be called from early startup class it causes NPE because the shell is not available at times

MessageDialog messageDialog = new MessageDialog(shell, Messages.EimJsonChangedMsgTitle, null,
Messages.EimJsonChangedMsgDetail, MessageDialog.WARNING, 0,
new String[] { Messages.MsgYes, Messages.MsgNo });
response[0] = messageDialog.open();
});

return response[0];
}

public void handleUserResponse(int response)
{
if (response == 0)
{
try
{
loadEimJson();
if (eimJson.getIdfInstalled().size() == 1)
{
// only one entry in eimJson so we can simply refresh the IDE environment with that.
setupToolsInIde();
}
else
{
// multiple entries in json so launch manager for user to handle this
launchEspIdfManager();
}
}
catch (
IOException
| PartInitException e)
{
Logger.log(e);
}
}

EimJsonStateChecker checker = new EimJsonStateChecker(preferences);
checker.updateLastSeenTimestamp();
}

private void loadEimJson() throws IOException
{
EimIdfConfiguratinParser eimIdfConfiguratinParser = new EimIdfConfiguratinParser();
eimJson = eimIdfConfiguratinParser.getEimJson(true);
}

private void setupToolsInIde()
{
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(eimJson.getIdfInstalled().get(0), eimJson,
getConsoleStream(true), getConsoleStream(false));
SetupToolsJobListener toolsActivationJobListener = new SetupToolsJobListener(ESPIDFMainTablePage.getInstance(eimJson),
setupToolsInIde);
setupToolsInIde.addJobChangeListener(toolsActivationJobListener);
setupToolsInIde.schedule();
}

private void launchEspIdfManager() throws PartInitException
{
Display.getDefault().asyncExec(() -> {
IWorkbenchWindow activeww = EclipseHandler.getActiveWorkbenchWindow();
if (activeww == null || activeww.getActivePage() == null)
{
Logger.log("Cannot open ESP-IDF Manager. No active workbench window or active page.");
return;
}

try
{
IDE.openEditor(activeww.getActivePage(), new EimEditorInput(eimJson), ESPIDFManagerEditor.EDITOR_ID,
true);
}
catch (PartInitException e)
{
Logger.log("Failed to open ESP-IDF Manager Editor.");
Logger.log(e);
}
});

}

private MessageConsoleStream getConsoleStream(boolean errorStream)
{
IDFConsole idfConsole = new IDFConsole();
return idfConsole.getConsoleStream(Messages.IDFToolsHandler_ToolsManagerConsole, null, errorStream, true);
}
}
Loading