001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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.pde.internal.ui.PDEPlugin;
020: import org.eclipse.pde.internal.ui.PDEPluginImages;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
023: import org.eclipse.pde.internal.ui.wizards.NewWizard;
024: import org.eclipse.pde.internal.ui.wizards.WizardElement;
025: import org.eclipse.swt.graphics.Image;
026: import org.eclipse.ui.IWorkingSet;
027: import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
028:
029: public class NewLibraryPluginProjectWizard extends NewWizard implements
030: IExecutableExtension {
031: public static final String DEF_PROJECT_NAME = "project_name"; //$NON-NLS-1$
032:
033: public static final String DEF_TEMPLATE_ID = "template-id"; //$NON-NLS-1$
034:
035: public static final String PLUGIN_POINT = "pluginContent"; //$NON-NLS-1$
036:
037: public static final String TAG_WIZARD = "wizard"; //$NON-NLS-1$
038:
039: private IConfigurationElement fConfig;
040:
041: private LibraryPluginJarsPage fJarsPage;
042:
043: private NewLibraryPluginCreationPage fMainPage;
044:
045: private LibraryPluginFieldData fPluginData;
046:
047: private IProjectProvider fProjectProvider;
048:
049: public NewLibraryPluginProjectWizard() {
050: setDefaultPageImageDescriptor(PDEPluginImages.DESC_JAR_TO_PLUGIN_WIZ);
051: setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
052: setWindowTitle(PDEUIMessages.NewLibraryPluginProjectWizard_title);
053: setNeedsProgressMonitor(true);
054: PDEPlugin.getDefault().getLabelProvider().connect(this );
055: fPluginData = new LibraryPluginFieldData();
056: }
057:
058: /*
059: * (non-Javadoc)
060: *
061: * @see org.eclipse.jface.wizard.Wizard#addPages()
062: */
063: public void addPages() {
064: fJarsPage = new LibraryPluginJarsPage("jars", fPluginData); //$NON-NLS-1$
065: addPage(fJarsPage);
066: fMainPage = new NewLibraryPluginCreationPage(
067: "main", fPluginData, getSelection()); //$NON-NLS-1$
068: String pname = getDefaultValue(DEF_PROJECT_NAME);
069: if (pname != null)
070: fMainPage.setInitialProjectName(pname);
071:
072: fProjectProvider = new IProjectProvider() {
073: public IPath getLocationPath() {
074: return fMainPage.getLocationPath();
075: }
076:
077: public IProject getProject() {
078: return fMainPage.getProjectHandle();
079: }
080:
081: public String getProjectName() {
082: return fMainPage.getProjectName();
083: }
084: };
085:
086: addPage(fMainPage);
087: }
088:
089: protected WizardElement createWizardElement(
090: IConfigurationElement config) {
091: String name = config.getAttribute(WizardElement.ATT_NAME);
092: String id = config.getAttribute(WizardElement.ATT_ID);
093: String className = config.getAttribute(WizardElement.ATT_CLASS);
094: if (name == null || id == null || className == null)
095: return null;
096: WizardElement element = new WizardElement(config);
097: String imageName = config.getAttribute(WizardElement.ATT_ICON);
098: if (imageName != null) {
099: String pluginID = config.getNamespaceIdentifier();
100: Image image = PDEPlugin.getDefault().getLabelProvider()
101: .getImageFromPlugin(pluginID, imageName);
102: element.setImage(image);
103: }
104: return element;
105: }
106:
107: /*
108: * (non-Javadoc)
109: *
110: * @see org.eclipse.jface.wizard.Wizard#dispose()
111: */
112: public void dispose() {
113: super .dispose();
114: PDEPlugin.getDefault().getLabelProvider().disconnect(this );
115: }
116:
117: /*
118: * (non-Javadoc)
119: *
120: * @see org.eclipse.pde.internal.ui.wizards.NewWizard#performFinish()
121: */
122: public boolean performFinish() {
123: try {
124: fJarsPage.updateData();
125: fMainPage.updateData();
126: BasicNewProjectResourceWizard.updatePerspective(fConfig);
127: getContainer().run(
128: false,
129: true,
130: new NewLibraryPluginCreationOperation(fPluginData,
131: fProjectProvider, null));
132: IWorkingSet[] workingSets = fMainPage
133: .getSelectedWorkingSets();
134: getWorkbench().getWorkingSetManager().addToWorkingSets(
135: fProjectProvider.getProject(), workingSets);
136: return true;
137: } catch (InvocationTargetException e) {
138: PDEPlugin.logException(e);
139: } catch (InterruptedException e) {
140: }
141: return false;
142: }
143:
144: /*
145: * (non-Javadoc)
146: *
147: * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
148: * java.lang.String, java.lang.Object)
149: */
150: public void setInitializationData(IConfigurationElement config,
151: String propertyName, Object data) throws CoreException {
152: fConfig = config;
153: }
154:
155: }
|