001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.plugin;
011:
012: import java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.resources.IProject;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.core.runtime.IExecutableExtension;
018: import org.eclipse.core.runtime.IPath;
019: import org.eclipse.jface.wizard.IWizardPage;
020: import org.eclipse.pde.internal.ui.PDEPlugin;
021: import org.eclipse.pde.internal.ui.PDEPluginImages;
022: import org.eclipse.pde.internal.ui.PDEUIMessages;
023: import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
024: import org.eclipse.pde.internal.ui.wizards.NewWizard;
025: import org.eclipse.ui.IWorkingSet;
026: import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
027:
028: public class NewFragmentProjectWizard extends NewWizard implements
029: IExecutableExtension {
030:
031: private NewProjectCreationPage fMainPage;
032: private ContentPage fContentPage;
033: private FragmentFieldData fFragmentData;
034: private IProjectProvider fProjectProvider;
035: private IConfigurationElement fConfig;
036:
037: public NewFragmentProjectWizard() {
038: setDefaultPageImageDescriptor(PDEPluginImages.DESC_NEWFRAGPRJ_WIZ);
039: setWindowTitle(PDEUIMessages.NewFragmentProjectWizard_title);
040: setNeedsProgressMonitor(true);
041: PDEPlugin.getDefault().getLabelProvider().connect(this );
042: fFragmentData = new FragmentFieldData();
043: }
044:
045: /* (non-Javadoc)
046: * @see org.eclipse.jface.wizard.Wizard#addPages()
047: */
048: public void addPages() {
049: fMainPage = new NewProjectCreationPage(
050: "main", fFragmentData, true, getSelection()); //$NON-NLS-1$
051: fMainPage
052: .setTitle(PDEUIMessages.NewProjectWizard_MainPage_ftitle);
053: fMainPage
054: .setDescription(PDEUIMessages.NewProjectWizard_MainPage_fdesc);
055: addPage(fMainPage);
056:
057: fProjectProvider = new IProjectProvider() {
058: public String getProjectName() {
059: return fMainPage.getProjectName();
060: }
061:
062: public IProject getProject() {
063: return fMainPage.getProjectHandle();
064: }
065:
066: public IPath getLocationPath() {
067: return fMainPage.getLocationPath();
068: }
069: };
070: fContentPage = new FragmentContentPage(
071: "page2", fProjectProvider, fMainPage, fFragmentData); //$NON-NLS-1$
072: addPage(fContentPage);
073: }
074:
075: /* (non-Javadoc)
076: * @see org.eclipse.jface.wizard.Wizard#canFinish()
077: */
078: public boolean canFinish() {
079: IWizardPage page = getContainer().getCurrentPage();
080: return (page.isPageComplete() && page != fMainPage);
081: }
082:
083: /*
084: * (non-Javadoc)
085: *
086: * @see org.eclipse.pde.internal.ui.wizards.NewWizard#performFinish()
087: */
088: public boolean performFinish() {
089: try {
090: fMainPage.updateData();
091: fContentPage.updateData();
092: BasicNewProjectResourceWizard.updatePerspective(fConfig);
093: getContainer().run(
094: false,
095: true,
096: new NewProjectCreationOperation(fFragmentData,
097: fProjectProvider, null));
098:
099: IWorkingSet[] workingSets = fMainPage
100: .getSelectedWorkingSets();
101: getWorkbench().getWorkingSetManager().addToWorkingSets(
102: fProjectProvider.getProject(), workingSets);
103:
104: return true;
105: } catch (InvocationTargetException e) {
106: PDEPlugin.logException(e);
107: } catch (InterruptedException e) {
108: }
109: return false;
110: }
111:
112: /* (non-Javadoc)
113: * @see org.eclipse.jface.wizard.Wizard#dispose()
114: */
115: public void dispose() {
116: super .dispose();
117: PDEPlugin.getDefault().getLabelProvider().disconnect(this );
118: }
119:
120: /* (non-Javadoc)
121: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
122: */
123: public void setInitializationData(IConfigurationElement config,
124: String propertyName, Object data) throws CoreException {
125: fConfig = config;
126: }
127:
128: public String getFragmentId() {
129: return fFragmentData.getId();
130: }
131: }
|