|
11 | 11 |
|
12 | 12 | package com.ibm.microclimate.ui.internal.wizards; |
13 | 13 |
|
| 14 | +import java.io.IOException; |
14 | 15 | import java.util.List; |
15 | 16 |
|
16 | 17 | import org.eclipse.core.resources.IProject; |
17 | 18 | import org.eclipse.core.resources.ResourcesPlugin; |
| 19 | +import org.eclipse.core.runtime.IProgressMonitor; |
| 20 | +import org.eclipse.core.runtime.IStatus; |
| 21 | +import org.eclipse.core.runtime.Status; |
| 22 | +import org.eclipse.core.runtime.jobs.Job; |
18 | 23 | import org.eclipse.jface.wizard.Wizard; |
19 | 24 | import org.eclipse.osgi.util.NLS; |
20 | 25 | import org.eclipse.swt.widgets.Display; |
| 26 | +import org.json.JSONException; |
21 | 27 |
|
22 | 28 | import com.ibm.microclimate.core.internal.MCLogger; |
23 | 29 | import com.ibm.microclimate.core.internal.MCUtil; |
24 | 30 | import com.ibm.microclimate.core.internal.MicroclimateApplication; |
25 | 31 | import com.ibm.microclimate.core.internal.connection.IOperationHandler; |
26 | 32 | import com.ibm.microclimate.core.internal.connection.MicroclimateConnection; |
27 | 33 | import com.ibm.microclimate.core.internal.console.ProjectTemplateInfo; |
| 34 | +import com.ibm.microclimate.ui.MicroclimateUIPlugin; |
28 | 35 | import com.ibm.microclimate.ui.internal.actions.ImportProjectAction; |
29 | 36 | import com.ibm.microclimate.ui.internal.messages.Messages; |
30 | 37 | import com.ibm.microclimate.ui.internal.views.ViewHelper; |
@@ -53,51 +60,56 @@ public boolean performFinish() { |
53 | 60 | return false; |
54 | 61 | } |
55 | 62 |
|
56 | | - ProjectTemplateInfo info = newProjectPage.getProjectTemplateInfo(); |
57 | | - String name = newProjectPage.getProjectName(); |
| 63 | + final ProjectTemplateInfo info = newProjectPage.getProjectTemplateInfo(); |
| 64 | + final String name = newProjectPage.getProjectName(); |
58 | 65 | if (info == null || name == null) { |
59 | 66 | MCLogger.logError("The project type or name was null for the new project wizard"); |
60 | 67 | return false; |
61 | 68 | } |
62 | 69 |
|
63 | | - try { |
64 | | - final boolean importProject = newProjectPage.importProject(); |
65 | | - connection.getMCSocket().registerProjectCreateHandler(name, new IOperationHandler() { |
66 | | - @Override |
67 | | - public void operationComplete(boolean passed, String msg) { |
68 | | - connection.getMCSocket().deregisterProjectCreateHandler(name); |
69 | | - if (passed) { |
70 | | - MicroclimateApplication app = connection.getAppByName(name); |
71 | | - if (app != null) { |
72 | | - Display.getDefault().asyncExec(new Runnable() { |
73 | | - @Override |
74 | | - public void run() { |
75 | | - ViewHelper.expandConnection(connection); |
76 | | - } |
77 | | - }); |
78 | | - if (importProject) { |
79 | | - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(app.name); |
80 | | - if (project == null || !project.exists()) { |
81 | | - ImportProjectAction.importProject(app); |
82 | | - } else { |
83 | | - // This should not happen since the wizard checks for this |
84 | | - MCLogger.logError("The project cannot be imported because a project already exists with the name: " + app.name); |
85 | | - } |
| 70 | + final boolean importProject = newProjectPage.importProject(); |
| 71 | + connection.getMCSocket().registerProjectCreateHandler(name, new IOperationHandler() { |
| 72 | + @Override |
| 73 | + public void operationComplete(boolean passed, String msg) { |
| 74 | + connection.getMCSocket().deregisterProjectCreateHandler(name); |
| 75 | + if (passed) { |
| 76 | + MicroclimateApplication app = connection.getAppByName(name); |
| 77 | + if (app != null) { |
| 78 | + Display.getDefault().asyncExec(new Runnable() { |
| 79 | + @Override |
| 80 | + public void run() { |
| 81 | + ViewHelper.expandConnection(connection); |
| 82 | + } |
| 83 | + }); |
| 84 | + if (importProject) { |
| 85 | + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(app.name); |
| 86 | + if (project == null || !project.exists()) { |
| 87 | + ImportProjectAction.importProject(app); |
| 88 | + } else { |
| 89 | + // This should not happen since the wizard checks for this |
| 90 | + MCLogger.logError("The project cannot be imported because a project already exists with the name: " + app.name); |
86 | 91 | } |
87 | | - return; |
88 | | - } else { |
89 | | - MCLogger.logError("An import operation was requested but the application could not be found for: " + name); |
90 | 92 | } |
| 93 | + return; |
| 94 | + } else { |
| 95 | + MCLogger.logError("An import operation was requested but the application could not be found for: " + name); |
91 | 96 | } |
92 | 97 | } |
93 | | - }); |
94 | | - connection.requestProjectCreate(info, name); |
95 | | - return true; |
96 | | - } catch (Exception e) { |
97 | | - MCLogger.logError("An error occured trying to create a project with type: " + info.getExtension() + ", and name: " + name, e); |
98 | | - MCUtil.openDialog(true, Messages.NewProjectPage_ProjectCreateErrorTitle, |
99 | | - NLS.bind(Messages.NewProjectPage_ProjectCreateErrorMsg, new String[] {name, e.getMessage()})); |
100 | | - return false; |
101 | | - } |
| 98 | + } |
| 99 | + }); |
| 100 | + Job job = new Job(NLS.bind(Messages.NewProjectWizard_CreateProjectJobTitle, name)) { |
| 101 | + @Override |
| 102 | + protected IStatus run(IProgressMonitor monitor) { |
| 103 | + try { |
| 104 | + connection.requestProjectCreate(info, name); |
| 105 | + return Status.OK_STATUS; |
| 106 | + } catch (Exception e) { |
| 107 | + MCLogger.logError("An error occurred creating project: " + name, e); |
| 108 | + return new Status(IStatus.ERROR, MicroclimateUIPlugin.PLUGIN_ID, NLS.bind(Messages.NewProjectWizard_ProjectCreateErrorMsg, name), e); |
| 109 | + } |
| 110 | + } |
| 111 | + }; |
| 112 | + job.schedule(); |
| 113 | + return true; |
102 | 114 | } |
103 | 115 | } |
0 commit comments