diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java index 03d5972edee..58d2e62a542 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/E4Workbench.java @@ -20,6 +20,7 @@ import java.util.Hashtable; import java.util.List; import java.util.UUID; +import org.eclipse.core.runtime.ILog; import org.eclipse.e4.core.commands.ExpressionContext; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.EclipseContextFactory; @@ -201,6 +202,12 @@ public boolean close() { @Override public boolean restart() { + if (!canRestart()) { + String message = "Can't restart the workbench. This application was started with the '--launcher.noRestart' argument. Shutdown and start again manually."; //$NON-NLS-1$ + ILog.get().error(message); + return false; + } + this.restart = true; return close(); } @@ -212,6 +219,22 @@ public boolean isRestart() { return restart; } + /** + * Returns whether the workbench can be {@link #restart() restarted}. + * + *

+ * It can not be restarted if the --launcher.noRestart argument is + * given. + *

+ * + * @return true if the workbench can be restarted. + */ + public static boolean canRestart() { + String commands = System.getProperty("eclipse.commands", ""); //$NON-NLS-1$ //$NON-NLS-2$ + String NO_RESTART_ARGUMENT = "--launcher.noRestart"; //$NON-NLS-1$ + return commands.lines().map(String::strip).noneMatch(NO_RESTART_ARGUMENT::equals); + } + /** * @return a context that can be used to lookup OSGi services */ diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java index a62cce27627..8a406791ac4 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java @@ -28,6 +28,9 @@ import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Category; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; @@ -50,6 +53,7 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; +import javax.xml.crypto.dsig.Transform; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.CommandManager; import org.eclipse.core.commands.ExecutionException; @@ -148,13 +152,7 @@ import org.eclipse.swt.graphics.DeviceData; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.graphics.Transform; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IDecoratorManager; import org.eclipse.ui.IEditorInput; @@ -1404,6 +1402,11 @@ public boolean close() { */ /* package */ boolean close(int returnCode, final boolean force) { + if (returnCode == PlatformUI.RETURN_RESTART && !E4Workbench.canRestart()) { + informNoRestart(); + return false; + } + this.returnCode = returnCode; final boolean[] ret = new boolean[1]; BusyIndicator.showWhile(null, () -> ret[0] = busyClose(force)); @@ -2555,11 +2558,21 @@ public WorkbenchWindow openWorkbenchWindow(IAdaptable input, IPerspectiveDescrip @Override public boolean restart() { + if (!E4Workbench.canRestart()) { + informNoRestart(); + return false; + } + return close(PlatformUI.RETURN_RESTART, false); } @Override public boolean restart(boolean useCurrrentWorkspace) { + if (!E4Workbench.canRestart()) { + informNoRestart(); + return false; + } + if (Platform.inDevelopmentMode()) { // In development mode, command line parameters cannot be changed and restart // will always be EXIT_RESTART. Also see setRestartArguments method @@ -2583,6 +2596,18 @@ public boolean restart(boolean useCurrrentWorkspace) { return close(PlatformUI.RETURN_RESTART, false); } + /** + * Inform the user that the workbench can't be restarted. If the workbench UI is + * not available, this method does nothing. + */ + public void informNoRestart() { + final Display display = getDisplay(); + if (display != null && !display.isDisposed()) { + MessageDialog.openError(null, WorkbenchMessages.Workbench_CantRestart_Title, + WorkbenchMessages.Workbench_CantRestart_Message); + } + } + /** * Create and return a string with command line options for eclipse.exe that * will launch a new workbench that is the same as the currently running one, diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java index d0a2acb25ca..dbddbbb6b6b 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java @@ -586,6 +586,9 @@ public class WorkbenchMessages extends NLS { public static String Workbench_NeedsClose_Title; public static String Workbench_NeedsClose_Message; + public static String Workbench_CantRestart_Title; + public static String Workbench_CantRestart_Message; + public static String ErrorPreferencePage_errorMessage; public static String ListSelection_title; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties index c0ffd410a32..d51bc7b5021 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties @@ -554,6 +554,10 @@ InstallationDialog_ShellTitle={0} Installation Details Workbench_NeedsClose_Title = Restart Needed Workbench_NeedsClose_Message = A required plug-in is no longer available and the Workbench needs to be restarted. You will be prompted to save if there is any unsaved work. +Workbench_CantRestart_Title = Restart unavailable +Workbench_CantRestart_Message = Can't restart the workbench. This application was started with the '--launcher.noRestart' argument.\n\ +Shutdown and start again manually. + ErrorPreferencePage_errorMessage = An error has occurred when creating this preference page. ListSelection_title = Selection Needed