Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 137f2e3

Browse files
authored
Merge pull request #181 from eharris369/157-improveErrorHandling
Issue #157: Show dialog if user tries to create or bind project while installer running
2 parents f199c24 + 83fe7df commit 137f2e3

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/actions/BindProjectAction.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.concurrent.TimeoutException;
1717

1818
import org.eclipse.codewind.core.internal.CodewindManager;
19+
import org.eclipse.codewind.core.internal.CodewindManager.InstallerStatus;
1920
import org.eclipse.codewind.core.internal.CoreUtil;
2021
import org.eclipse.codewind.core.internal.InstallUtil;
2122
import org.eclipse.codewind.core.internal.InstallUtil.InstallStatus;
@@ -57,6 +58,18 @@ public void run(IAction action) {
5758
Logger.logError("BindProjectAction ran but no project was selected"); //$NON-NLS-1$
5859
return;
5960
}
61+
62+
// If the installer is currently running, show a dialog to the user
63+
final InstallerStatus installerStatus = CodewindManager.getManager().getInstallerStatus();
64+
if (installerStatus != null) {
65+
Display.getDefault().asyncExec(new Runnable() {
66+
@Override
67+
public void run() {
68+
CodewindInstall.installerActiveDialog(installerStatus);
69+
}
70+
});
71+
return;
72+
}
6073

6174
try {
6275
if (CodewindInstall.isCodewindInstalled()) {
@@ -68,7 +81,7 @@ public void run(IAction action) {
6881
} catch (InvocationTargetException e) {
6982
Logger.logError("Error trying to set up Codewind to add existing project: " + project.getName(), e);
7083
}
71-
84+
7285
if (connection == null || !connection.isConnected()) {
7386
CoreUtil.openDialog(true, Messages.BindProjectErrorTitle, Messages.BindProjectConnectionError);
7487
return;

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/actions/CodewindInstall.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.eclipse.codewind.core.CodewindCorePlugin;
1919
import org.eclipse.codewind.core.internal.CodewindManager;
20+
import org.eclipse.codewind.core.internal.CodewindManager.InstallerStatus;
2021
import org.eclipse.codewind.core.internal.InstallUtil;
2122
import org.eclipse.codewind.core.internal.InstallUtil.InstallStatus;
2223
import org.eclipse.codewind.core.internal.Logger;
@@ -81,6 +82,29 @@ public static void codewindInstallerDialog(IProject project) {
8182
}
8283
}
8384

85+
public static void installerActiveDialog(InstallerStatus status) {
86+
if (status == null) {
87+
// This should not happen
88+
Logger.logError("The installerActiveDialog method is invoked but the installer status is null");
89+
return;
90+
}
91+
String msg = null;
92+
switch(status) {
93+
case INSTALLING:
94+
case STARTING:
95+
msg = Messages.InstallCodewindInstallingMessage;
96+
break;
97+
case UNINSTALLING:
98+
case STOPPING:
99+
msg = Messages.InstallCodewindUninstallingMessage;
100+
break;
101+
default:
102+
Logger.logError("The installerActiveDialog method is invoked but the installer status is not recognized: " + status);
103+
return;
104+
}
105+
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.InstallCodewindDialogTitle, msg);
106+
}
107+
84108
public static void installCodewind(Runnable prompt) {
85109

86110
try {
@@ -301,6 +325,9 @@ protected IStatus run(IProgressMonitor mon) {
301325
private static IStatus getErrorStatus(ProcessResult result, String msg) {
302326
Logger.logError("Installer failed with return code: " + result.getExitValue() + ", output: " + result.getOutput() + ", error: " + result.getError());
303327
String errorText = result.getError() != null && !result.getError().isEmpty() ? result.getError() : result.getOutput();
328+
if (errorText == null || errorText.trim().isEmpty()) {
329+
errorText = NLS.bind(Messages.InstallCodewindFailNoMessage, result.getExitValue());
330+
}
304331
return getErrorStatus(msg + errorText, null);
305332
}
306333

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/Messages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ public class Messages extends NLS {
107107
public static String InstallCodewindDialogMessage;
108108
public static String InstallCodewindNewProjectMessage;
109109
public static String InstallCodewindAddProjectMessage;
110+
public static String InstallCodewindInstallingMessage;
111+
public static String InstallCodewindUninstallingMessage;
112+
public static String InstallCodewindFailNoMessage;
110113

111114
public static String BindProjectErrorTitle;
112115
public static String BindProjectConnectionError;

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ InstallCodewindDialogTitle=Codewind Installer
109109
InstallCodewindDialogMessage=Codewind requires the installation of Docker containers to run, which might take a few minutes to download. Do you want to complete the installation now?
110110
InstallCodewindNewProjectMessage=Codewind installation is complete, do you want to create a new Codewind project?
111111
InstallCodewindAddProjectMessage=Codewind installation is complete, do you want to add the {0} project to Codewind?
112+
InstallCodewindInstallingMessage=Please wait for Codewind to be fully installed and running before trying to create or add projects.
113+
InstallCodewindUninstallingMessage=Projects cannot be created or added while Codewind is stopping or uninstalling.
114+
InstallCodewindFailNoMessage=The installer failed with error code {0}. Check logs for more information.
112115

113116
SelectProjectTypePageName=Select Project Type
114117
SelectProjectTypePageTitle=Project Type and Language Selection

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/wizards/NewCodewindProjectWizard.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616

1717
import org.eclipse.codewind.core.internal.CodewindApplication;
18+
import org.eclipse.codewind.core.internal.CodewindManager;
1819
import org.eclipse.codewind.core.internal.Logger;
1920
import org.eclipse.codewind.core.internal.connection.CodewindConnection;
2021
import org.eclipse.codewind.core.internal.connection.CodewindConnectionManager;
@@ -64,6 +65,12 @@ public void addPages() {
6465
setWindowTitle(Messages.NewProjectPage_ShellTitle);
6566
newProjectPage = new NewCodewindProjectPage(connection, templateList);
6667
addPage(newProjectPage);
68+
} else if (CodewindManager.getManager().getInstallerStatus() != null) {
69+
// The installer is currently running
70+
CodewindInstall.installerActiveDialog(CodewindManager.getManager().getInstallerStatus());
71+
if (getContainer() != null) {
72+
getContainer().getShell().close();
73+
}
6774
} else {
6875
CodewindInstall.codewindInstallerDialog();
6976
if (getContainer() != null) {

0 commit comments

Comments
 (0)