Skip to content

Commit 8da5403

Browse files
eharris369GitHub Enterprise
authored andcommitted
Merge pull request #197 from eharris/196-debugDialogs
Issue #196: Prompt user if no project or project closed when restart in debug selected
2 parents 69d3203 + 5f0a730 commit 8da5403

File tree

4 files changed

+105
-6
lines changed

4 files changed

+105
-6
lines changed

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/ImportProjectAction.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.eclipse.core.resources.IProject;
1313
import org.eclipse.core.resources.ResourcesPlugin;
1414
import org.eclipse.core.runtime.IPath;
15+
import org.eclipse.core.runtime.jobs.Job;
1516
import org.eclipse.jface.action.IAction;
1617
import org.eclipse.jface.viewers.ISelection;
1718
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -59,6 +60,15 @@ public void run(IAction action) {
5960
return;
6061
}
6162

63+
importProject(app);
64+
}
65+
66+
@Override
67+
public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
68+
// nothing
69+
}
70+
71+
public static void importProject(MicroclimateApplication app) {
6272
try {
6373
IPath path = app.fullLocalPath;
6474
SmartImportJob importJob = new SmartImportJob(path.toFile(), null, true, false);
@@ -69,9 +79,4 @@ public void run(IAction action) {
6979
return;
7080
}
7181
}
72-
73-
@Override
74-
public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
75-
// nothing
76-
}
7782
}

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/RestartDebugModeAction.java

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@
99

1010
package com.ibm.microclimate.ui.internal.actions;
1111

12+
import org.eclipse.core.resources.IProject;
13+
import org.eclipse.core.resources.ResourcesPlugin;
14+
import org.eclipse.core.runtime.CoreException;
15+
import org.eclipse.core.runtime.IProgressMonitor;
16+
import org.eclipse.core.runtime.IStatus;
17+
import org.eclipse.core.runtime.Status;
18+
import org.eclipse.core.runtime.jobs.Job;
1219
import org.eclipse.debug.core.DebugPlugin;
1320
import org.eclipse.debug.core.ILaunch;
1421
import org.eclipse.debug.core.ILaunchManager;
1522
import org.eclipse.jface.action.IAction;
23+
import org.eclipse.jface.dialogs.MessageDialog;
1624
import org.eclipse.jface.viewers.ISelection;
1725
import org.eclipse.jface.viewers.IStructuredSelection;
26+
import org.eclipse.osgi.util.NLS;
27+
import org.eclipse.swt.widgets.Display;
1828
import org.eclipse.swt.widgets.Event;
29+
import org.eclipse.swt.widgets.Shell;
1930
import org.eclipse.ui.IActionDelegate2;
2031
import org.eclipse.ui.IObjectActionDelegate;
2132
import org.eclipse.ui.IViewActionDelegate;
@@ -27,6 +38,7 @@
2738
import com.ibm.microclimate.core.internal.MCUtil;
2839
import com.ibm.microclimate.core.internal.constants.AppState;
2940
import com.ibm.microclimate.core.internal.constants.StartMode;
41+
import com.ibm.microclimate.ui.MicroclimateUIPlugin;
3042
import com.ibm.microclimate.ui.internal.messages.Messages;
3143

3244
public class RestartDebugModeAction implements IObjectActionDelegate, IViewActionDelegate, IActionDelegate2 {
@@ -62,6 +74,40 @@ public void run(IAction action) {
6274
MCLogger.logError("RestartDebugModeAction ran but no Microclimate application was selected");
6375
return;
6476
}
77+
78+
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(app.name);
79+
if (project == null || !project.exists()) {
80+
int result = openDialog(NLS.bind(Messages.ProjectNotImportedDialogTitle, app.name), NLS.bind(Messages.ProjectNotImportedDialogMsg, app.name));
81+
if (result == 0) {
82+
// Import the project
83+
ImportProjectAction.importProject(app);
84+
} else if (result == 2) {
85+
// Cancel selected
86+
return;
87+
}
88+
} else if (!project.isOpen()) {
89+
int result = openDialog(NLS.bind(Messages.ProjectClosedDialogTitle, app.name), NLS.bind(Messages.ProjectClosedDialogMsg, app.name));
90+
if (result == 0) {
91+
// Open the project
92+
Job job = new Job(NLS.bind(Messages.ProjectOpenJob, app.name)) {
93+
@Override
94+
protected IStatus run(IProgressMonitor monitor) {
95+
try {
96+
project.open(monitor);
97+
return Status.OK_STATUS;
98+
} catch (CoreException e) {
99+
return new Status(IStatus.ERROR, MicroclimateUIPlugin.PLUGIN_ID,
100+
NLS.bind(Messages.ProjectOpenError, app.name), e);
101+
}
102+
}
103+
};
104+
job.setPriority(Job.LONG);
105+
job.schedule();
106+
} else if (result == 2) {
107+
// Cancel selected
108+
return;
109+
}
110+
}
65111

66112
try {
67113
ILaunch launch = app.getLaunch();
@@ -78,7 +124,31 @@ public void run(IAction action) {
78124
return;
79125
}
80126
}
81-
127+
128+
/*
129+
* Dialog which asks the user a question and they can select Yes, No
130+
* or Cancel.
131+
* Returns:
132+
* 0 - user selected Yes
133+
* 1 - user selected No
134+
* 2 - user selected Cancel
135+
*/
136+
private static int openDialog(String title, String msg) {
137+
final int[] result = new int[1];
138+
Display.getDefault().syncExec(new Runnable() {
139+
@Override
140+
public void run() {
141+
Shell shell = Display.getDefault().getActiveShell();
142+
String[] buttonLabels = new String[] {Messages.DialogYesButton, Messages.DialogNoButton, Messages.DialogCancelButton};
143+
MessageDialog dialog = new MessageDialog(shell, title, MicroclimateUIPlugin.getImage(MicroclimateUIPlugin.MICROCLIMATE_ICON),
144+
msg, MessageDialog.QUESTION, buttonLabels, 0);
145+
result[0] = dialog.open();
146+
}
147+
});
148+
149+
return result[0];
150+
}
151+
82152
@Override
83153
public void runWithEvent(IAction action, Event event) {
84154
run(action);

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/Messages.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public class Messages extends NLS {
6767
public static String OpenMicroclimateUIError;
6868
public static String OpenMicroclimateUINotConnectedError;
6969

70+
public static String DialogYesButton;
71+
public static String DialogNoButton;
72+
public static String DialogCancelButton;
73+
74+
public static String ProjectNotImportedDialogTitle;
75+
public static String ProjectNotImportedDialogMsg;
76+
77+
public static String ProjectClosedDialogTitle;
78+
public static String ProjectClosedDialogMsg;
79+
public static String ProjectOpenJob;
80+
public static String ProjectOpenError;
81+
7082
static {
7183
// initialize resource bundle
7284
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/messages.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,15 @@ ImportProjectError=An error occurred while importing the {0} project.
5959
StartBuildError=An error occurred while starting a build for the {0} project.
6060
OpenMicroclimateUIError=An error occurred while opening the Microclimate UI.
6161
OpenMicroclimateUINotConnectedError=The Microclimate UI could not be reached at {0}. Check that Microclimate is running.
62+
63+
DialogYesButton=Yes
64+
DialogNoButton=No
65+
DialogCancelButton=Cancel
66+
67+
ProjectNotImportedDialogTitle=The {0} project is not imported into Eclipse
68+
ProjectNotImportedDialogMsg=There will be no source available for debugging if the project is not imported. Do you want to import the {0} project?
69+
70+
ProjectClosedDialogTitle=The {0} project is closed in Eclipse
71+
ProjectClosedDialogMsg=There will be no source available for debugging if the project is not opened. Do you want to open the {0} project?
72+
ProjectOpenJob=Open project {0}
73+
ProjectOpenError=An error occurred while trying to open the {0} project

0 commit comments

Comments
 (0)