99
1010package 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 ;
1219import org .eclipse .debug .core .DebugPlugin ;
1320import org .eclipse .debug .core .ILaunch ;
1421import org .eclipse .debug .core .ILaunchManager ;
1522import org .eclipse .jface .action .IAction ;
23+ import org .eclipse .jface .dialogs .MessageDialog ;
1624import org .eclipse .jface .viewers .ISelection ;
1725import org .eclipse .jface .viewers .IStructuredSelection ;
26+ import org .eclipse .osgi .util .NLS ;
27+ import org .eclipse .swt .widgets .Display ;
1828import org .eclipse .swt .widgets .Event ;
29+ import org .eclipse .swt .widgets .Shell ;
1930import org .eclipse .ui .IActionDelegate2 ;
2031import org .eclipse .ui .IObjectActionDelegate ;
2132import org .eclipse .ui .IViewActionDelegate ;
2738import com .ibm .microclimate .core .internal .MCUtil ;
2839import com .ibm .microclimate .core .internal .constants .AppState ;
2940import com .ibm .microclimate .core .internal .constants .StartMode ;
41+ import com .ibm .microclimate .ui .MicroclimateUIPlugin ;
3042import com .ibm .microclimate .ui .internal .messages .Messages ;
3143
3244public 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 );
0 commit comments