Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 166947
Collapse All | Expand All

(-)src/org/eclipse/ui/internal/wizards/newresource/ResourceMessages.java (+3 lines)
Lines 36-41 Link Here
36
	public static String NewProject_internalError;
36
	public static String NewProject_internalError;
37
	public static String NewProject_caseVariantExistsError;
37
	public static String NewProject_caseVariantExistsError;
38
	public static String NewProject_perspSwitchTitle;
38
	public static String NewProject_perspSwitchTitle;
39
	public static String NewProject_maintaskLabel;
40
	public static String NewProject_subtaskLabel;
41
39
	/**
42
	/**
40
	 * Combines a perspective name and text for introducing a perspective switch
43
	 * Combines a perspective name and text for introducing a perspective switch
41
	 */
44
	 */
(-)src/org/eclipse/ui/internal/wizards/newresource/messages.properties (+2 lines)
Lines 35-37 Link Here
35
NewProject_perspSwitchTitle = Open Associated Perspective?
35
NewProject_perspSwitchTitle = Open Associated Perspective?
36
NewProject_perspSwitchMessage = This kind of project is associated with the {0} perspective.  Do you want to open this perspective now?
36
NewProject_perspSwitchMessage = This kind of project is associated with the {0} perspective.  Do you want to open this perspective now?
37
NewProject_perspSwitchMessageWithDesc = This kind of project is associated with the {0} perspective.\n\n{1}\n\nDo you want to open this perspective now?
37
NewProject_perspSwitchMessageWithDesc = This kind of project is associated with the {0} perspective.\n\n{1}\n\nDo you want to open this perspective now?
38
NewProject_maintaskLabel=Create Project.
39
NewProject_subtaskLabel=Create new project ...
(-)src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java (-437 / +45 lines)
Lines 13-78 Link Here
13
13
14
package org.eclipse.ui.wizards.newresource;
14
package org.eclipse.ui.wizards.newresource;
15
15
16
import java.lang.reflect.InvocationTargetException;
17
import java.net.URI;
16
import java.net.URI;
18
import java.util.ArrayList;
19
import java.util.HashSet;
20
import java.util.List;
21
import java.util.Set;
22
import java.util.StringTokenizer;
23
17
24
import org.eclipse.core.commands.ExecutionException;
25
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.resources.IProject;
26
import org.eclipse.core.resources.IProjectDescription;
19
import org.eclipse.core.resources.IProjectDescription;
27
import org.eclipse.core.resources.IResourceStatus;
28
import org.eclipse.core.resources.IWorkspace;
20
import org.eclipse.core.resources.IWorkspace;
29
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.IConfigurationElement;
32
import org.eclipse.core.runtime.IExecutableExtension;
33
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.jface.dialogs.Dialog;
37
import org.eclipse.jface.dialogs.ErrorDialog;
38
import org.eclipse.jface.dialogs.IDialogConstants;
39
import org.eclipse.jface.dialogs.IDialogSettings;
26
import org.eclipse.jface.dialogs.IDialogSettings;
40
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
41
import org.eclipse.jface.operation.IRunnableWithProgress;
42
import org.eclipse.jface.preference.IPreferenceStore;
43
import org.eclipse.jface.resource.ImageDescriptor;
27
import org.eclipse.jface.resource.ImageDescriptor;
44
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.viewers.IStructuredSelection;
45
import org.eclipse.osgi.util.NLS;
46
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.ui.IPerspectiveDescriptor;
48
import org.eclipse.ui.IPerspectiveRegistry;
49
import org.eclipse.ui.IPluginContribution;
50
import org.eclipse.ui.IWorkbench;
30
import org.eclipse.ui.IWorkbench;
51
import org.eclipse.ui.IWorkbenchPage;
52
import org.eclipse.ui.IWorkbenchPreferenceConstants;
53
import org.eclipse.ui.IWorkbenchWindow;
54
import org.eclipse.ui.IWorkingSet;
31
import org.eclipse.ui.IWorkingSet;
55
import org.eclipse.ui.PlatformUI;
56
import org.eclipse.ui.WorkbenchException;
57
import org.eclipse.ui.activities.IActivityManager;
58
import org.eclipse.ui.activities.IIdentifier;
59
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
60
import org.eclipse.ui.activities.WorkbenchActivityHelper;
61
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
32
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
62
import org.eclipse.ui.dialogs.WizardNewProjectReferencePage;
33
import org.eclipse.ui.dialogs.WizardNewProjectReferencePage;
63
import org.eclipse.ui.ide.IDE;
64
import org.eclipse.ui.ide.undo.CreateProjectOperation;
65
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
66
import org.eclipse.ui.internal.IPreferenceConstants;
67
import org.eclipse.ui.internal.WorkbenchPlugin;
68
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
69
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
34
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
70
import org.eclipse.ui.internal.ide.StatusUtil;
71
import org.eclipse.ui.internal.registry.PerspectiveDescriptor;
72
import org.eclipse.ui.internal.util.PrefUtil;
73
import org.eclipse.ui.internal.wizards.newresource.ResourceMessages;
35
import org.eclipse.ui.internal.wizards.newresource.ResourceMessages;
74
import org.eclipse.ui.statushandlers.StatusAdapter;
75
import org.eclipse.ui.statushandlers.StatusManager;
76
36
77
/**
37
/**
78
 * Standard workbench wizard that creates a new project resource in the
38
 * Standard workbench wizard that creates a new project resource in the
Lines 91-137 Link Here
91
 * dialog.open();
51
 * dialog.open();
92
 * </pre>
52
 * </pre>
93
 * 
53
 * 
94
 * During the call to <code>open</code>, the wizard dialog is presented to
54
 * During the call to <code>open</code>, the wizard dialog is presented to the
95
 * the user. When the user hits Finish, a project resource with the
55
 * user. When the user hits Finish, a project resource with the user-specified
96
 * user-specified name is created, the dialog closes, and the call to
56
 * name is created, the dialog closes, and the call to <code>open</code>
97
 * <code>open</code> returns.
57
 * returns.
98
 * </p>
58
 * </p>
59
 * 
99
 * @noextend This class is not intended to be subclassed by clients.
60
 * @noextend This class is not intended to be subclassed by clients.
100
 */
61
 */
101
public class BasicNewProjectResourceWizard extends BasicNewResourceWizard
62
public class BasicNewProjectResourceWizard extends NewProjectWizard {
102
		implements IExecutableExtension {
63
103
	
104
	/**
64
	/**
105
	 * The wizard id for creating new projects in the workspace.
65
	 * The wizard id for creating new projects in the workspace.
66
	 * 
106
	 * @since 3.4
67
	 * @since 3.4
107
	 */
68
	 */
108
	public static final String WIZARD_ID = "org.eclipse.ui.wizards.new.project"; //$NON-NLS-1$
69
	public static final String WIZARD_ID = "org.eclipse.ui.wizards.new.project"; //$NON-NLS-1$
109
	
70
110
	private WizardNewProjectCreationPage mainPage;
71
	private WizardNewProjectCreationPage mainPage;
111
72
112
	private WizardNewProjectReferencePage referencePage;
73
	private WizardNewProjectReferencePage referencePage;
113
74
114
	// cache of newly-created project
115
	private IProject newProject;
75
	private IProject newProject;
116
76
117
	/**
77
	/**
118
	 * The config element which declares this wizard.
119
	 */
120
	private IConfigurationElement configElement;
121
122
	private static String WINDOW_PROBLEMS_TITLE = ResourceMessages.NewProject_errorOpeningWindow;
123
124
	/**
125
	 * Extension attribute name for final perspective.
126
	 */
127
	private static final String FINAL_PERSPECTIVE = "finalPerspective"; //$NON-NLS-1$
128
129
	/**
130
	 * Extension attribute name for preferred perspectives.
131
	 */
132
	private static final String PREFERRED_PERSPECTIVES = "preferredPerspectives"; //$NON-NLS-1$
133
134
	/**
135
	 * Creates a wizard for creating a new project resource in the workspace.
78
	 * Creates a wizard for creating a new project resource in the workspace.
136
	 */
79
	 */
137
	public BasicNewProjectResourceWizard() {
80
	public BasicNewProjectResourceWizard() {
Lines 156-162 Link Here
156
			/*
99
			/*
157
			 * (non-Javadoc)
100
			 * (non-Javadoc)
158
			 * 
101
			 * 
159
			 * @see org.eclipse.ui.dialogs.WizardNewProjectCreationPage#createControl(org.eclipse.swt.widgets.Composite)
102
			 * @see
103
			 * org.eclipse.ui.dialogs.WizardNewProjectCreationPage#createControl
104
			 * (org.eclipse.swt.widgets.Composite)
160
			 */
105
			 */
161
			public void createControl(Composite parent) {
106
			public void createControl(Composite parent) {
162
				super.createControl(parent);
107
				super.createControl(parent);
Lines 166-172 Link Here
166
						new String[] { "org.eclipse.ui.resourceWorkingSetPage" }); //$NON-NLS-1$
111
						new String[] { "org.eclipse.ui.resourceWorkingSetPage" }); //$NON-NLS-1$
167
				Dialog.applyDialogFont(getControl());
112
				Dialog.applyDialogFont(getControl());
168
			}
113
			}
169
		}; 
114
		};
170
		mainPage.setTitle(ResourceMessages.NewProject_title);
115
		mainPage.setTitle(ResourceMessages.NewProject_title);
171
		mainPage.setDescription(ResourceMessages.NewProject_description);
116
		mainPage.setDescription(ResourceMessages.NewProject_description);
172
		this.addPage(mainPage);
117
		this.addPage(mainPage);
Lines 182-208 Link Here
182
		}
127
		}
183
	}
128
	}
184
129
185
	/**
130
	/*
186
	 * Creates a new project resource with the selected name.
131
	 * (non-Javadoc)
187
	 * <p>
188
	 * In normal usage, this method is invoked after the user has pressed Finish
189
	 * on the wizard; the enablement of the Finish button implies that all
190
	 * controls on the pages currently contain valid values.
191
	 * </p>
192
	 * <p>
193
	 * Note that this wizard caches the new project once it has been
194
	 * successfully created; subsequent invocations of this method will answer
195
	 * the same project resource without attempting to create it again.
196
	 * </p>
197
	 * 
132
	 * 
198
	 * @return the created project resource, or <code>null</code> if the
133
	 * @see
199
	 *         project was not created
134
	 * org.eclipse.ui.wizards.newresource.NewProjectWizard#createProjectDescription
135
	 * ()
200
	 */
136
	 */
201
	private IProject createNewProject() {
137
	protected IProjectDescription createProjectDescription() {
202
		if (newProject != null) {
203
			return newProject;
204
		}
205
206
		// get a project handle
138
		// get a project handle
207
		final IProject newProjectHandle = mainPage.getProjectHandle();
139
		final IProject newProjectHandle = mainPage.getProjectHandle();
208
140
Lines 225-302 Link Here
225
			}
157
			}
226
		}
158
		}
227
159
228
		// create the new project operation
160
		return description;
229
		IRunnableWithProgress op = new IRunnableWithProgress() {
161
	}
230
			public void run(IProgressMonitor monitor)
231
					throws InvocationTargetException {
232
				CreateProjectOperation op = new CreateProjectOperation(
233
						description, ResourceMessages.NewProject_windowTitle);
234
				try {
235
					// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
236
					// directly execute the operation so that the undo state is
237
					// not preserved.  Making this undoable resulted in too many 
238
					// accidental file deletions.
239
					op.execute(monitor, WorkspaceUndoUtil
240
						.getUIInfoAdapter(getShell()));
241
				} catch (ExecutionException e) {
242
					throw new InvocationTargetException(e);
243
				}
244
			}
245
		};
246
247
		// run the new project creation operation
248
		try {
249
			getContainer().run(true, true, op);
250
		} catch (InterruptedException e) {
251
			return null;
252
		} catch (InvocationTargetException e) {
253
			Throwable t = e.getTargetException();
254
			if (t instanceof ExecutionException
255
					&& t.getCause() instanceof CoreException) {
256
				CoreException cause = (CoreException) t.getCause();
257
				StatusAdapter status;
258
				if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
259
					status = new StatusAdapter(
260
							StatusUtil
261
									.newStatus(
262
											IStatus.WARNING,
263
											NLS
264
													.bind(
265
															ResourceMessages.NewProject_caseVariantExistsError,
266
															newProjectHandle
267
																	.getName()),
268
											cause));
269
				} else {
270
					status = new StatusAdapter(StatusUtil.newStatus(cause
271
							.getStatus().getSeverity(),
272
							ResourceMessages.NewProject_errorMessage, cause));
273
				}
274
				status.setProperty(StatusAdapter.TITLE_PROPERTY,
275
						ResourceMessages.NewProject_errorMessage);
276
				StatusManager.getManager().handle(status, StatusManager.BLOCK);
277
			} else {
278
				StatusAdapter status = new StatusAdapter(new Status(
279
						IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0,
280
						NLS.bind(ResourceMessages.NewProject_internalError, t
281
								.getMessage()), t));
282
				status.setProperty(StatusAdapter.TITLE_PROPERTY,
283
						ResourceMessages.NewProject_errorMessage);
284
				StatusManager.getManager().handle(status,
285
						StatusManager.LOG | StatusManager.BLOCK);
286
			}
287
			return null;
288
		}
289
290
		newProject = newProjectHandle;
291
162
163
	/*
164
	 * (non-Javadoc)
165
	 * 
166
	 * @see
167
	 * org.eclipse.ui.wizards.newresource.NewProjectWizard#createNewProject(
168
	 * org.eclipse.core.resources.IProjectDescription,
169
	 * org.eclipse.core.resources.IWorkspace,
170
	 * org.eclipse.core.runtime.IProgressMonitor)
171
	 */
172
	protected IProject createNewProject(IProjectDescription projectDescription,
173
			IWorkspace workspace, IProgressMonitor monitor)
174
			throws CoreException {
175
		newProject = super.createNewProject(projectDescription, workspace,
176
				monitor);
292
		return newProject;
177
		return newProject;
293
	}
178
	}
294
179
295
	/**
180
	/**
296
	 * Returns the newly created project.
181
	 * Returns the newly created project.
297
	 * 
182
	 * 
298
	 * @return the created project, or <code>null</code> if project not
183
	 * @return the created project, or <code>null</code> if project not created
299
	 *         created
300
	 */
184
	 */
301
	public IProject getNewProject() {
185
	public IProject getNewProject() {
302
		return newProject;
186
		return newProject;
Lines 320-614 Link Here
320
		setDefaultPageImageDescriptor(desc);
204
		setDefaultPageImageDescriptor(desc);
321
	}
205
	}
322
206
323
	/*
324
	 * (non-Javadoc) Opens a new window with a particular perspective and input.
325
	 */
326
	private static void openInNewWindow(IPerspectiveDescriptor desc) {
327
328
		// Open the page.
329
		try {
330
			PlatformUI.getWorkbench().openWorkbenchWindow(desc.getId(),
331
					ResourcesPlugin.getWorkspace().getRoot());
332
		} catch (WorkbenchException e) {
333
			IWorkbenchWindow window = PlatformUI.getWorkbench()
334
					.getActiveWorkbenchWindow();
335
			if (window != null) {
336
				ErrorDialog.openError(window.getShell(), WINDOW_PROBLEMS_TITLE,
337
						e.getMessage(), e.getStatus());
338
			}
339
		}
340
	}
341
342
	/*
343
	 * (non-Javadoc) Method declared on IWizard.
344
	 */
345
	public boolean performFinish() {
346
		createNewProject();
347
348
		if (newProject == null) {
349
			return false;
350
		}
351
		
352
		IWorkingSet[] workingSets = mainPage.getSelectedWorkingSets();
353
		getWorkbench().getWorkingSetManager().addToWorkingSets(newProject,
354
				workingSets);
355
        
356
		updatePerspective();
357
		selectAndReveal(newProject);
358
359
		return true;
360
	}
361
362
	/*
363
	 * (non-Javadoc) Replaces the current perspective with the new one.
364
	 */
365
	private static void replaceCurrentPerspective(IPerspectiveDescriptor persp) {
366
367
		// Get the active page.
368
		IWorkbenchWindow window = PlatformUI.getWorkbench()
369
				.getActiveWorkbenchWindow();
370
		if (window == null) {
371
			return;
372
		}
373
		IWorkbenchPage page = window.getActivePage();
374
		if (page == null) {
375
			return;
376
		}
377
378
		// Set the perspective.
379
		page.setPerspective(persp);
380
	}
381
382
	/**
207
	/**
383
	 * Stores the configuration element for the wizard. The config element will
208
	 * @deprecated use
384
	 * be used in <code>performFinish</code> to set the result perspective.
209
	 *             {@link NewProjectWizard#updatePerspective(IConfigurationElement)}
385
	 */
210
	 *             .
386
	public void setInitializationData(IConfigurationElement cfig,
387
			String propertyName, Object data) {
388
		configElement = cfig;
389
	}
390
391
	/**
392
	 * Updates the perspective for the active page within the window.
393
	 */
394
	protected void updatePerspective() {
395
		updatePerspective(configElement);
396
	}
397
398
	/**
399
	 * Updates the perspective based on the current settings in the
400
	 * Workbench/Perspectives preference page.
401
	 * 
402
	 * Use the setting for the new perspective opening if we are set to open in
403
	 * a new perspective.
404
	 * <p>
405
	 * A new project wizard class will need to implement the
406
	 * <code>IExecutableExtension</code> interface so as to gain access to the
407
	 * wizard's <code>IConfigurationElement</code>. That is the configuration
408
	 * element to pass into this method.
409
	 * </p>
410
	 * 
411
	 * @param configElement -
412
	 *            the element we are updating with
413
	 * 
414
	 * @see IPreferenceConstants#OPM_NEW_WINDOW
415
	 * @see IPreferenceConstants#OPM_ACTIVE_PAGE
416
	 * @see IWorkbenchPreferenceConstants#NO_NEW_PERSPECTIVE
417
	 */
211
	 */
418
	public static void updatePerspective(IConfigurationElement configElement) {
212
	public static void updatePerspective(IConfigurationElement configElement) {
419
		// Do not change perspective if the configuration element is
213
		NewProjectWizard.updatePerspective(configElement);
420
		// not specified.
421
		if (configElement == null) {
422
			return;
423
		}
424
425
		// Retrieve the new project open perspective preference setting
426
		String perspSetting = PrefUtil.getAPIPreferenceStore().getString(
427
				IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE);
428
429
		String promptSetting = IDEWorkbenchPlugin.getDefault()
430
				.getPreferenceStore().getString(
431
						IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
432
433
		// Return if do not switch perspective setting and are not prompting
434
		if (!(promptSetting.equals(MessageDialogWithToggle.PROMPT))
435
				&& perspSetting
436
						.equals(IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE)) {
437
			return;
438
		}
439
440
		// Read the requested perspective id to be opened.
441
		String finalPerspId = configElement.getAttribute(FINAL_PERSPECTIVE);
442
		if (finalPerspId == null) {
443
			return;
444
		}
445
446
		// Map perspective id to descriptor.
447
		IPerspectiveRegistry reg = PlatformUI.getWorkbench()
448
				.getPerspectiveRegistry();
449
450
		// leave this code in - the perspective of a given project may map to
451
		// activities other than those that the wizard itself maps to.
452
		IPerspectiveDescriptor finalPersp = reg
453
				.findPerspectiveWithId(finalPerspId);
454
		if (finalPersp != null && finalPersp instanceof IPluginContribution) {
455
			IPluginContribution contribution = (IPluginContribution) finalPersp;
456
			if (contribution.getPluginId() != null) {
457
				IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI
458
						.getWorkbench().getActivitySupport();
459
				IActivityManager activityManager = workbenchActivitySupport
460
						.getActivityManager();
461
				IIdentifier identifier = activityManager
462
						.getIdentifier(WorkbenchActivityHelper
463
								.createUnifiedId(contribution));
464
				Set idActivities = identifier.getActivityIds();
465
466
				if (!idActivities.isEmpty()) {
467
					Set enabledIds = new HashSet(activityManager
468
							.getEnabledActivityIds());
469
470
					if (enabledIds.addAll(idActivities)) {
471
						workbenchActivitySupport
472
								.setEnabledActivityIds(enabledIds);
473
					}
474
				}
475
			}
476
		} else {
477
			IDEWorkbenchPlugin.log("Unable to find persective " //$NON-NLS-1$
478
					+ finalPerspId
479
					+ " in BasicNewProjectResourceWizard.updatePerspective"); //$NON-NLS-1$
480
			return;
481
		}
482
483
		// gather the preferred perspectives
484
		// always consider the final perspective (and those derived from it)
485
		// to be preferred
486
		ArrayList preferredPerspIds = new ArrayList();
487
		addPerspectiveAndDescendants(preferredPerspIds, finalPerspId);
488
		String preferred = configElement.getAttribute(PREFERRED_PERSPECTIVES);
489
		if (preferred != null) {
490
			StringTokenizer tok = new StringTokenizer(preferred, " \t\n\r\f,"); //$NON-NLS-1$
491
			while (tok.hasMoreTokens()) {
492
				addPerspectiveAndDescendants(preferredPerspIds, tok.nextToken());
493
			}
494
		}
495
496
		IWorkbenchWindow window = PlatformUI.getWorkbench()
497
				.getActiveWorkbenchWindow();
498
		if (window != null) {
499
			IWorkbenchPage page = window.getActivePage();
500
			if (page != null) {
501
				IPerspectiveDescriptor currentPersp = page.getPerspective();
502
503
				// don't switch if the current perspective is a preferred
504
				// perspective
505
				if (currentPersp != null
506
						&& preferredPerspIds.contains(currentPersp.getId())) {
507
					return;
508
				}
509
			}
510
511
			// prompt the user to switch
512
			if (!confirmPerspectiveSwitch(window, finalPersp)) {
513
				return;
514
			}
515
		}
516
517
		int workbenchPerspectiveSetting = WorkbenchPlugin.getDefault()
518
				.getPreferenceStore().getInt(
519
						IPreferenceConstants.OPEN_PERSP_MODE);
520
521
		// open perspective in new window setting
522
		if (workbenchPerspectiveSetting == IPreferenceConstants.OPM_NEW_WINDOW) {
523
			openInNewWindow(finalPersp);
524
			return;
525
		}
526
527
		// replace active perspective setting otherwise
528
		replaceCurrentPerspective(finalPersp);
529
	}
214
	}
530
215
	
531
	/**
216
	/* (non-Javadoc)
532
	 * Adds to the list all perspective IDs in the Workbench who's original ID
217
	 * @see org.eclipse.ui.wizards.newresource.NewProjectWizard#getSelectedWorkingSets()
533
	 * matches the given ID.
534
	 * 
535
	 * @param perspectiveIds
536
	 *            the list of perspective IDs to supplement.
537
	 * @param id
538
	 *            the id to query.
539
	 * @since 3.0
540
	 */
541
	private static void addPerspectiveAndDescendants(List perspectiveIds,
542
			String id) {
543
		IPerspectiveRegistry registry = PlatformUI.getWorkbench()
544
				.getPerspectiveRegistry();
545
		IPerspectiveDescriptor[] perspectives = registry.getPerspectives();
546
		for (int i = 0; i < perspectives.length; i++) {
547
			// @issue illegal ref to workbench internal class;
548
			// consider adding getOriginalId() as API on IPerspectiveDescriptor
549
			PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]);
550
			if (descriptor.getOriginalId().equals(id)) {
551
				perspectiveIds.add(descriptor.getId());
552
			}
553
		}
554
	}
555
556
	/**
557
	 * Prompts the user for whether to switch perspectives.
558
	 * 
559
	 * @param window
560
	 *            The workbench window in which to switch perspectives; must not
561
	 *            be <code>null</code>
562
	 * @param finalPersp
563
	 *            The perspective to switch to; must not be <code>null</code>.
564
	 * 
565
	 * @return <code>true</code> if it's OK to switch, <code>false</code>
566
	 *         otherwise
567
	 */
218
	 */
568
	private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window,
219
	protected IWorkingSet[] getSelectedWorkingSets() {
569
			IPerspectiveDescriptor finalPersp) {
220
		return mainPage.getSelectedWorkingSets();
570
		IPreferenceStore store = IDEWorkbenchPlugin.getDefault()
571
				.getPreferenceStore();
572
		String pspm = store
573
				.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
574
		if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) {
575
			// Return whether or not we should always switch
576
			return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm);
577
		}
578
		String desc = finalPersp.getDescription();
579
		String message;
580
		if (desc == null || desc.length() == 0)
581
			message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage,
582
					finalPersp.getLabel());
583
		else
584
			message = NLS.bind(
585
					ResourceMessages.NewProject_perspSwitchMessageWithDesc,
586
					new String[] { finalPersp.getLabel(), desc });
587
588
		MessageDialogWithToggle dialog = MessageDialogWithToggle
589
				.openYesNoQuestion(window.getShell(),
590
						ResourceMessages.NewProject_perspSwitchTitle, message,
591
						null /* use the default message for the toggle */,
592
						false /* toggle is initially unchecked */, store,
593
						IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
594
		int result = dialog.getReturnCode();
595
596
		// If we are not going to prompt anymore propogate the choice.
597
		if (dialog.getToggleState()) {
598
			String preferenceValue;
599
			if (result == IDialogConstants.YES_ID) {
600
				// Doesn't matter if it is replace or new window
601
				// as we are going to use the open perspective setting
602
				preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE;
603
			} else {
604
				preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE;
605
			}
606
607
			// update PROJECT_OPEN_NEW_PERSPECTIVE to correspond
608
			PrefUtil.getAPIPreferenceStore().setValue(
609
					IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE,
610
					preferenceValue);
611
		}
612
		return result == IDialogConstants.YES_ID;
613
	}
221
	}
614
}
222
}
(-)src/org/eclipse/ui/wizards/newresource/NewProjectWizard.java (+584 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Sierra Wireless/Simon Bernard - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.wizards.newresource;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
18
import java.util.StringTokenizer;
19
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IProjectDescription;
22
import org.eclipse.core.resources.IResourceStatus;
23
import org.eclipse.core.resources.IWorkspace;
24
import org.eclipse.core.resources.IWorkspaceRunnable;
25
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IConfigurationElement;
28
import org.eclipse.core.runtime.IExecutableExtension;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.OperationCanceledException;
32
import org.eclipse.core.runtime.Status;
33
import org.eclipse.core.runtime.SubProgressMonitor;
34
import org.eclipse.jface.dialogs.ErrorDialog;
35
import org.eclipse.jface.dialogs.IDialogConstants;
36
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
37
import org.eclipse.jface.operation.IRunnableWithProgress;
38
import org.eclipse.jface.preference.IPreferenceStore;
39
import org.eclipse.osgi.util.NLS;
40
import org.eclipse.ui.IPerspectiveDescriptor;
41
import org.eclipse.ui.IPerspectiveRegistry;
42
import org.eclipse.ui.IPluginContribution;
43
import org.eclipse.ui.IWorkbenchPage;
44
import org.eclipse.ui.IWorkbenchPreferenceConstants;
45
import org.eclipse.ui.IWorkbenchWindow;
46
import org.eclipse.ui.IWorkingSet;
47
import org.eclipse.ui.PlatformUI;
48
import org.eclipse.ui.WorkbenchException;
49
import org.eclipse.ui.activities.IActivityManager;
50
import org.eclipse.ui.activities.IIdentifier;
51
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
52
import org.eclipse.ui.activities.WorkbenchActivityHelper;
53
import org.eclipse.ui.ide.IDE;
54
import org.eclipse.ui.internal.IPreferenceConstants;
55
import org.eclipse.ui.internal.WorkbenchPlugin;
56
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
57
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
58
import org.eclipse.ui.internal.ide.StatusUtil;
59
import org.eclipse.ui.internal.registry.PerspectiveDescriptor;
60
import org.eclipse.ui.internal.util.PrefUtil;
61
import org.eclipse.ui.internal.wizards.newresource.ResourceMessages;
62
import org.eclipse.ui.statushandlers.IStatusAdapterConstants;
63
import org.eclipse.ui.statushandlers.StatusAdapter;
64
import org.eclipse.ui.statushandlers.StatusManager;
65
66
/**
67
 * A general-purpose wizard to create project.<br>
68
 * 
69
 * Clients should extend the class and override
70
 * <code>createProjectDescription</code>,<code>addPages</code> and
71
 * <code>configureProject</code> protected methods.
72
 * <p>
73
 * <code>addPages</code> will allow you to define pages which will collect
74
 * information to create your project.<br>
75
 * <code>createProjectDescription</code> must be used to create the
76
 * ProjectDescription from collected information (in wizard page).
77
 * <code>configureProject</code> must be used to do specific project
78
 * configuration (e.g. create folder or file ...).
79
 * <p>
80
 * 
81
 * @since 3.7
82
 */
83
public abstract class NewProjectWizard extends BasicNewResourceWizard implements
84
		IExecutableExtension {
85
86
	/**
87
	 * The config element which declares this wizard.
88
	 */
89
	private IConfigurationElement configElement;
90
91
	/**
92
	 * Extension attribute name for final perspective.
93
	 */
94
	private static final String FINAL_PERSPECTIVE = "finalPerspective"; //$NON-NLS-1$
95
96
	/**
97
	 * Extension attribute name for preferred perspectives.
98
	 */
99
	private static final String PREFERRED_PERSPECTIVES = "preferredPerspectives"; //$NON-NLS-1$
100
	
101
	private static String WINDOW_PROBLEMS_TITLE = ResourceMessages.NewProject_errorOpeningWindow;
102
103
	/**
104
	 * client must extend it to create the project description used to create
105
	 * the project
106
	 * 
107
	 * @extend
108
	 */
109
	protected abstract IProjectDescription createProjectDescription();
110
111
	/**
112
	 * Create the project from the given project description.<br>
113
	 * This method will be seen as an atomic operation with the configureProject
114
	 * method as workspace level.
115
	 * 
116
	 * @param projectDescription
117
	 *            description used to create project
118
	 * @param workspace
119
	 *            workspace in which project will be created
120
	 * @param monitor
121
	 *            monitor to manage task progess and task cancellation
122
	 * @return the created project
123
	 * @throws CoreException
124
	 *             throw coreException if a problem occurs
125
	 */
126
	protected IProject createNewProject(IProjectDescription projectDescription,
127
			IWorkspace workspace, IProgressMonitor monitor)
128
			throws CoreException {
129
		try {
130
			monitor.beginTask(ResourceMessages.NewProject_subtaskLabel, 2);
131
			IProject project = workspace.getRoot().getProject(
132
					projectDescription.getName());
133
			project.create(projectDescription, new SubProgressMonitor(monitor,
134
					1));
135
			if (monitor.isCanceled()) {
136
				throw new OperationCanceledException();
137
			}
138
			project.open(new SubProgressMonitor(monitor, 1));
139
			return project;
140
		} finally {
141
			monitor.done();
142
		}
143
	}
144
145
	/**
146
	 * Could be use by client to configure the project after creation. (like add
147
	 * folder or file .. )<br>
148
	 * This method will be seen as an atomic operation with the project creation
149
	 * at workspace level.
150
	 * <p>
151
	 * client must use monitor to manage task progess and task cancellation.
152
	 * <p>
153
	 * 
154
	 * <pre>
155
	 *   try {
156
	 *       monitor.beginTask("Configure project", nbtask);
157
	 *       ...
158
	 *       monitor.worked(1)
159
	 *       if (monitor.isCanceled()) {
160
	 *          throw new OperationCanceledException();
161
	 *       }
162
	 *       ...
163
	 *       monitor.worked(2)
164
	 *    }finally{
165
	 *       monitor.done();
166
	 *    }
167
	 * </pre>
168
	 * 
169
	 * 
170
	 * @param newProject
171
	 *            project created to configure
172
	 * @param monitor
173
	 *            monitor to manage task progess and task cancellation
174
	 * @throws CoreException
175
	 *             client could throw coreException if a problem occurs
176
	 */
177
	protected void configureProject(IProject newProject,
178
			IProgressMonitor monitor) throws CoreException {
179
		// nothing to do by default
180
	}
181
182
	/**
183
	 * @extend could be extend to add project in given working sets
184
	 */
185
	protected IWorkingSet[] getSelectedWorkingSets() {
186
		// no working set by default
187
		return null;
188
	}
189
190
	/**
191
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
192
	 */
193
	public boolean performFinish() {
194
		IProject newProject = createNewProjectInWizardContext();
195
196
		if (newProject == null) {
197
			return false;
198
		}
199
200
		// add project to working set if needed
201
		IWorkingSet[] workingSets = getSelectedWorkingSets();
202
		if (workingSets != null && workingSets.length > 0)
203
			getWorkbench().getWorkingSetManager().addToWorkingSets(newProject,
204
					workingSets);
205
206
		// change perspective
207
		updatePerspective();
208
209
		// select the created project
210
		selectAndReveal(newProject);
211
212
		return true;
213
	}
214
215
	/**
216
	 * Stores the configuration element for the wizard. The config element will
217
	 * be used in <code>performFinish</code> to set the result perspective.
218
	 */
219
	public void setInitializationData(IConfigurationElement cfig,
220
			String propertyName, Object data) {
221
		configElement = cfig;
222
	}
223
224
	/**
225
	 * Updates the perspective for the active page within the window.
226
	 */
227
	protected void updatePerspective() {
228
		updatePerspective(configElement);
229
	}
230
231
	/**
232
	 * Create the new project in the wizard context.<br>
233
	 * Creation is done as an atomic workspace operation
234
	 * 
235
	 * @noextend This class is not intended to be subclassed by clients.
236
	 */
237
	protected IProject createNewProjectInWizardContext() {
238
		// create project description
239
		final IProjectDescription description = createProjectDescription();
240
241
		// create the new project operation from project description
242
		IRunnableWithProgress op = new IRunnableWithProgress() {
243
			public void run(IProgressMonitor monitor)
244
					throws InvocationTargetException {
245
246
				final IWorkspace workspace = ResourcesPlugin.getWorkspace();
247
				try {
248
					workspace.run(new IWorkspaceRunnable() {
249
						public void run(IProgressMonitor monitor)
250
								throws CoreException {
251
							try {
252
								monitor.beginTask(
253
										ResourceMessages.NewProject_maintaskLabel,
254
										2);
255
256
								// first Task create project
257
								if (monitor.isCanceled()) {
258
									throw new OperationCanceledException();
259
								}
260
								IProject newProject = createNewProject(
261
										description, workspace,
262
										new SubProgressMonitor(monitor, 1));
263
264
								// second Task configure it (add folder, file
265
								// ...)
266
								if (monitor.isCanceled()) {
267
									throw new OperationCanceledException();
268
								}
269
								configureProject(newProject,
270
										new SubProgressMonitor(monitor, 1));
271
							} finally {
272
								monitor.done();
273
							}
274
						}
275
					}, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
276
				} catch (CoreException e) {
277
					throw new InvocationTargetException(e);
278
				}
279
			}
280
		};
281
282
		// run the new project creation operation
283
		try {
284
			getContainer().run(true, true, op);
285
		} catch (InterruptedException e) {
286
			// nothing to do.
287
		} catch (InvocationTargetException t) {
288
			if (t.getTargetException() instanceof CoreException) {
289
				CoreException cause = (CoreException) t.getTargetException();
290
				StatusAdapter status;
291
				if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
292
					status = new StatusAdapter(
293
							StatusUtil.newStatus(
294
									IStatus.WARNING,
295
									NLS.bind(
296
											ResourceMessages.NewProject_caseVariantExistsError,
297
											description.getName()), cause));
298
				} else {
299
					status = new StatusAdapter(StatusUtil.newStatus(cause
300
							.getStatus().getSeverity(),
301
							ResourceMessages.NewProject_errorMessage, cause));
302
				}
303
				status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
304
						ResourceMessages.NewProject_errorMessage);
305
				StatusManager.getManager().handle(status, StatusManager.BLOCK);
306
			} else {
307
				StatusAdapter status = new StatusAdapter(new Status(
308
						IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0,
309
						NLS.bind(ResourceMessages.NewProject_internalError,
310
								t.getMessage()), t));
311
				status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
312
						ResourceMessages.NewProject_errorMessage);
313
				StatusManager.getManager().handle(status,
314
						StatusManager.LOG | StatusManager.BLOCK);
315
			}
316
317
		}
318
319
		// In all case we try to get the created project (this is the common
320
		// eclipse wizard behavior... perhaps not the best)
321
		IProject project = ResourcesPlugin.getWorkspace().getRoot()
322
				.getProject(description.getName());
323
		if (project.exists())
324
			return project;
325
		return null;
326
	}
327
	
328
	/**
329
	 * Updates the perspective based on the current settings in the
330
	 * Workbench/Perspectives preference page.
331
	 * 
332
	 * Use the setting for the new perspective opening if we are set to open in
333
	 * a new perspective.
334
	 * <p>
335
	 * A new project wizard class will need to implement the
336
	 * <code>IExecutableExtension</code> interface so as to gain access to the
337
	 * wizard's <code>IConfigurationElement</code>. That is the configuration
338
	 * element to pass into this method.
339
	 * </p>
340
	 * 
341
	 * @param configElement -
342
	 *            the element we are updating with
343
	 * 
344
	 * @see IPreferenceConstants#OPM_NEW_WINDOW
345
	 * @see IPreferenceConstants#OPM_ACTIVE_PAGE
346
	 * @see IWorkbenchPreferenceConstants#NO_NEW_PERSPECTIVE
347
	 */
348
	public static void updatePerspective(IConfigurationElement configElement) {
349
		// Do not change perspective if the configuration element is
350
		// not specified.
351
		if (configElement == null) {
352
			return;
353
		}
354
355
		// Retrieve the new project open perspective preference setting
356
		String perspSetting = PrefUtil.getAPIPreferenceStore().getString(
357
				IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE);
358
359
		String promptSetting = IDEWorkbenchPlugin.getDefault()
360
				.getPreferenceStore().getString(
361
						IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
362
363
		// Return if do not switch perspective setting and are not prompting
364
		if (!(promptSetting.equals(MessageDialogWithToggle.PROMPT))
365
				&& perspSetting
366
						.equals(IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE)) {
367
			return;
368
		}
369
370
		// Read the requested perspective id to be opened.
371
		String finalPerspId = configElement.getAttribute(FINAL_PERSPECTIVE);
372
		if (finalPerspId == null) {
373
			return;
374
		}
375
376
		// Map perspective id to descriptor.
377
		IPerspectiveRegistry reg = PlatformUI.getWorkbench()
378
				.getPerspectiveRegistry();
379
380
		// leave this code in - the perspective of a given project may map to
381
		// activities other than those that the wizard itself maps to.
382
		IPerspectiveDescriptor finalPersp = reg
383
				.findPerspectiveWithId(finalPerspId);
384
		if (finalPersp != null && finalPersp instanceof IPluginContribution) {
385
			IPluginContribution contribution = (IPluginContribution) finalPersp;
386
			if (contribution.getPluginId() != null) {
387
				IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI
388
						.getWorkbench().getActivitySupport();
389
				IActivityManager activityManager = workbenchActivitySupport
390
						.getActivityManager();
391
				IIdentifier identifier = activityManager
392
						.getIdentifier(WorkbenchActivityHelper
393
								.createUnifiedId(contribution));
394
				Set idActivities = identifier.getActivityIds();
395
396
				if (!idActivities.isEmpty()) {
397
					Set enabledIds = new HashSet(activityManager
398
							.getEnabledActivityIds());
399
400
					if (enabledIds.addAll(idActivities)) {
401
						workbenchActivitySupport
402
								.setEnabledActivityIds(enabledIds);
403
					}
404
				}
405
			}
406
		} else {
407
			IDEWorkbenchPlugin.log("Unable to find persective " //$NON-NLS-1$
408
					+ finalPerspId
409
					+ " in BasicNewProjectResourceWizard.updatePerspective"); //$NON-NLS-1$
410
			return;
411
		}
412
413
		// gather the preferred perspectives
414
		// always consider the final perspective (and those derived from it)
415
		// to be preferred
416
		ArrayList preferredPerspIds = new ArrayList();
417
		addPerspectiveAndDescendants(preferredPerspIds, finalPerspId);
418
		String preferred = configElement.getAttribute(PREFERRED_PERSPECTIVES);
419
		if (preferred != null) {
420
			StringTokenizer tok = new StringTokenizer(preferred, " \t\n\r\f,"); //$NON-NLS-1$
421
			while (tok.hasMoreTokens()) {
422
				addPerspectiveAndDescendants(preferredPerspIds, tok.nextToken());
423
			}
424
		}
425
426
		IWorkbenchWindow window = PlatformUI.getWorkbench()
427
				.getActiveWorkbenchWindow();
428
		if (window != null) {
429
			IWorkbenchPage page = window.getActivePage();
430
			if (page != null) {
431
				IPerspectiveDescriptor currentPersp = page.getPerspective();
432
433
				// don't switch if the current perspective is a preferred
434
				// perspective
435
				if (currentPersp != null
436
						&& preferredPerspIds.contains(currentPersp.getId())) {
437
					return;
438
				}
439
			}
440
441
			// prompt the user to switch
442
			if (!confirmPerspectiveSwitch(window, finalPersp)) {
443
				return;
444
			}
445
		}
446
447
		int workbenchPerspectiveSetting = WorkbenchPlugin.getDefault()
448
				.getPreferenceStore().getInt(
449
						IPreferenceConstants.OPEN_PERSP_MODE);
450
451
		// open perspective in new window setting
452
		if (workbenchPerspectiveSetting == IPreferenceConstants.OPM_NEW_WINDOW) {
453
			openInNewWindow(finalPersp);
454
			return;
455
		}
456
457
		// replace active perspective setting otherwise
458
		replaceCurrentPerspective(finalPersp);
459
	}
460
461
	/**
462
	 * Adds to the list all perspective IDs in the Workbench who's original ID
463
	 * matches the given ID.
464
	 * 
465
	 * @param perspectiveIds
466
	 *            the list of perspective IDs to supplement.
467
	 * @param id
468
	 *            the id to query.
469
	 * @since 3.0
470
	 */
471
	private static void addPerspectiveAndDescendants(List perspectiveIds,
472
			String id) {
473
		IPerspectiveRegistry registry = PlatformUI.getWorkbench()
474
				.getPerspectiveRegistry();
475
		IPerspectiveDescriptor[] perspectives = registry.getPerspectives();
476
		for (int i = 0; i < perspectives.length; i++) {
477
			// @issue illegal ref to workbench internal class;
478
			// consider adding getOriginalId() as API on IPerspectiveDescriptor
479
			PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]);
480
			if (descriptor.getOriginalId().equals(id)) {
481
				perspectiveIds.add(descriptor.getId());
482
			}
483
		}
484
	}
485
486
	/**
487
	 * Prompts the user for whether to switch perspectives.
488
	 * 
489
	 * @param window
490
	 *            The workbench window in which to switch perspectives; must not
491
	 *            be <code>null</code>
492
	 * @param finalPersp
493
	 *            The perspective to switch to; must not be <code>null</code>.
494
	 * 
495
	 * @return <code>true</code> if it's OK to switch, <code>false</code>
496
	 *         otherwise
497
	 */
498
	private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window,
499
			IPerspectiveDescriptor finalPersp) {
500
		IPreferenceStore store = IDEWorkbenchPlugin.getDefault()
501
				.getPreferenceStore();
502
		String pspm = store
503
				.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
504
		if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) {
505
			// Return whether or not we should always switch
506
			return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm);
507
		}
508
		String desc = finalPersp.getDescription();
509
		String message;
510
		if (desc == null || desc.length() == 0)
511
			message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage,
512
					finalPersp.getLabel());
513
		else
514
			message = NLS.bind(
515
					ResourceMessages.NewProject_perspSwitchMessageWithDesc,
516
					new String[] { finalPersp.getLabel(), desc });
517
518
		MessageDialogWithToggle dialog = MessageDialogWithToggle
519
				.openYesNoQuestion(window.getShell(),
520
						ResourceMessages.NewProject_perspSwitchTitle, message,
521
						null /* use the default message for the toggle */,
522
						false /* toggle is initially unchecked */, store,
523
						IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);
524
		int result = dialog.getReturnCode();
525
526
		// If we are not going to prompt anymore propogate the choice.
527
		if (dialog.getToggleState()) {
528
			String preferenceValue;
529
			if (result == IDialogConstants.YES_ID) {
530
				// Doesn't matter if it is replace or new window
531
				// as we are going to use the open perspective setting
532
				preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE;
533
			} else {
534
				preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE;
535
			}
536
537
			// update PROJECT_OPEN_NEW_PERSPECTIVE to correspond
538
			PrefUtil.getAPIPreferenceStore().setValue(
539
					IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE,
540
					preferenceValue);
541
		}
542
		return result == IDialogConstants.YES_ID;
543
	}
544
	
545
	/*
546
	 * (non-Javadoc) Opens a new window with a particular perspective and input.
547
	 */
548
	private static void openInNewWindow(IPerspectiveDescriptor desc) {
549
550
		// Open the page.
551
		try {
552
			PlatformUI.getWorkbench().openWorkbenchWindow(desc.getId(),
553
					ResourcesPlugin.getWorkspace().getRoot());
554
		} catch (WorkbenchException e) {
555
			IWorkbenchWindow window = PlatformUI.getWorkbench()
556
					.getActiveWorkbenchWindow();
557
			if (window != null) {
558
				ErrorDialog.openError(window.getShell(), WINDOW_PROBLEMS_TITLE,
559
						e.getMessage(), e.getStatus());
560
			}
561
		}
562
	}
563
564
	/*
565
	 * (non-Javadoc) Replaces the current perspective with the new one.
566
	 */
567
	private static void replaceCurrentPerspective(IPerspectiveDescriptor persp) {
568
569
		// Get the active page.
570
		IWorkbenchWindow window = PlatformUI.getWorkbench()
571
				.getActiveWorkbenchWindow();
572
		if (window == null) {
573
			return;
574
		}
575
		IWorkbenchPage page = window.getActivePage();
576
		if (page == null) {
577
			return;
578
		}
579
580
		// Set the perspective.
581
		page.setPerspective(persp);
582
	}
583
584
}

Return to bug 166947