|
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 |
} |