-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathExpressProjectWizardPage.java
More file actions
474 lines (408 loc) · 15.6 KB
/
ExpressProjectWizardPage.java
File metadata and controls
474 lines (408 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
package org.nodeclipse.ui.wizards;
import java.net.URI;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.WorkingSetGroup;
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea;
import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter;
import org.nodeclipse.ui.Activator;
import org.nodeclipse.ui.preferences.PreferenceConstants;
import org.nodeclipse.ui.util.Constants;
import org.eclipse.swt.widgets.Button;
/**
* @author Tomoyuki Inagaki, Paul Verest
*
*
<pre>
>express -h
Usage: express [options]
Options:
-h, --help output usage information
-V, --version output the version number
-s, --sessions add session support
-e, --ejs add ejs engine support (defaults to jade)
-J, --jshtml add jshtml engine support (defaults to jade)
-H, --hogan add hogan.js engine support
-c, --css `engine` add stylesheet `engine` support (less|stylus) (defaults to plain css)
-f, --force force on non-empty directory
</pre>
*/
@SuppressWarnings("restriction")
public class ExpressProjectWizardPage extends WizardPage {
// initial value stores
private String initialProjectFieldValue;
// widgets
Text projectNameField;
Button btnJade;
Button btnEjs;
Button btnJshtml;
Button btnHogan;
Button btnCss;
Button btnLess;
Button btnStylus;
private Listener nameModifyListener = new Listener() {
public void handleEvent(Event e) {
setLocationForSelection();
boolean valid = validatePage();
setPageComplete(valid);
}
};
private ProjectContentsLocationArea locationArea;
private WorkingSetGroup workingSetGroup;
// constants
private static final int SIZING_TEXT_FIELD_WIDTH = 250;
/**
* Creates a new project creation wizard page.
*
* @param pageName
* the name of this page
* @wbp.parser.constructor
*/
public ExpressProjectWizardPage(String pageName) {
super(pageName);
setPageComplete(false);
}
/*
* (non-Javadoc) Method declared on IDialogPage.
*/
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
initializeDialogUnits(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
createProjectNameGroup(composite);
locationArea = new ProjectContentsLocationArea(getErrorReporter(), composite);
if (initialProjectFieldValue != null) {
locationArea.updateProjectName(initialProjectFieldValue);
}
createTemplateGroup(composite);
createStylesheetEngineGroup(composite);
// Scale the button based on the rest of the dialog
setButtonLayoutData(locationArea.getBrowseButton());
setPageComplete(validatePage());
// Show description on opening
setErrorMessage(null);
setMessage(null);
if (!isExpressInstalled()) {
setErrorMessage("Express is not found. Please install Express and check Preference.");
}
setControl(composite);
Dialog.applyDialogFont(composite);
}
private boolean isExpressInstalled() {
String path = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.EXPRESS_PATH);
if (path == null || path.equals("")) {
return false;
}
java.io.File file = new java.io.File(path);
return file.exists();
}
/**
* Create a working set group for this page. This method can only be called
* once.
*
* @param composite
* the composite in which to create the group
* @param selection
* the current workbench selection
* @param supportedWorkingSetTypes
* an array of working set type IDs that will restrict what types
* of working sets can be chosen in this group
* @return the created group. If this method has been called previously the
* original group will be returned.
* @since 3.4
*/
public WorkingSetGroup createWorkingSetGroup(Composite composite, IStructuredSelection selection, String[] supportedWorkingSetTypes) {
if (workingSetGroup != null)
return workingSetGroup;
workingSetGroup = new WorkingSetGroup(composite, selection, supportedWorkingSetTypes);
return workingSetGroup;
}
/**
* Get an error reporter for the receiver.
*
* @return IErrorMessageReporter
*/
private IErrorMessageReporter getErrorReporter() {
return new IErrorMessageReporter() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea
* .IErrorMessageReporter#reportError(java.lang.String)
*/
public void reportError(String errorMessage, boolean infoOnly) {
if (infoOnly) {
setMessage(errorMessage, IStatus.INFO);
setErrorMessage(null);
} else
setErrorMessage(errorMessage);
boolean valid = errorMessage == null;
if (valid) {
valid = validatePage();
}
setPageComplete(valid);
}
};
}
/**
* Creates the project name specification controls.
*
* @param parent
* the parent composite
*/
private final void createProjectNameGroup(Composite parent) {
// project specification group
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
projectGroup.setLayout(layout);
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// new project label
Label projectLabel = new Label(projectGroup, SWT.NONE);
projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel);
projectLabel.setFont(parent.getFont());
// new project name entry field
projectNameField = new Text(projectGroup, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
projectNameField.setLayoutData(data);
projectNameField.setFont(parent.getFont());
// Set the initial value first before listener
// to avoid handling an event during the creation.
if (initialProjectFieldValue != null) {
projectNameField.setText(initialProjectFieldValue);
}
projectNameField.addListener(SWT.Modify, nameModifyListener);
}
private final void createTemplateGroup(Composite parent) {
Composite templateGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 5;
templateGroup.setLayout(layout);
templateGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label lblTemplateEngine = new Label(templateGroup, SWT.NONE);
lblTemplateEngine.setText("Template Engine:");
btnJade = new Button(templateGroup, SWT.RADIO);
btnJade.setSelection(true);
btnJade.setText("Jade");
btnEjs = new Button(templateGroup, SWT.RADIO);
btnEjs.setText("ejs");
btnJshtml = new Button(templateGroup, SWT.RADIO);
btnJshtml.setText("jshtml");
btnHogan = new Button(templateGroup, SWT.RADIO);
btnHogan.setText("hogan.js");
}
private final void createStylesheetEngineGroup(Composite parent) {
Composite stylesheetEngineGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 5;
stylesheetEngineGroup.setLayout(layout);
stylesheetEngineGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label lblTemplateEngine = new Label(stylesheetEngineGroup, SWT.NONE);
lblTemplateEngine.setText("Stylesheet Engine:");
btnCss = new Button(stylesheetEngineGroup, SWT.RADIO);
btnCss.setSelection(true);
btnCss.setText("CSS");
btnLess = new Button(stylesheetEngineGroup, SWT.RADIO);
btnLess.setText("LESS");
btnStylus = new Button(stylesheetEngineGroup, SWT.RADIO);
btnStylus.setText("Stylus");
}
/**
* Returns the current project location path as entered by the user, or its
* anticipated initial value. Note that if the default has been returned the
* path in a project description used to create a project should not be set.
*
* @return the project location path or its anticipated initial value.
*/
public IPath getLocationPath() {
return new Path(locationArea.getProjectLocation());
}
/**
* /** Returns the current project location URI as entered by the user, or
* <code>null</code> if a valid project location has not been entered.
*
* @return the project location URI, or <code>null</code>
* @since 3.2
*/
public URI getLocationURI() {
return locationArea.getProjectLocationURI();
}
/**
* Creates a project resource handle for the current project name field
* value. The project handle is created relative to the workspace root.
* <p>
* This method does not create the project resource; this is the
* responsibility of <code>IProject::create</code> invoked by the new
* project resource wizard.
* </p>
*
* @return the new project resource handle
*/
public IProject getProjectHandle() {
return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
}
/**
* Returns the current project name as entered by the user, or its
* anticipated initial value.
*
* @return the project name, its anticipated initial value, or
* <code>null</code> if no project name is known
*/
public String getProjectName() {
if (projectNameField == null) {
return initialProjectFieldValue;
}
return getProjectNameFieldValue();
}
/**
* Returns the value of the project name field with leading and trailing
* spaces removed.
*
* @return the project name in the field
*/
private String getProjectNameFieldValue() {
if (projectNameField == null) {
return ""; //$NON-NLS-1$
}
return projectNameField.getText().trim();
}
/**
* Sets the initial project name that this page will use when created. The
* name is ignored if the createControl(Composite) method has already been
* called. Leading and trailing spaces in the name are ignored. Providing
* the name of an existing project will not necessarily cause the wizard to
* warn the user. Callers of this method should first check if the project
* name passed already exists in the workspace.
*
* @param name
* initial project name for this page
*
* @see IWorkspace#validateName(String, int)
*
*/
public void setInitialProjectName(String name) {
if (name == null) {
initialProjectFieldValue = null;
} else {
initialProjectFieldValue = name.trim();
if (locationArea != null) {
locationArea.updateProjectName(name.trim());
}
}
}
/**
* Set the location to the default location if we are set to useDefaults.
*/
void setLocationForSelection() {
locationArea.updateProjectName(getProjectNameFieldValue());
}
/**
* Returns whether this page's controls currently all contain valid values.
*
* @return <code>true</code> if all controls are valid, and
* <code>false</code> if at least one is invalid
*/
protected boolean validatePage() {
IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
String projectFieldContents = getProjectNameFieldValue();
if (projectFieldContents.equals("")) { //$NON-NLS-1$
setErrorMessage(null);
setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
return false;
}
IStatus nameStatus = workspace.validateName(projectFieldContents, IResource.PROJECT);
if (!nameStatus.isOK()) {
setErrorMessage(nameStatus.getMessage());
return false;
}
IProject handle = getProjectHandle();
if (handle.exists()) {
setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
return false;
}
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectNameFieldValue());
locationArea.setExistingProject(project);
String validLocationMessage = locationArea.checkValidLocation();
if (validLocationMessage != null) {
// there is no destination location given
setErrorMessage(validLocationMessage);
return false;
}
setErrorMessage(null);
setMessage(null);
return true;
}
/*
* see @DialogPage.setVisible(boolean)
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
projectNameField.setFocus();
}
}
/**
* Returns the useDefaults.
*
* @return boolean
*/
public boolean useDefaults() {
return locationArea.isDefault();
}
/**
* Return the selected working sets, if any. If this page is not configured
* to interact with working sets this will be an empty array.
*
* @return the selected working sets
* @since 3.4
*/
public IWorkingSet[] getSelectedWorkingSets() {
return workingSetGroup == null ? new IWorkingSet[0] : workingSetGroup.getSelectedWorkingSets();
}
public String getSelectedTemplateEngine() {
if (btnEjs.getSelection()) {
return Constants.TEMPLATE_ENGINE_EJS;
}
if (btnJshtml.getSelection()) {
return Constants.TEMPLATE_ENGINE_JSHTML;
}
if (btnHogan.getSelection()) {
return Constants.TEMPLATE_ENGINE_HOGAN;
}
return Constants.BLANK_STRING;
}
public String getSelectedStylesheetEngine() {
if (btnLess.getSelection()) {
return Constants.STYLESHEET_LESS;
}
if (btnStylus.getSelection()) {
return Constants.STYLESHEET_STYLUS;
}
return Constants.STYLESHEET_CSS;
}
}