From c5c518c0b0b594eaa577e2f811fc06fb8ff2fe77 Mon Sep 17 00:00:00 2001 From: pushkar Date: Sun, 12 May 2013 23:32:57 +0800 Subject: [PATCH] Issue #31 : Need a descriptive error message if node settings are not correctly configured. User will now be prompted to open the preferences page. --- .../launch/LaunchConfigurationDelegate.java | 37 ++++++++++++++++++- .../ui/preferences/PreferenceConstants.java | 2 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java b/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java index 3353fc67..da066b64 100644 --- a/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java +++ b/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java @@ -17,6 +17,12 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.debug.core.model.RuntimeProcess; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PreferencesUtil; import org.nodeclipse.debug.util.Constants; import org.nodeclipse.debug.util.NodeDebugUtil; import org.nodeclipse.ui.Activator; @@ -43,10 +49,20 @@ public void launch(ILaunchConfiguration configuration, String mode, } // Using configuration to build command line + + String nodePath = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.NODE_PATH); + + // Check if the node location is correctly configured + File nodeFile = new File(nodePath); + if(!nodeFile.exists()){ + // If the location is not valid than show a dialog which prompts the user to goto the preferences page + showPreferencesDialog(); + return; + } + List cmdLine = new ArrayList(); // Application path should be stored in preference. - cmdLine.add(Activator.getDefault().getPreferenceStore() - .getString(PreferenceConstants.NODE_PATH)); + cmdLine.add(nodePath); if (mode.equals(ILaunchManager.DEBUG_MODE)) { cmdLine.add("--debug-brk=5858"); } @@ -87,6 +103,23 @@ public void launch(ILaunchConfiguration configuration, String mode, } nodeProcess = process; } + + private void showPreferencesDialog() { + Display.getDefault().syncExec(new Runnable() { + public void run() { + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + + MessageDialog dialog = new MessageDialog(shell, "Nodeclipse", null, "Node.js runtime not correctly configured.\n\n" + + "Please goto Window -> Prefrences -> Nodeclipse and configure the correct location", MessageDialog.ERROR, new String[] { "Open Prefrences ...", "Cancel" }, 0); + int result = dialog.open(); + if (result == 0) { + PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(shell, PreferenceConstants.PREFERENCES_PAGE, null, null); + if (pref != null) + pref.open(); + } + } + }); + } public static void terminateNodeProcess() { if(nodeProcess != null) { diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java index 96bb62fb..4f9aa28f 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java @@ -12,5 +12,7 @@ public class PreferenceConstants { public static final String EXPRESS_PATH = "express_pass"; public static final String EXPRESS_VERSION = "express_version"; public static final String COMPLETIONS_JSON_PATH = "completionsjson_path"; + public static final String PREFERENCES_PAGE = "org.nodeclipse.ui.preferences.NodePreferencePage"; + }