Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 188911 Details for
Bug 166947
[Wizards] Better extensibility for BasicNewProjectResourceWizard for RCP needed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
a generic project wizard
patch_genericprojectwizard.txt (text/plain), 43.64 KB, created by
Simon Bernard
on 2011-02-14 11:45:35 EST
(
hide
)
Description:
a generic project wizard
Filename:
MIME Type:
Creator:
Simon Bernard
Created:
2011-02-14 11:45:35 EST
Size:
43.64 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.ide >Index: src/org/eclipse/ui/internal/wizards/newresource/ResourceMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/newresource/ResourceMessages.java,v >retrieving revision 1.6 >diff -u -r1.6 ResourceMessages.java >--- src/org/eclipse/ui/internal/wizards/newresource/ResourceMessages.java 1 Jun 2010 19:22:30 -0000 1.6 >+++ src/org/eclipse/ui/internal/wizards/newresource/ResourceMessages.java 14 Feb 2011 16:39:31 -0000 >@@ -36,6 +36,9 @@ > public static String NewProject_internalError; > public static String NewProject_caseVariantExistsError; > public static String NewProject_perspSwitchTitle; >+ public static String NewProject_maintaskLabel; >+ public static String NewProject_subtaskLabel; >+ > /** > * Combines a perspective name and text for introducing a perspective switch > */ >Index: src/org/eclipse/ui/internal/wizards/newresource/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/newresource/messages.properties,v >retrieving revision 1.10 >diff -u -r1.10 messages.properties >--- src/org/eclipse/ui/internal/wizards/newresource/messages.properties 1 Jun 2010 19:22:30 -0000 1.10 >+++ src/org/eclipse/ui/internal/wizards/newresource/messages.properties 14 Feb 2011 16:39:31 -0000 >@@ -35,3 +35,5 @@ > NewProject_perspSwitchTitle = Open Associated Perspective? > NewProject_perspSwitchMessage = This kind of project is associated with the {0} perspective. Do you want to open this perspective now? > NewProject_perspSwitchMessageWithDesc = This kind of project is associated with the {0} perspective.\n\n{1}\n\nDo you want to open this perspective now? >+NewProject_maintaskLabel=Create Project. >+NewProject_subtaskLabel=Create new project ... >Index: src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java,v >retrieving revision 1.50 >diff -u -r1.50 BasicNewProjectResourceWizard.java >--- src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java 22 Oct 2008 22:15:59 -0000 1.50 >+++ src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java 14 Feb 2011 16:39:31 -0000 >@@ -13,66 +13,26 @@ > > package org.eclipse.ui.wizards.newresource; > >-import java.lang.reflect.InvocationTargetException; > import java.net.URI; >-import java.util.ArrayList; >-import java.util.HashSet; >-import java.util.List; >-import java.util.Set; >-import java.util.StringTokenizer; > >-import org.eclipse.core.commands.ExecutionException; > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IProjectDescription; >-import org.eclipse.core.resources.IResourceStatus; > import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IConfigurationElement; >-import org.eclipse.core.runtime.IExecutableExtension; > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; > import org.eclipse.jface.dialogs.Dialog; >-import org.eclipse.jface.dialogs.ErrorDialog; >-import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.IDialogSettings; >-import org.eclipse.jface.dialogs.MessageDialogWithToggle; >-import org.eclipse.jface.operation.IRunnableWithProgress; >-import org.eclipse.jface.preference.IPreferenceStore; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.viewers.IStructuredSelection; >-import org.eclipse.osgi.util.NLS; > import org.eclipse.swt.widgets.Composite; >-import org.eclipse.ui.IPerspectiveDescriptor; >-import org.eclipse.ui.IPerspectiveRegistry; >-import org.eclipse.ui.IPluginContribution; > import org.eclipse.ui.IWorkbench; >-import org.eclipse.ui.IWorkbenchPage; >-import org.eclipse.ui.IWorkbenchPreferenceConstants; >-import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.IWorkingSet; >-import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.WorkbenchException; >-import org.eclipse.ui.activities.IActivityManager; >-import org.eclipse.ui.activities.IIdentifier; >-import org.eclipse.ui.activities.IWorkbenchActivitySupport; >-import org.eclipse.ui.activities.WorkbenchActivityHelper; > import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; > import org.eclipse.ui.dialogs.WizardNewProjectReferencePage; >-import org.eclipse.ui.ide.IDE; >-import org.eclipse.ui.ide.undo.CreateProjectOperation; >-import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; >-import org.eclipse.ui.internal.IPreferenceConstants; >-import org.eclipse.ui.internal.WorkbenchPlugin; >-import org.eclipse.ui.internal.ide.IDEInternalPreferences; > import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; >-import org.eclipse.ui.internal.ide.StatusUtil; >-import org.eclipse.ui.internal.registry.PerspectiveDescriptor; >-import org.eclipse.ui.internal.util.PrefUtil; > import org.eclipse.ui.internal.wizards.newresource.ResourceMessages; >-import org.eclipse.ui.statushandlers.StatusAdapter; >-import org.eclipse.ui.statushandlers.StatusManager; > > /** > * Standard workbench wizard that creates a new project resource in the >@@ -91,47 +51,30 @@ > * dialog.open(); > * </pre> > * >- * During the call to <code>open</code>, the wizard dialog is presented to >- * the user. When the user hits Finish, a project resource with the >- * user-specified name is created, the dialog closes, and the call to >- * <code>open</code> returns. >+ * During the call to <code>open</code>, the wizard dialog is presented to the >+ * user. When the user hits Finish, a project resource with the user-specified >+ * name is created, the dialog closes, and the call to <code>open</code> >+ * returns. > * </p> >+ * > * @noextend This class is not intended to be subclassed by clients. > */ >-public class BasicNewProjectResourceWizard extends BasicNewResourceWizard >- implements IExecutableExtension { >- >+public class BasicNewProjectResourceWizard extends NewProjectWizard { >+ > /** > * The wizard id for creating new projects in the workspace. >+ * > * @since 3.4 > */ > public static final String WIZARD_ID = "org.eclipse.ui.wizards.new.project"; //$NON-NLS-1$ >- >+ > private WizardNewProjectCreationPage mainPage; > > private WizardNewProjectReferencePage referencePage; > >- // cache of newly-created project > private IProject newProject; > > /** >- * The config element which declares this wizard. >- */ >- private IConfigurationElement configElement; >- >- private static String WINDOW_PROBLEMS_TITLE = ResourceMessages.NewProject_errorOpeningWindow; >- >- /** >- * Extension attribute name for final perspective. >- */ >- private static final String FINAL_PERSPECTIVE = "finalPerspective"; //$NON-NLS-1$ >- >- /** >- * Extension attribute name for preferred perspectives. >- */ >- private static final String PREFERRED_PERSPECTIVES = "preferredPerspectives"; //$NON-NLS-1$ >- >- /** > * Creates a wizard for creating a new project resource in the workspace. > */ > public BasicNewProjectResourceWizard() { >@@ -156,7 +99,9 @@ > /* > * (non-Javadoc) > * >- * @see org.eclipse.ui.dialogs.WizardNewProjectCreationPage#createControl(org.eclipse.swt.widgets.Composite) >+ * @see >+ * org.eclipse.ui.dialogs.WizardNewProjectCreationPage#createControl >+ * (org.eclipse.swt.widgets.Composite) > */ > public void createControl(Composite parent) { > super.createControl(parent); >@@ -166,7 +111,7 @@ > new String[] { "org.eclipse.ui.resourceWorkingSetPage" }); //$NON-NLS-1$ > Dialog.applyDialogFont(getControl()); > } >- }; >+ }; > mainPage.setTitle(ResourceMessages.NewProject_title); > mainPage.setDescription(ResourceMessages.NewProject_description); > this.addPage(mainPage); >@@ -182,27 +127,14 @@ > } > } > >- /** >- * Creates a new project resource with the selected name. >- * <p> >- * In normal usage, this method is invoked after the user has pressed Finish >- * on the wizard; the enablement of the Finish button implies that all >- * controls on the pages currently contain valid values. >- * </p> >- * <p> >- * Note that this wizard caches the new project once it has been >- * successfully created; subsequent invocations of this method will answer >- * the same project resource without attempting to create it again. >- * </p> >+ /* >+ * (non-Javadoc) > * >- * @return the created project resource, or <code>null</code> if the >- * project was not created >+ * @see >+ * org.eclipse.ui.wizards.newresource.NewProjectWizard#createProjectDescription >+ * () > */ >- private IProject createNewProject() { >- if (newProject != null) { >- return newProject; >- } >- >+ protected IProjectDescription createProjectDescription() { > // get a project handle > final IProject newProjectHandle = mainPage.getProjectHandle(); > >@@ -225,78 +157,30 @@ > } > } > >- // create the new project operation >- IRunnableWithProgress op = new IRunnableWithProgress() { >- public void run(IProgressMonitor monitor) >- throws InvocationTargetException { >- CreateProjectOperation op = new CreateProjectOperation( >- description, ResourceMessages.NewProject_windowTitle); >- try { >- // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901 >- // directly execute the operation so that the undo state is >- // not preserved. Making this undoable resulted in too many >- // accidental file deletions. >- op.execute(monitor, WorkspaceUndoUtil >- .getUIInfoAdapter(getShell())); >- } catch (ExecutionException e) { >- throw new InvocationTargetException(e); >- } >- } >- }; >- >- // run the new project creation operation >- try { >- getContainer().run(true, true, op); >- } catch (InterruptedException e) { >- return null; >- } catch (InvocationTargetException e) { >- Throwable t = e.getTargetException(); >- if (t instanceof ExecutionException >- && t.getCause() instanceof CoreException) { >- CoreException cause = (CoreException) t.getCause(); >- StatusAdapter status; >- if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { >- status = new StatusAdapter( >- StatusUtil >- .newStatus( >- IStatus.WARNING, >- NLS >- .bind( >- ResourceMessages.NewProject_caseVariantExistsError, >- newProjectHandle >- .getName()), >- cause)); >- } else { >- status = new StatusAdapter(StatusUtil.newStatus(cause >- .getStatus().getSeverity(), >- ResourceMessages.NewProject_errorMessage, cause)); >- } >- status.setProperty(StatusAdapter.TITLE_PROPERTY, >- ResourceMessages.NewProject_errorMessage); >- StatusManager.getManager().handle(status, StatusManager.BLOCK); >- } else { >- StatusAdapter status = new StatusAdapter(new Status( >- IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0, >- NLS.bind(ResourceMessages.NewProject_internalError, t >- .getMessage()), t)); >- status.setProperty(StatusAdapter.TITLE_PROPERTY, >- ResourceMessages.NewProject_errorMessage); >- StatusManager.getManager().handle(status, >- StatusManager.LOG | StatusManager.BLOCK); >- } >- return null; >- } >- >- newProject = newProjectHandle; >+ return description; >+ } > >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.ui.wizards.newresource.NewProjectWizard#createNewProject( >+ * org.eclipse.core.resources.IProjectDescription, >+ * org.eclipse.core.resources.IWorkspace, >+ * org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ protected IProject createNewProject(IProjectDescription projectDescription, >+ IWorkspace workspace, IProgressMonitor monitor) >+ throws CoreException { >+ newProject = super.createNewProject(projectDescription, workspace, >+ monitor); > return newProject; > } > > /** > * Returns the newly created project. > * >- * @return the created project, or <code>null</code> if project not >- * created >+ * @return the created project, or <code>null</code> if project not created > */ > public IProject getNewProject() { > return newProject; >@@ -320,295 +204,19 @@ > setDefaultPageImageDescriptor(desc); > } > >- /* >- * (non-Javadoc) Opens a new window with a particular perspective and input. >- */ >- private static void openInNewWindow(IPerspectiveDescriptor desc) { >- >- // Open the page. >- try { >- PlatformUI.getWorkbench().openWorkbenchWindow(desc.getId(), >- ResourcesPlugin.getWorkspace().getRoot()); >- } catch (WorkbenchException e) { >- IWorkbenchWindow window = PlatformUI.getWorkbench() >- .getActiveWorkbenchWindow(); >- if (window != null) { >- ErrorDialog.openError(window.getShell(), WINDOW_PROBLEMS_TITLE, >- e.getMessage(), e.getStatus()); >- } >- } >- } >- >- /* >- * (non-Javadoc) Method declared on IWizard. >- */ >- public boolean performFinish() { >- createNewProject(); >- >- if (newProject == null) { >- return false; >- } >- >- IWorkingSet[] workingSets = mainPage.getSelectedWorkingSets(); >- getWorkbench().getWorkingSetManager().addToWorkingSets(newProject, >- workingSets); >- >- updatePerspective(); >- selectAndReveal(newProject); >- >- return true; >- } >- >- /* >- * (non-Javadoc) Replaces the current perspective with the new one. >- */ >- private static void replaceCurrentPerspective(IPerspectiveDescriptor persp) { >- >- // Get the active page. >- IWorkbenchWindow window = PlatformUI.getWorkbench() >- .getActiveWorkbenchWindow(); >- if (window == null) { >- return; >- } >- IWorkbenchPage page = window.getActivePage(); >- if (page == null) { >- return; >- } >- >- // Set the perspective. >- page.setPerspective(persp); >- } >- > /** >- * Stores the configuration element for the wizard. The config element will >- * be used in <code>performFinish</code> to set the result perspective. >- */ >- public void setInitializationData(IConfigurationElement cfig, >- String propertyName, Object data) { >- configElement = cfig; >- } >- >- /** >- * Updates the perspective for the active page within the window. >- */ >- protected void updatePerspective() { >- updatePerspective(configElement); >- } >- >- /** >- * Updates the perspective based on the current settings in the >- * Workbench/Perspectives preference page. >- * >- * Use the setting for the new perspective opening if we are set to open in >- * a new perspective. >- * <p> >- * A new project wizard class will need to implement the >- * <code>IExecutableExtension</code> interface so as to gain access to the >- * wizard's <code>IConfigurationElement</code>. That is the configuration >- * element to pass into this method. >- * </p> >- * >- * @param configElement - >- * the element we are updating with >- * >- * @see IPreferenceConstants#OPM_NEW_WINDOW >- * @see IPreferenceConstants#OPM_ACTIVE_PAGE >- * @see IWorkbenchPreferenceConstants#NO_NEW_PERSPECTIVE >+ * @deprecated use >+ * {@link NewProjectWizard#updatePerspective(IConfigurationElement)} >+ * . > */ > public static void updatePerspective(IConfigurationElement configElement) { >- // Do not change perspective if the configuration element is >- // not specified. >- if (configElement == null) { >- return; >- } >- >- // Retrieve the new project open perspective preference setting >- String perspSetting = PrefUtil.getAPIPreferenceStore().getString( >- IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE); >- >- String promptSetting = IDEWorkbenchPlugin.getDefault() >- .getPreferenceStore().getString( >- IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); >- >- // Return if do not switch perspective setting and are not prompting >- if (!(promptSetting.equals(MessageDialogWithToggle.PROMPT)) >- && perspSetting >- .equals(IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE)) { >- return; >- } >- >- // Read the requested perspective id to be opened. >- String finalPerspId = configElement.getAttribute(FINAL_PERSPECTIVE); >- if (finalPerspId == null) { >- return; >- } >- >- // Map perspective id to descriptor. >- IPerspectiveRegistry reg = PlatformUI.getWorkbench() >- .getPerspectiveRegistry(); >- >- // leave this code in - the perspective of a given project may map to >- // activities other than those that the wizard itself maps to. >- IPerspectiveDescriptor finalPersp = reg >- .findPerspectiveWithId(finalPerspId); >- if (finalPersp != null && finalPersp instanceof IPluginContribution) { >- IPluginContribution contribution = (IPluginContribution) finalPersp; >- if (contribution.getPluginId() != null) { >- IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI >- .getWorkbench().getActivitySupport(); >- IActivityManager activityManager = workbenchActivitySupport >- .getActivityManager(); >- IIdentifier identifier = activityManager >- .getIdentifier(WorkbenchActivityHelper >- .createUnifiedId(contribution)); >- Set idActivities = identifier.getActivityIds(); >- >- if (!idActivities.isEmpty()) { >- Set enabledIds = new HashSet(activityManager >- .getEnabledActivityIds()); >- >- if (enabledIds.addAll(idActivities)) { >- workbenchActivitySupport >- .setEnabledActivityIds(enabledIds); >- } >- } >- } >- } else { >- IDEWorkbenchPlugin.log("Unable to find persective " //$NON-NLS-1$ >- + finalPerspId >- + " in BasicNewProjectResourceWizard.updatePerspective"); //$NON-NLS-1$ >- return; >- } >- >- // gather the preferred perspectives >- // always consider the final perspective (and those derived from it) >- // to be preferred >- ArrayList preferredPerspIds = new ArrayList(); >- addPerspectiveAndDescendants(preferredPerspIds, finalPerspId); >- String preferred = configElement.getAttribute(PREFERRED_PERSPECTIVES); >- if (preferred != null) { >- StringTokenizer tok = new StringTokenizer(preferred, " \t\n\r\f,"); //$NON-NLS-1$ >- while (tok.hasMoreTokens()) { >- addPerspectiveAndDescendants(preferredPerspIds, tok.nextToken()); >- } >- } >- >- IWorkbenchWindow window = PlatformUI.getWorkbench() >- .getActiveWorkbenchWindow(); >- if (window != null) { >- IWorkbenchPage page = window.getActivePage(); >- if (page != null) { >- IPerspectiveDescriptor currentPersp = page.getPerspective(); >- >- // don't switch if the current perspective is a preferred >- // perspective >- if (currentPersp != null >- && preferredPerspIds.contains(currentPersp.getId())) { >- return; >- } >- } >- >- // prompt the user to switch >- if (!confirmPerspectiveSwitch(window, finalPersp)) { >- return; >- } >- } >- >- int workbenchPerspectiveSetting = WorkbenchPlugin.getDefault() >- .getPreferenceStore().getInt( >- IPreferenceConstants.OPEN_PERSP_MODE); >- >- // open perspective in new window setting >- if (workbenchPerspectiveSetting == IPreferenceConstants.OPM_NEW_WINDOW) { >- openInNewWindow(finalPersp); >- return; >- } >- >- // replace active perspective setting otherwise >- replaceCurrentPerspective(finalPersp); >+ NewProjectWizard.updatePerspective(configElement); > } >- >- /** >- * Adds to the list all perspective IDs in the Workbench who's original ID >- * matches the given ID. >- * >- * @param perspectiveIds >- * the list of perspective IDs to supplement. >- * @param id >- * the id to query. >- * @since 3.0 >- */ >- private static void addPerspectiveAndDescendants(List perspectiveIds, >- String id) { >- IPerspectiveRegistry registry = PlatformUI.getWorkbench() >- .getPerspectiveRegistry(); >- IPerspectiveDescriptor[] perspectives = registry.getPerspectives(); >- for (int i = 0; i < perspectives.length; i++) { >- // @issue illegal ref to workbench internal class; >- // consider adding getOriginalId() as API on IPerspectiveDescriptor >- PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]); >- if (descriptor.getOriginalId().equals(id)) { >- perspectiveIds.add(descriptor.getId()); >- } >- } >- } >- >- /** >- * Prompts the user for whether to switch perspectives. >- * >- * @param window >- * The workbench window in which to switch perspectives; must not >- * be <code>null</code> >- * @param finalPersp >- * The perspective to switch to; must not be <code>null</code>. >- * >- * @return <code>true</code> if it's OK to switch, <code>false</code> >- * otherwise >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.wizards.newresource.NewProjectWizard#getSelectedWorkingSets() > */ >- private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window, >- IPerspectiveDescriptor finalPersp) { >- IPreferenceStore store = IDEWorkbenchPlugin.getDefault() >- .getPreferenceStore(); >- String pspm = store >- .getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); >- if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) { >- // Return whether or not we should always switch >- return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm); >- } >- String desc = finalPersp.getDescription(); >- String message; >- if (desc == null || desc.length() == 0) >- message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, >- finalPersp.getLabel()); >- else >- message = NLS.bind( >- ResourceMessages.NewProject_perspSwitchMessageWithDesc, >- new String[] { finalPersp.getLabel(), desc }); >- >- MessageDialogWithToggle dialog = MessageDialogWithToggle >- .openYesNoQuestion(window.getShell(), >- ResourceMessages.NewProject_perspSwitchTitle, message, >- null /* use the default message for the toggle */, >- false /* toggle is initially unchecked */, store, >- IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); >- int result = dialog.getReturnCode(); >- >- // If we are not going to prompt anymore propogate the choice. >- if (dialog.getToggleState()) { >- String preferenceValue; >- if (result == IDialogConstants.YES_ID) { >- // Doesn't matter if it is replace or new window >- // as we are going to use the open perspective setting >- preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE; >- } else { >- preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE; >- } >- >- // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond >- PrefUtil.getAPIPreferenceStore().setValue( >- IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, >- preferenceValue); >- } >- return result == IDialogConstants.YES_ID; >+ protected IWorkingSet[] getSelectedWorkingSets() { >+ return mainPage.getSelectedWorkingSets(); > } > } >Index: src/org/eclipse/ui/wizards/newresource/NewProjectWizard.java >=================================================================== >RCS file: src/org/eclipse/ui/wizards/newresource/NewProjectWizard.java >diff -N src/org/eclipse/ui/wizards/newresource/NewProjectWizard.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/wizards/newresource/NewProjectWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,584 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Sierra Wireless/Simon Bernard - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.wizards.newresource; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.util.ArrayList; >+import java.util.HashSet; >+import java.util.List; >+import java.util.Set; >+import java.util.StringTokenizer; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IProjectDescription; >+import org.eclipse.core.resources.IResourceStatus; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.IWorkspaceRunnable; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExecutableExtension; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.jface.dialogs.ErrorDialog; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.MessageDialogWithToggle; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.ui.IPerspectiveDescriptor; >+import org.eclipse.ui.IPerspectiveRegistry; >+import org.eclipse.ui.IPluginContribution; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchPreferenceConstants; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.IWorkingSet; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.WorkbenchException; >+import org.eclipse.ui.activities.IActivityManager; >+import org.eclipse.ui.activities.IIdentifier; >+import org.eclipse.ui.activities.IWorkbenchActivitySupport; >+import org.eclipse.ui.activities.WorkbenchActivityHelper; >+import org.eclipse.ui.ide.IDE; >+import org.eclipse.ui.internal.IPreferenceConstants; >+import org.eclipse.ui.internal.WorkbenchPlugin; >+import org.eclipse.ui.internal.ide.IDEInternalPreferences; >+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; >+import org.eclipse.ui.internal.ide.StatusUtil; >+import org.eclipse.ui.internal.registry.PerspectiveDescriptor; >+import org.eclipse.ui.internal.util.PrefUtil; >+import org.eclipse.ui.internal.wizards.newresource.ResourceMessages; >+import org.eclipse.ui.statushandlers.IStatusAdapterConstants; >+import org.eclipse.ui.statushandlers.StatusAdapter; >+import org.eclipse.ui.statushandlers.StatusManager; >+ >+/** >+ * A general-purpose wizard to create project.<br> >+ * >+ * Clients should extend the class and override >+ * <code>createProjectDescription</code>,<code>addPages</code> and >+ * <code>configureProject</code> protected methods. >+ * <p> >+ * <code>addPages</code> will allow you to define pages which will collect >+ * information to create your project.<br> >+ * <code>createProjectDescription</code> must be used to create the >+ * ProjectDescription from collected information (in wizard page). >+ * <code>configureProject</code> must be used to do specific project >+ * configuration (e.g. create folder or file ...). >+ * <p> >+ * >+ * @since 3.7 >+ */ >+public abstract class NewProjectWizard extends BasicNewResourceWizard implements >+ IExecutableExtension { >+ >+ /** >+ * The config element which declares this wizard. >+ */ >+ private IConfigurationElement configElement; >+ >+ /** >+ * Extension attribute name for final perspective. >+ */ >+ private static final String FINAL_PERSPECTIVE = "finalPerspective"; //$NON-NLS-1$ >+ >+ /** >+ * Extension attribute name for preferred perspectives. >+ */ >+ private static final String PREFERRED_PERSPECTIVES = "preferredPerspectives"; //$NON-NLS-1$ >+ >+ private static String WINDOW_PROBLEMS_TITLE = ResourceMessages.NewProject_errorOpeningWindow; >+ >+ /** >+ * client must extend it to create the project description used to create >+ * the project >+ * >+ * @extend >+ */ >+ protected abstract IProjectDescription createProjectDescription(); >+ >+ /** >+ * Create the project from the given project description.<br> >+ * This method will be seen as an atomic operation with the configureProject >+ * method as workspace level. >+ * >+ * @param projectDescription >+ * description used to create project >+ * @param workspace >+ * workspace in which project will be created >+ * @param monitor >+ * monitor to manage task progess and task cancellation >+ * @return the created project >+ * @throws CoreException >+ * throw coreException if a problem occurs >+ */ >+ protected IProject createNewProject(IProjectDescription projectDescription, >+ IWorkspace workspace, IProgressMonitor monitor) >+ throws CoreException { >+ try { >+ monitor.beginTask(ResourceMessages.NewProject_subtaskLabel, 2); >+ IProject project = workspace.getRoot().getProject( >+ projectDescription.getName()); >+ project.create(projectDescription, new SubProgressMonitor(monitor, >+ 1)); >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ project.open(new SubProgressMonitor(monitor, 1)); >+ return project; >+ } finally { >+ monitor.done(); >+ } >+ } >+ >+ /** >+ * Could be use by client to configure the project after creation. (like add >+ * folder or file .. )<br> >+ * This method will be seen as an atomic operation with the project creation >+ * at workspace level. >+ * <p> >+ * client must use monitor to manage task progess and task cancellation. >+ * <p> >+ * >+ * <pre> >+ * try { >+ * monitor.beginTask("Configure project", nbtask); >+ * ... >+ * monitor.worked(1) >+ * if (monitor.isCanceled()) { >+ * throw new OperationCanceledException(); >+ * } >+ * ... >+ * monitor.worked(2) >+ * }finally{ >+ * monitor.done(); >+ * } >+ * </pre> >+ * >+ * >+ * @param newProject >+ * project created to configure >+ * @param monitor >+ * monitor to manage task progess and task cancellation >+ * @throws CoreException >+ * client could throw coreException if a problem occurs >+ */ >+ protected void configureProject(IProject newProject, >+ IProgressMonitor monitor) throws CoreException { >+ // nothing to do by default >+ } >+ >+ /** >+ * @extend could be extend to add project in given working sets >+ */ >+ protected IWorkingSet[] getSelectedWorkingSets() { >+ // no working set by default >+ return null; >+ } >+ >+ /** >+ * @see org.eclipse.jface.wizard.Wizard#performFinish() >+ */ >+ public boolean performFinish() { >+ IProject newProject = createNewProjectInWizardContext(); >+ >+ if (newProject == null) { >+ return false; >+ } >+ >+ // add project to working set if needed >+ IWorkingSet[] workingSets = getSelectedWorkingSets(); >+ if (workingSets != null && workingSets.length > 0) >+ getWorkbench().getWorkingSetManager().addToWorkingSets(newProject, >+ workingSets); >+ >+ // change perspective >+ updatePerspective(); >+ >+ // select the created project >+ selectAndReveal(newProject); >+ >+ return true; >+ } >+ >+ /** >+ * Stores the configuration element for the wizard. The config element will >+ * be used in <code>performFinish</code> to set the result perspective. >+ */ >+ public void setInitializationData(IConfigurationElement cfig, >+ String propertyName, Object data) { >+ configElement = cfig; >+ } >+ >+ /** >+ * Updates the perspective for the active page within the window. >+ */ >+ protected void updatePerspective() { >+ updatePerspective(configElement); >+ } >+ >+ /** >+ * Create the new project in the wizard context.<br> >+ * Creation is done as an atomic workspace operation >+ * >+ * @noextend This class is not intended to be subclassed by clients. >+ */ >+ protected IProject createNewProjectInWizardContext() { >+ // create project description >+ final IProjectDescription description = createProjectDescription(); >+ >+ // create the new project operation from project description >+ IRunnableWithProgress op = new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) >+ throws InvocationTargetException { >+ >+ final IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ try { >+ workspace.run(new IWorkspaceRunnable() { >+ public void run(IProgressMonitor monitor) >+ throws CoreException { >+ try { >+ monitor.beginTask( >+ ResourceMessages.NewProject_maintaskLabel, >+ 2); >+ >+ // first Task create project >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ IProject newProject = createNewProject( >+ description, workspace, >+ new SubProgressMonitor(monitor, 1)); >+ >+ // second Task configure it (add folder, file >+ // ...) >+ if (monitor.isCanceled()) { >+ throw new OperationCanceledException(); >+ } >+ configureProject(newProject, >+ new SubProgressMonitor(monitor, 1)); >+ } finally { >+ monitor.done(); >+ } >+ } >+ }, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor); >+ } catch (CoreException e) { >+ throw new InvocationTargetException(e); >+ } >+ } >+ }; >+ >+ // run the new project creation operation >+ try { >+ getContainer().run(true, true, op); >+ } catch (InterruptedException e) { >+ // nothing to do. >+ } catch (InvocationTargetException t) { >+ if (t.getTargetException() instanceof CoreException) { >+ CoreException cause = (CoreException) t.getTargetException(); >+ StatusAdapter status; >+ if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { >+ status = new StatusAdapter( >+ StatusUtil.newStatus( >+ IStatus.WARNING, >+ NLS.bind( >+ ResourceMessages.NewProject_caseVariantExistsError, >+ description.getName()), cause)); >+ } else { >+ status = new StatusAdapter(StatusUtil.newStatus(cause >+ .getStatus().getSeverity(), >+ ResourceMessages.NewProject_errorMessage, cause)); >+ } >+ status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, >+ ResourceMessages.NewProject_errorMessage); >+ StatusManager.getManager().handle(status, StatusManager.BLOCK); >+ } else { >+ StatusAdapter status = new StatusAdapter(new Status( >+ IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0, >+ NLS.bind(ResourceMessages.NewProject_internalError, >+ t.getMessage()), t)); >+ status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, >+ ResourceMessages.NewProject_errorMessage); >+ StatusManager.getManager().handle(status, >+ StatusManager.LOG | StatusManager.BLOCK); >+ } >+ >+ } >+ >+ // In all case we try to get the created project (this is the common >+ // eclipse wizard behavior... perhaps not the best) >+ IProject project = ResourcesPlugin.getWorkspace().getRoot() >+ .getProject(description.getName()); >+ if (project.exists()) >+ return project; >+ return null; >+ } >+ >+ /** >+ * Updates the perspective based on the current settings in the >+ * Workbench/Perspectives preference page. >+ * >+ * Use the setting for the new perspective opening if we are set to open in >+ * a new perspective. >+ * <p> >+ * A new project wizard class will need to implement the >+ * <code>IExecutableExtension</code> interface so as to gain access to the >+ * wizard's <code>IConfigurationElement</code>. That is the configuration >+ * element to pass into this method. >+ * </p> >+ * >+ * @param configElement - >+ * the element we are updating with >+ * >+ * @see IPreferenceConstants#OPM_NEW_WINDOW >+ * @see IPreferenceConstants#OPM_ACTIVE_PAGE >+ * @see IWorkbenchPreferenceConstants#NO_NEW_PERSPECTIVE >+ */ >+ public static void updatePerspective(IConfigurationElement configElement) { >+ // Do not change perspective if the configuration element is >+ // not specified. >+ if (configElement == null) { >+ return; >+ } >+ >+ // Retrieve the new project open perspective preference setting >+ String perspSetting = PrefUtil.getAPIPreferenceStore().getString( >+ IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE); >+ >+ String promptSetting = IDEWorkbenchPlugin.getDefault() >+ .getPreferenceStore().getString( >+ IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); >+ >+ // Return if do not switch perspective setting and are not prompting >+ if (!(promptSetting.equals(MessageDialogWithToggle.PROMPT)) >+ && perspSetting >+ .equals(IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE)) { >+ return; >+ } >+ >+ // Read the requested perspective id to be opened. >+ String finalPerspId = configElement.getAttribute(FINAL_PERSPECTIVE); >+ if (finalPerspId == null) { >+ return; >+ } >+ >+ // Map perspective id to descriptor. >+ IPerspectiveRegistry reg = PlatformUI.getWorkbench() >+ .getPerspectiveRegistry(); >+ >+ // leave this code in - the perspective of a given project may map to >+ // activities other than those that the wizard itself maps to. >+ IPerspectiveDescriptor finalPersp = reg >+ .findPerspectiveWithId(finalPerspId); >+ if (finalPersp != null && finalPersp instanceof IPluginContribution) { >+ IPluginContribution contribution = (IPluginContribution) finalPersp; >+ if (contribution.getPluginId() != null) { >+ IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI >+ .getWorkbench().getActivitySupport(); >+ IActivityManager activityManager = workbenchActivitySupport >+ .getActivityManager(); >+ IIdentifier identifier = activityManager >+ .getIdentifier(WorkbenchActivityHelper >+ .createUnifiedId(contribution)); >+ Set idActivities = identifier.getActivityIds(); >+ >+ if (!idActivities.isEmpty()) { >+ Set enabledIds = new HashSet(activityManager >+ .getEnabledActivityIds()); >+ >+ if (enabledIds.addAll(idActivities)) { >+ workbenchActivitySupport >+ .setEnabledActivityIds(enabledIds); >+ } >+ } >+ } >+ } else { >+ IDEWorkbenchPlugin.log("Unable to find persective " //$NON-NLS-1$ >+ + finalPerspId >+ + " in BasicNewProjectResourceWizard.updatePerspective"); //$NON-NLS-1$ >+ return; >+ } >+ >+ // gather the preferred perspectives >+ // always consider the final perspective (and those derived from it) >+ // to be preferred >+ ArrayList preferredPerspIds = new ArrayList(); >+ addPerspectiveAndDescendants(preferredPerspIds, finalPerspId); >+ String preferred = configElement.getAttribute(PREFERRED_PERSPECTIVES); >+ if (preferred != null) { >+ StringTokenizer tok = new StringTokenizer(preferred, " \t\n\r\f,"); //$NON-NLS-1$ >+ while (tok.hasMoreTokens()) { >+ addPerspectiveAndDescendants(preferredPerspIds, tok.nextToken()); >+ } >+ } >+ >+ IWorkbenchWindow window = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow(); >+ if (window != null) { >+ IWorkbenchPage page = window.getActivePage(); >+ if (page != null) { >+ IPerspectiveDescriptor currentPersp = page.getPerspective(); >+ >+ // don't switch if the current perspective is a preferred >+ // perspective >+ if (currentPersp != null >+ && preferredPerspIds.contains(currentPersp.getId())) { >+ return; >+ } >+ } >+ >+ // prompt the user to switch >+ if (!confirmPerspectiveSwitch(window, finalPersp)) { >+ return; >+ } >+ } >+ >+ int workbenchPerspectiveSetting = WorkbenchPlugin.getDefault() >+ .getPreferenceStore().getInt( >+ IPreferenceConstants.OPEN_PERSP_MODE); >+ >+ // open perspective in new window setting >+ if (workbenchPerspectiveSetting == IPreferenceConstants.OPM_NEW_WINDOW) { >+ openInNewWindow(finalPersp); >+ return; >+ } >+ >+ // replace active perspective setting otherwise >+ replaceCurrentPerspective(finalPersp); >+ } >+ >+ /** >+ * Adds to the list all perspective IDs in the Workbench who's original ID >+ * matches the given ID. >+ * >+ * @param perspectiveIds >+ * the list of perspective IDs to supplement. >+ * @param id >+ * the id to query. >+ * @since 3.0 >+ */ >+ private static void addPerspectiveAndDescendants(List perspectiveIds, >+ String id) { >+ IPerspectiveRegistry registry = PlatformUI.getWorkbench() >+ .getPerspectiveRegistry(); >+ IPerspectiveDescriptor[] perspectives = registry.getPerspectives(); >+ for (int i = 0; i < perspectives.length; i++) { >+ // @issue illegal ref to workbench internal class; >+ // consider adding getOriginalId() as API on IPerspectiveDescriptor >+ PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]); >+ if (descriptor.getOriginalId().equals(id)) { >+ perspectiveIds.add(descriptor.getId()); >+ } >+ } >+ } >+ >+ /** >+ * Prompts the user for whether to switch perspectives. >+ * >+ * @param window >+ * The workbench window in which to switch perspectives; must not >+ * be <code>null</code> >+ * @param finalPersp >+ * The perspective to switch to; must not be <code>null</code>. >+ * >+ * @return <code>true</code> if it's OK to switch, <code>false</code> >+ * otherwise >+ */ >+ private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window, >+ IPerspectiveDescriptor finalPersp) { >+ IPreferenceStore store = IDEWorkbenchPlugin.getDefault() >+ .getPreferenceStore(); >+ String pspm = store >+ .getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); >+ if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) { >+ // Return whether or not we should always switch >+ return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm); >+ } >+ String desc = finalPersp.getDescription(); >+ String message; >+ if (desc == null || desc.length() == 0) >+ message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, >+ finalPersp.getLabel()); >+ else >+ message = NLS.bind( >+ ResourceMessages.NewProject_perspSwitchMessageWithDesc, >+ new String[] { finalPersp.getLabel(), desc }); >+ >+ MessageDialogWithToggle dialog = MessageDialogWithToggle >+ .openYesNoQuestion(window.getShell(), >+ ResourceMessages.NewProject_perspSwitchTitle, message, >+ null /* use the default message for the toggle */, >+ false /* toggle is initially unchecked */, store, >+ IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); >+ int result = dialog.getReturnCode(); >+ >+ // If we are not going to prompt anymore propogate the choice. >+ if (dialog.getToggleState()) { >+ String preferenceValue; >+ if (result == IDialogConstants.YES_ID) { >+ // Doesn't matter if it is replace or new window >+ // as we are going to use the open perspective setting >+ preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE; >+ } else { >+ preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE; >+ } >+ >+ // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond >+ PrefUtil.getAPIPreferenceStore().setValue( >+ IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, >+ preferenceValue); >+ } >+ return result == IDialogConstants.YES_ID; >+ } >+ >+ /* >+ * (non-Javadoc) Opens a new window with a particular perspective and input. >+ */ >+ private static void openInNewWindow(IPerspectiveDescriptor desc) { >+ >+ // Open the page. >+ try { >+ PlatformUI.getWorkbench().openWorkbenchWindow(desc.getId(), >+ ResourcesPlugin.getWorkspace().getRoot()); >+ } catch (WorkbenchException e) { >+ IWorkbenchWindow window = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow(); >+ if (window != null) { >+ ErrorDialog.openError(window.getShell(), WINDOW_PROBLEMS_TITLE, >+ e.getMessage(), e.getStatus()); >+ } >+ } >+ } >+ >+ /* >+ * (non-Javadoc) Replaces the current perspective with the new one. >+ */ >+ private static void replaceCurrentPerspective(IPerspectiveDescriptor persp) { >+ >+ // Get the active page. >+ IWorkbenchWindow window = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow(); >+ if (window == null) { >+ return; >+ } >+ IWorkbenchPage page = window.getActivePage(); >+ if (page == null) { >+ return; >+ } >+ >+ // Set the perspective. >+ page.setPerspective(persp); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 166947
: 188911