1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.ui.wizards;
26
27 import java.lang.reflect.InvocationTargetException;
28
29 import org.eclipse.core.resources.*;
30 import org.eclipse.core.runtime.*;
31 import org.eclipse.jface.dialogs.MessageDialog;
32 import org.eclipse.jface.wizard.WizardPage;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.events.*;
35 import org.eclipse.swt.layout.*;
36 import org.eclipse.swt.widgets.*;
37 import org.eclipse.ui.INewWizard;
38 import org.eclipse.ui.actions.WorkspaceModifyOperation;
39 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
40 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
41 import org.wsmostudio.runtime.WSMORuntime;
42 import org.wsmostudio.ui.ProjectNamespaceAction;
43
44 /***
45 * An <code>org.eclipse.ui.newWizards</code> extension which creates a new
46 * project in the workspace. The implementation inherits most of its functionality
47 * from <code>BasicNewProjectResourceWizard</code> class.
48 *
49 * @author not attributable
50 * @version $Revision: 571 $ $Date: 2006-02-07 13:40:22 +0200 $
51 */
52
53 public class NewWSMOProjectWizard extends BasicNewProjectResourceWizard implements INewWizard {
54
55 protected WizardNewProjectCreationPage mainPage;
56 protected IProject newProject;
57
58 private class NSWizardPage extends WizardPage {
59
60 private Text nsField;
61
62 public NSWizardPage() {
63 super("");
64 }
65
66 public void createControl(Composite parent) {
67 Group comp = new Group(parent, SWT.NONE);
68 comp.setLayout(new GridLayout(1, false));
69 new Label(comp, SWT.NONE).setText("Namespace IRI:");
70
71 nsField = new Text(comp, SWT.BORDER);
72 nsField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
73 nsField.addModifyListener(new ModifyListener() {
74 public void modifyText(ModifyEvent e) {
75 if (nsField.getText().length() > 0) {
76 try {
77 WSMORuntime.getRuntime().getWsmoFactory().createIRI(nsField.getText());
78 setErrorMessage(null);
79 }
80 catch(Throwable ex) {
81 setErrorMessage(ex.getMessage());
82 }
83 }
84 else {
85 setErrorMessage(null);
86 }
87 }
88 });
89
90 setControl(comp);
91 setTitle("New WSMO Project");
92 setDescription("Supply a default namespace for the project (optional)");
93 }
94
95 public String getNSText() {
96 return nsField.getText();
97 }
98 }
99 private NSWizardPage nsPage;
100
101 public void addPages() {
102 mainPage = new WizardNewProjectCreationPage("WSMO Project page");
103 mainPage.setDescription("Create a new WSMO project");
104 mainPage.setTitle("New WSMO project");
105 addPage(mainPage);
106
107 nsPage = new NSWizardPage();
108 addPage(nsPage);
109 }
110
111 public void dispose() {
112 mainPage.dispose();
113 nsPage.dispose();
114 super.dispose();
115 }
116
117 public boolean performFinish() {
118 if (nsPage.getErrorMessage() != null) {
119 if (false == MessageDialog.openConfirm(getShell(),
120 "Invalid Namespace",
121 "The supplied project default namespace is invalid!"
122 +"\nContinue anyway ?")) {
123 return false;
124 }
125 }
126 newProject = createNewWSMOProject();
127 if (newProject == null)
128 return false;
129
130 updatePerspective();
131 selectAndReveal(newProject);
132
133 try {
134 String nsText = nsPage.getNSText();
135 WSMORuntime.getRuntime().getWsmoFactory().createIRI(nsText);
136 newProject.setPersistentProperty(
137 ProjectNamespaceAction.PROJECT_NAMESPACE_NAME,
138 nsText);
139 }
140 catch(Throwable ex) {}
141 return true;
142 }
143
144 protected IProject createNewWSMOProject() {
145 if (newProject != null)
146 return newProject;
147
148 IWorkspace workspace = ResourcesPlugin.getWorkspace();
149 final IProject newProjectHandle = mainPage.getProjectHandle();
150 final IProjectDescription description = workspace
151 .newProjectDescription(newProjectHandle.getName());
152 if (!mainPage.useDefaults())
153 description.setLocation(mainPage.getLocationPath());
154
155 WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
156 protected void execute(IProgressMonitor monitor)
157 throws CoreException {
158 createWSMOProject(description, newProjectHandle, monitor);
159 }
160 };
161
162 try {
163 getContainer().run(true, true, operation);
164 }
165 catch (InterruptedException e) {
166 return null;
167 }
168 catch (InvocationTargetException e) {
169 MessageDialog.openError(getShell(), "Cannot create a new WSMO project",
170 e.getTargetException().getMessage());
171 return null;
172 }
173
174 return newProjectHandle;
175 }
176
177 protected void createWSMOProject(IProjectDescription description, IProject projectHandle,
178 IProgressMonitor monitor) throws CoreException, OperationCanceledException {
179 try {
180 monitor.beginTask("", 2000);
181 projectHandle.create(description, new SubProgressMonitor(monitor, 1000));
182 if (monitor.isCanceled())
183 throw new OperationCanceledException();
184 projectHandle.open(new SubProgressMonitor(monitor, 1000));
185 }
186 finally {
187 monitor.done();
188 }
189 }
190 }
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205