bugzilla 79050: samples wizard cleanup
diff --git a/plugins/org.eclipse.wst.common.ui/plugin.xml b/plugins/org.eclipse.wst.common.ui/plugin.xml
index 4bcd4f9..a132019 100644
--- a/plugins/org.eclipse.wst.common.ui/plugin.xml
+++ b/plugins/org.eclipse.wst.common.ui/plugin.xml
@@ -23,10 +23,8 @@
<import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.core.resources"/>
</requires>
-
- <extension point="org.eclipse.ui.newWizards">
- <category id="org.eclipse.wst.xml.samples" name="XML"
- parentCategory="org.eclipse.ui.Examples" />
- </extension>
+
+ <extension-point id="exampleProjectCreationWizard" name="Example Project Creation Wizard" schema="schema/exampleProjectCreationWizard.exsd"/>
+
</plugin>
diff --git a/plugins/org.eclipse.wst.common.ui/schema/exampleProjectCreationWizard.exsd b/plugins/org.eclipse.wst.common.ui/schema/exampleProjectCreationWizard.exsd
new file mode 100644
index 0000000..2786bcb
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.ui/schema/exampleProjectCreationWizard.exsd
@@ -0,0 +1,243 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.wst.examples.xml.org.eclipse.wst.examples">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.wst.examples.xml.org.eclipse.wst.examples" id="ExampleProjectCreationWizard" name="Example Project Creation Wizard"/>
+ </appInfo>
+ <documentation>
+ This extension point allows to extend New project withard with the
+page set up setup information for the created project as well as source files that will be imported on the project creation.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="wizard"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ Unique identifier for the extension
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ Optional name of the extension
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="wizard">
+ <complexType>
+ <sequence>
+ <element ref="projectsetup" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Id of the wizard that this extension is intended for.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="banner" type="string">
+ <annotation>
+ <documentation>
+ Plugin relative path to the image that will be displayed as a banner on the wizard.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="projectsetup">
+ <annotation>
+ <documentation>
+ Element that describes additional project setup.
+There will be as many pages created for the wizard as there are projectsetup elements.
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="import" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="nature" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="references" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="pagetitle" type="string">
+ <annotation>
+ <documentation>
+ Title of the wizard's page.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ Initial project name that will be provided on the wizard page.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="label" type="string">
+ <annotation>
+ <documentation>
+ Label for the project name field on the wizard page.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="pagedescription" type="string">
+ <annotation>
+ <documentation>
+ Description of the wizard page
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="open" type="string">
+ <annotation>
+ <documentation>
+ Plugin relative path of the file that will be opened when wizard finished.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="import">
+ <annotation>
+ <documentation>
+ Element that describes what to import into the project when it's created.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="dest" type="string">
+ <annotation>
+ <documentation>
+ Project relative path of the folder where project files will be imported to, if not specified, it's the projest itself.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="src" type="string">
+ <annotation>
+ <documentation>
+ Plugin relative path of the import .zip file with the files to be imported into the project.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="nature">
+ <annotation>
+ <documentation>
+ Element that specified Eclipse nature that is applicable to the project.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ The id of the nature that will be opened when project will be created.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="references">
+ <annotation>
+ <documentation>
+ Element that specifies reference for the project that will be created.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ The id of the referenced project.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ November 2004
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ <extension point="org.eclipse.wst.common.ui.exampleProjectCreationWizard"
+ id="org.eclipse.wst.xml.ui.ExampleProjectCreationWizardExtension">
+ <wizard
+ id="org.eclipse.wst.xml.ui.ExampleProjectCreationWizard"
+ banner="icons/newSampleProject_wizbanner.gif">
+ <projectsetup
+ pagetitle="%XMLExampleProjectCreationWizard.pagetitle"
+ name="%XMLExampleProjectCreationWizard.projectname"
+ label="%XMLExampleProjectCreationWizard.label"
+ pagedescription="%XMLExampleProjectCreationWizard.pagedescription"
+ open="readme.html">
+ <import
+ dest=""
+ src="examples/EditingAndValidatingXML.zip">
+ </import>
+ </projectsetup>
+ </wizard>
+ </extension>
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2001, 2004 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:
+ IBM Corporation - initial API and implementation
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/UIPlugin.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/UIPlugin.java
index b85612f..ffb1780 100644
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/UIPlugin.java
+++ b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/UIPlugin.java
@@ -28,6 +28,7 @@
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
@@ -37,25 +38,20 @@
public class UIPlugin extends AbstractUIPlugin {
//The shared instance.
private static UIPlugin plugin;
- //Resource bundle.
- // dmw 11/15 private field never read locally
- //private ResourceBundle resourceBundle;
/**
* The constructor.
*/
+ public UIPlugin() {
+ super();
+ plugin = this;
+ }
+
public UIPlugin(IPluginDescriptor descriptor) {
super(descriptor);
plugin = this;
- try {
- // dmw 11/15 private field never read locally
- ResourceBundle resourceBundle = descriptor.getResourceBundle();
- } catch (java.util.MissingResourceException exception) {
- //TODO... log an error message
- //resourceBundle = null;
- }
}
-
+
/**
* Returns the shared instance.
*/
@@ -75,18 +71,18 @@
* or 'key' if not found.
*/
public static String getResourceString(String key) {
- ResourceBundle bundle= UIPlugin.getDefault().getResourceBundle();
+ ResourceBundle aResourceBundle = getDefault().getResourceBundle();
try {
- return bundle.getString(key);
+ return (aResourceBundle != null) ? aResourceBundle.getString(key) : key;
} catch (MissingResourceException e) {
return key;
}
}
-
+
/**
* This gets the string resource and does one substitution.
*/
- public String getString(String key, Object s1)
+ public static String getString(String key, Object s1)
{
return MessageFormat.format(getResourceString(key), new Object [] { s1 });
}
@@ -94,7 +90,7 @@
/**
* This gets the string resource and does two substitutions.
*/
- public String getString(String key, Object s1, Object s2)
+ public static String getString(String key, Object s1, Object s2)
{
return MessageFormat.format(getResourceString(key), new Object [] { s1, s2 });
}
@@ -106,7 +102,7 @@
try {
return Platform.getResourceBundle(plugin.getBundle());
} catch (MissingResourceException x) {
- x.printStackTrace();
+ log(x);
}
return null;
}
@@ -154,4 +150,18 @@
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, e.getLocalizedMessage(), e));
}
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ // TODO Auto-generated method stub
+ super.start(context);
+ }
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ // TODO Auto-generated method stub
+ super.stop(context);
+ }
}
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationOperation.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationOperation.java
index aff782e..7919178 100644
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationOperation.java
+++ b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationOperation.java
@@ -22,6 +22,7 @@
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -33,171 +34,171 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
-
import org.eclipse.jface.operation.IRunnableWithProgress;
-
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
import org.eclipse.wst.common.ui.UIPlugin;
import org.osgi.framework.Bundle;
-
-
-
public class ExampleProjectCreationOperation implements IRunnableWithProgress {
- private IResource fElementToOpen;
-
- private ExampleProjectCreationWizardPage[] fPages;
- private IOverwriteQuery fOverwriteQuery;
-
+ private IResource elementToOpen;
+
+ private IOverwriteQuery overwriteQuery;
+
+ private ExampleProjectCreationWizardPage[] pages;
+
/**
* Constructor for ExampleProjectCreationOperation
*/
- public ExampleProjectCreationOperation(ExampleProjectCreationWizardPage[] pages, IOverwriteQuery overwriteQuery) {
- fElementToOpen= null;
- fPages= pages;
- fOverwriteQuery= overwriteQuery;
+ public ExampleProjectCreationOperation(ExampleProjectCreationWizardPage[] myPages, IOverwriteQuery myOverwriteQuery) {
+ elementToOpen = null;
+ pages = myPages;
+ overwriteQuery = myOverwriteQuery;
}
-
- /*
- * @see IRunnableWithProgress#run(IProgressMonitor)
- */
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- if (monitor == null) {
- monitor= new NullProgressMonitor();
- }
- try {
- monitor.beginTask(UIPlugin.getResourceString("ExampleProjectCreationOperation.op_desc"), fPages.length); //$NON-NLS-1$
- IWorkspaceRoot root= UIPlugin.getWorkspace().getRoot();
-
- for (int i= 0; i < fPages.length; i++) {
- createProject(root, fPages[i], new SubProgressMonitor(monitor, 1));
- }
- } finally {
- monitor.done();
- }
- }
-
- public IResource getElementToOpen() {
- return fElementToOpen;
- }
-
- private void createProject(IWorkspaceRoot root, ExampleProjectCreationWizardPage page, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- IConfigurationElement desc= page.getConfigurationElement();
-
- IConfigurationElement[] imports= desc.getChildren("import"); //$NON-NLS-1$
- IConfigurationElement[] natures= desc.getChildren("nature"); //$NON-NLS-1$
- IConfigurationElement[] references= desc.getChildren("references"); //$NON-NLS-1$
- int nImports= (imports == null) ? 0 : imports.length;
- int nNatures= (natures == null) ? 0 : natures.length;
- int nReferences= (references == null) ? 0 : references.length;
-
- monitor.beginTask(UIPlugin.getResourceString("ExampleProjectCreationOperation.op_desc_proj"), nImports + 1); //$NON-NLS-1$
-
- String name= page.getName();
-
- String[] natureIds= new String[nNatures];
- for (int i= 0; i < nNatures; i++) {
- natureIds[i]= natures[i].getAttribute("id"); //$NON-NLS-1$
- }
- IProject[] referencedProjects= new IProject[nReferences];
- for (int i= 0; i < nReferences; i++) {
- referencedProjects[i]= root.getProject(references[i].getAttribute("id")); //$NON-NLS-1$
- }
-
- IProject proj= configNewProject(root, name, natureIds, referencedProjects, monitor);
-
- for (int i= 0; i < nImports; i++) {
- doImports(proj, imports[i], new SubProgressMonitor(monitor, 1));
- }
-
- String open= desc.getAttribute("open"); //$NON-NLS-1$
- if (open != null && open.length() > 0) {
- IResource fileToOpen= proj.findMember(new Path(open));
- if (fileToOpen != null) {
- fElementToOpen= fileToOpen;
- }
- }
-
- }
-
private IProject configNewProject(IWorkspaceRoot root, String name, String[] natureIds, IProject[] referencedProjects, IProgressMonitor monitor) throws InvocationTargetException {
try {
- IProject project= root.getProject(name);
+ IProject project = root.getProject(name);
if (!project.exists()) {
project.create(null);
}
if (!project.isOpen()) {
project.open(null);
}
- IProjectDescription desc= project.getDescription();
+ IProjectDescription desc = project.getDescription();
desc.setLocation(null);
desc.setNatureIds(natureIds);
desc.setReferencedProjects(referencedProjects);
-
+
project.setDescription(desc, new SubProgressMonitor(monitor, 1));
return project;
- } catch (CoreException e) {
+ }
+ catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
-
+
+ private void createProject(IWorkspaceRoot root, ExampleProjectCreationWizardPage page, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ IConfigurationElement desc = page.getConfigurationElement();
+
+ IConfigurationElement[] imports = desc.getChildren("import"); //$NON-NLS-1$
+ IConfigurationElement[] natures = desc.getChildren("nature"); //$NON-NLS-1$
+ IConfigurationElement[] references = desc.getChildren("references"); //$NON-NLS-1$
+ int nImports = (imports == null) ? 0 : imports.length;
+ int nNatures = (natures == null) ? 0 : natures.length;
+ int nReferences = (references == null) ? 0 : references.length;
+
+ monitor.beginTask(UIPlugin.getResourceString("ExampleProjectCreationOperation.op_desc_proj"), nImports + 1); //$NON-NLS-1$
+
+ String name = page.getProjectName();
+
+ String[] natureIds = new String[nNatures];
+ for (int i = 0; i < nNatures; i++) {
+ natureIds[i] = natures[i].getAttribute("id"); //$NON-NLS-1$
+ }
+ IProject[] referencedProjects = new IProject[nReferences];
+ for (int i = 0; i < nReferences; i++) {
+ referencedProjects[i] = root.getProject(references[i].getAttribute("id")); //$NON-NLS-1$
+ }
+
+ IProject proj = configNewProject(root, name, natureIds, referencedProjects, monitor);
+
+ for (int i = 0; i < nImports; i++) {
+ doImports(proj, imports[i], new SubProgressMonitor(monitor, 1));
+ }
+
+ String open = desc.getAttribute("open"); //$NON-NLS-1$
+ if (open != null && open.length() > 0) {
+ IResource fileToOpen = proj.findMember(new Path(open));
+ if (fileToOpen != null) {
+ elementToOpen = fileToOpen;
+ }
+ }
+
+ }
+
private void doImports(IProject project, IConfigurationElement curr, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
IPath destPath;
- String name= curr.getAttribute("dest"); //$NON-NLS-1$
+ String name = curr.getAttribute("dest"); //$NON-NLS-1$
if (name == null || name.length() == 0) {
- destPath= project.getFullPath();
- } else {
- IFolder folder= project.getFolder(name);
+ destPath = project.getFullPath();
+ }
+ else {
+ IFolder folder = project.getFolder(name);
if (!folder.exists()) {
folder.create(true, true, null);
}
- destPath= folder.getFullPath();
+ destPath = folder.getFullPath();
}
- String importPath= curr.getAttribute("src"); //$NON-NLS-1$
+ String importPath = curr.getAttribute("src"); //$NON-NLS-1$
if (importPath == null) {
- importPath= ""; //$NON-NLS-1$
+ importPath = ""; //$NON-NLS-1$
UIPlugin.log("projectsetup descriptor: import missing"); //$NON-NLS-1$
return;
}
-
- ZipFile zipFile= getZipFileFromPluginDir(importPath, getContributingPlugin(curr));
+
+ ZipFile zipFile = getZipFileFromPluginDir(importPath, getContributingPlugin(curr));
importFilesFromZip(zipFile, destPath, new SubProgressMonitor(monitor, 1));
- } catch (CoreException e) {
+ }
+ catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
-
+
private String getContributingPlugin(IConfigurationElement configurationElement) {
- Object parent= configurationElement;
- while(parent != null) {
+ Object parent = configurationElement;
+ while (parent != null) {
if (parent instanceof IExtension)
- return ((IExtension)parent).getNamespace();
- parent= ((IConfigurationElement)parent).getParent();
+ return ((IExtension) parent).getNamespace();
+ parent = ((IConfigurationElement) parent).getParent();
}
return null;
}
+ public IResource getElementToOpen() {
+ return elementToOpen;
+ }
+
private ZipFile getZipFileFromPluginDir(String pluginRelativePath, String symbolicName) throws CoreException {
try {
Bundle bundle = Platform.getBundle(symbolicName);
- URL starterURL= new URL(bundle.getEntry("/"), pluginRelativePath);
+ URL starterURL = new URL(bundle.getEntry("/"), pluginRelativePath); //$NON-NLS-1$
return new ZipFile(Platform.asLocalURL(starterURL).getFile());
- } catch (IOException e) {
- String message= pluginRelativePath + ": " + e.getMessage(); //$NON-NLS-1$
- Status status= new Status(IStatus.ERROR, UIPlugin.getPluginId(), IStatus.ERROR, message, e);
+ }
+ catch (IOException e) {
+ String message = pluginRelativePath + ": " + e.getMessage(); //$NON-NLS-1$
+ Status status = new Status(IStatus.ERROR, UIPlugin.getPluginId(), IStatus.ERROR, message, e);
throw new CoreException(status);
}
}
-
- private void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- ZipFileStructureProvider structureProvider= new ZipFileStructureProvider(srcZipFile);
- ImportOperation op= new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, fOverwriteQuery);
+
+ private void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile);
+ ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, overwriteQuery);
op.run(monitor);
}
-}
+
+ /*
+ * @see IRunnableWithProgress#run(IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ try {
+ monitor.beginTask(UIPlugin.getResourceString("ExampleProjectCreationOperation.op_desc"), pages.length); //$NON-NLS-1$
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+
+ for (int i = 0; i < pages.length; i++) {
+ createProject(root, pages[i], new SubProgressMonitor(monitor, 1));
+ }
+ }
+ finally {
+ monitor.done();
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizard.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizard.java
index e7838cd..df1ddd8 100644
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizard.java
+++ b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizard.java
@@ -14,21 +14,23 @@
import java.lang.reflect.InvocationTargetException;
+import org.eclipse.core.internal.runtime.InternalPlatform;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
@@ -39,160 +41,185 @@
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
import org.eclipse.wst.common.ui.UIPlugin;
-
-
-
public class ExampleProjectCreationWizard extends BasicNewResourceWizard implements INewWizard, IExecutableExtension {
- private ExampleProjectCreationWizardPage[] fPages;
- private IConfigurationElement fConfigElement;
+ private class ImportOverwriteQuery implements IOverwriteQuery {
+
+ private int openDialog(final String file) {
+ final int[] result = {IDialogConstants.CANCEL_ID};
+ getShell().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ String title = UIPlugin.getResourceString("ExampleProjectCreationWizard.overwritequery.title"); //$NON-NLS-1$
+ String msg = UIPlugin.getString("ExampleProjectCreationWizard.overwritequery.message", file); //$NON-NLS-1$
+ String[] options = {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL};
+ MessageDialog dialog = new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION, options, 0);
+ result[0] = dialog.open();
+ }
+ });
+ return result[0];
+ }
+
+ public String queryOverwrite(String file) {
+ String[] returnCodes = {YES, NO, ALL, CANCEL};
+ int returnVal = openDialog(file);
+ return returnVal < 0 ? CANCEL : returnCodes[returnVal];
+ }
+ }
+
+ private IConfigurationElement wizardConfigElement;
+ private IConfigurationElement exampleConfigElement;
+
+ private String EXAMPLE_WIZARD_XP_ID = "org.eclipse.wst.common.ui.exampleProjectCreationWizard"; //$NON-NLS-1$
+
+ private ExampleProjectCreationWizardPage[] pages;
+
+ private final String WEB_BROWSER_ID = "org.eclipse.wst.webbrowser"; //$NON-NLS-1$
public ExampleProjectCreationWizard() {
super();
setDialogSettings(UIPlugin.getDefault().getDialogSettings());
- setWindowTitle(UIPlugin.getResourceString("ExampleProjectCreationWizard.title")); //$NON-NLS-1$
+ setWindowTitle(UIPlugin.getResourceString("ExampleProjectCreationWizard.title")); //$NON-NLS-1$
setNeedsProgressMonitor(true);
+ }
-
- }
-
- public void initializeDefaultPageImageDescriptor() {
- if (fConfigElement != null) {
- String banner= fConfigElement.getAttribute("banner"); //$NON-NLS-1$
- if (banner != null) {
- ImageDescriptor desc= this.getImageDescriptor(banner);
- setDefaultPageImageDescriptor(desc);
- }
- }
- }
-
- protected ImageDescriptor getImageDescriptor(String banner) {
- return null;
- }
-
/*
* @see Wizard#addPages
- */
+ */
public void addPages() {
super.addPages();
-
- IConfigurationElement[] children = fConfigElement.getChildren("projectsetup"); //$NON-NLS-1$
+
+ if(exampleConfigElement == null) return;
+ IConfigurationElement[] children = exampleConfigElement.getChildren("projectsetup"); //$NON-NLS-1$
if (children == null || children.length == 0) {
UIPlugin.log("descriptor must contain one ore more projectsetup tags"); //$NON-NLS-1$
return;
}
-
- fPages= new ExampleProjectCreationWizardPage[children.length];
-
- for (int i= 0; i < children.length; i++) {
- fPages[i]= new ExampleProjectCreationWizardPage(i, children[i]);
- addPage(fPages[i]);
+
+ pages = new ExampleProjectCreationWizardPage[children.length];
+
+ for (int i = 0; i < children.length; i++) {
+ pages[i] = new ExampleProjectCreationWizardPage(i, children[i]);
+ addPage(pages[i]);
}
}
- /*
- * @see Wizard#performFinish
- */
- public boolean performFinish() {
- ExampleProjectCreationOperation runnable= new ExampleProjectCreationOperation(fPages, new ImportOverwriteQuery());
-
- IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(runnable);
- try {
- getContainer().run(false, true, op);
- } catch (InvocationTargetException e) {
- handleException(e.getTargetException());
- return false;
- } catch (InterruptedException e) {
- return false;
+ protected IConfigurationElement[] getExtendedConfigurationElements() {
+ IExtensionRegistry registry = InternalPlatform.getDefault().getRegistry();
+ IExtensionPoint exampleWizardXP = registry.getExtensionPoint(EXAMPLE_WIZARD_XP_ID);
+ if(exampleWizardXP == null){
+ return new IConfigurationElement[0];
}
- BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
- IResource res= runnable.getElementToOpen();
- if (res != null) {
- openResource(res);
+ IExtension extension = exampleWizardXP.getExtension(getWizardExtensionId());
+ if(extension == null){
+ return new IConfigurationElement[0];
}
- return true;
+ IConfigurationElement[] exampleWizardCEs = extension.getConfigurationElements();
+ return exampleWizardCEs;
}
-
+
+ protected ImageDescriptor getImageDescriptor(String banner) {
+ return UIPlugin.getDefault().getImageDescriptor(banner);
+ }
+
private void handleException(Throwable target) {
- String title= UIPlugin.getResourceString("ExampleProjectCreationWizard.op_error.title"); //$NON-NLS-1$
- String message= UIPlugin.getResourceString("ExampleProjectCreationWizard.op_error.message"); //$NON-NLS-1$
+ String title = UIPlugin.getResourceString("ExampleProjectCreationWizard.op_error.title"); //$NON-NLS-1$
+ String message = UIPlugin.getResourceString("ExampleProjectCreationWizard.op_error.message"); //$NON-NLS-1$
if (target instanceof CoreException) {
- IStatus status= ((CoreException)target).getStatus();
+ IStatus status = ((CoreException) target).getStatus();
ErrorDialog.openError(getShell(), title, message, status);
UIPlugin.log(status);
- } else {
+ }
+ else {
MessageDialog.openError(getShell(), title, target.getMessage());
UIPlugin.log(target);
}
}
-
+
+ public void initializeDefaultPageImageDescriptor() {
+ if (exampleConfigElement != null) {
+ String banner = exampleConfigElement.getAttribute("banner"); //$NON-NLS-1$
+ if (banner != null) {
+ ImageDescriptor desc = this.getImageDescriptor(banner);
+ setDefaultPageImageDescriptor(desc);
+ }
+ }
+ }
+
private void openResource(final IResource resource) {
if (resource.getType() != IResource.FILE) {
return;
}
- IWorkbenchWindow window= UIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
+ IWorkbenchWindow window = UIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
- final IWorkbenchPage activePage= window.getActivePage();
+ final IWorkbenchPage activePage = window.getActivePage();
if (activePage != null) {
- final Display display= getShell().getDisplay();
+ final Display display = getShell().getDisplay();
display.asyncExec(new Runnable() {
public void run() {
try {
- IDE.openEditor(activePage, (IFile)resource, true);
- } catch (PartInitException e) {
+ IDE.openEditor(activePage, (IFile) resource, WEB_BROWSER_ID, true);
+ }
+ catch (PartInitException e) {
UIPlugin.log(e);
}
}
});
BasicNewResourceWizard.selectAndReveal(resource, activePage.getWorkbenchWindow());
}
- }
-
+ }
+
+ /*
+ * @see Wizard#performFinish
+ */
+ public boolean performFinish() {
+ ExampleProjectCreationOperation runnable = new ExampleProjectCreationOperation(pages, new ImportOverwriteQuery());
+
+ IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable);
+ try {
+ getContainer().run(false, true, op);
+ }
+ catch (InvocationTargetException e) {
+ handleException(e.getTargetException());
+ return false;
+ }
+ catch (InterruptedException e) {
+ return false;
+ }
+ BasicNewProjectResourceWizard.updatePerspective(wizardConfigElement);
+ IResource res = runnable.getElementToOpen();
+ if (res != null) {
+ openResource(res);
+ }
+ return true;
+ }
+
/**
- * Stores the configuration element for the wizard. The config element will be used
- * in <code>performFinish</code> to set the result perspective.
+ * 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) {
- fConfigElement= cfig;
-
- initializeDefaultPageImageDescriptor();
-
- String title= fConfigElement.getAttribute("name"); //$NON-NLS-1$
+ wizardConfigElement = cfig;
+ String title = wizardConfigElement.getAttribute("name"); //$NON-NLS-1$
if (title != null) {
- //setWindowTitle(title);
+ setWindowTitle(title);
}
+ IConfigurationElement[] exampleWizardCEs = getExtendedConfigurationElements();
+ for (int i = 0; i < exampleWizardCEs.length; i++) {
+ IConfigurationElement element = exampleWizardCEs[i];
+ String wizardId = wizardConfigElement.getAttribute("id"); //$NON-NLS-1$
+ String extWizardId = element.getAttribute("id"); //$NON-NLS-1$
+ if(wizardId != null && extWizardId != null && wizardId.equals(extWizardId)){
+ exampleConfigElement = element;
+ }
+ }
+ initializeDefaultPageImageDescriptor();
}
- // overwrite dialog
-
- private class ImportOverwriteQuery implements IOverwriteQuery {
- public String queryOverwrite(String file) {
- String[] returnCodes= { YES, NO, ALL, CANCEL};
- int returnVal= openDialog(file);
- return returnVal < 0 ? CANCEL : returnCodes[returnVal];
- }
-
- private int openDialog(final String file) {
- final int[] result= { IDialogConstants.CANCEL_ID };
- getShell().getDisplay().syncExec(new Runnable() {
- public void run() {
- String title= UIPlugin.getResourceString("ExampleProjectCreationWizard.overwritequery.title"); //$NON-NLS-1$
- String msg= UIPlugin.getDefault().getString("ExampleProjectCreationWizard.overwritequery.message", file); //$NON-NLS-1$
- String[] options= {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL};
- MessageDialog dialog= new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION, options, 0);
- result[0]= dialog.open();
- }
- });
- return result[0];
- }
+ public String getWizardExtensionId(){
+ return EXAMPLE_WIZARD_XP_ID;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
- */
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- // Empty
- }
-}
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizardPage.java b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizardPage.java
index 0eba6e1..b2926ab 100644
--- a/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizardPage.java
+++ b/plugins/org.eclipse.wst.common.ui/src/org/eclipse/wst/common/ui/wizards/ExampleProjectCreationWizardPage.java
@@ -10,195 +10,101 @@
* Jens Lukowski/Innoopract - initial renaming/restructuring
*
*/
+
package org.eclipse.wst.common.ui.wizards;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.DialogPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.eclipse.wst.common.ui.UIPlugin;
+public class ExampleProjectCreationWizardPage extends WizardNewProjectCreationPage {
+ private IConfigurationElement configurationElement;
-
-public class ExampleProjectCreationWizardPage extends WizardPage {
-
- private IStatus fCurrStatus;
-
- private boolean fPageVisible;
-
- private IConfigurationElement fConfigurationElement;
-
- private String fNameLabel;
- private String fProjectName;
-
- private Text fTextControl;
-
public ExampleProjectCreationWizardPage(int pageNumber, IConfigurationElement elem) {
+
super("page" + pageNumber); //$NON-NLS-1$
- fCurrStatus= createStatus(IStatus.OK, ""); //$NON-NLS-1$
-
- fConfigurationElement= elem;
-
- setTitle(getAttribute(elem, "pagetitle")); //$NON-NLS-1$
- setDescription(getAttribute(elem, "pagedescription")); //$NON-NLS-1$
-
- fNameLabel= getAttribute(elem, "label"); //$NON-NLS-1$
- String name = getAttribute(elem, "name"); //$NON-NLS-1$
- fProjectName = getInitialProjectName(name);
+ configurationElement = elem;
+
+ String name = getAttribute(elem, "name"); //$NON-NLS-1$
+ setInitialProjectName(calculateInitialProjectName(name));
+
+ setDescription(getAttribute(configurationElement, "pagedescription")); //$NON-NLS-1$
+ setTitle(getAttribute(configurationElement, "pagetitle")); //$NON-NLS-1$
+
}
-
+
+ /*
+ * Set the default project name that is to appear on the initialPage page
+ * of this wizard.
+ */
+ protected String calculateInitialProjectName(String projectName) {
+ IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (!projectHandle.exists()) {
+ return projectName;
+ }
+ // Change the name until it doesn't exists. Try 9 times and then
+ // give up.
+ for (int i = 1; i < 10; i++) {
+ projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName + i);
+ if (!projectHandle.exists()) {
+ return projectName + i;
+ }
+ }
+ return projectName + "9"; //$NON-NLS-1$
+
+ }
+
private String getAttribute(IConfigurationElement elem, String tag) {
- String res= elem.getAttribute(tag);
+ String res = elem.getAttribute(tag);
if (res == null) {
return '!' + tag + '!';
}
return res;
}
-
- /*
- * @see IDialogPage#createControl(Composite)
- */
- public void createControl(Composite parent) {
- Composite composite= new Composite(parent, SWT.NONE);
- GridLayout gd= new GridLayout();
- gd.numColumns= 2;
- composite.setLayout(gd);
-
- Label label= new Label(composite, SWT.LEFT);
- label.setText(fNameLabel);
- label.setLayoutData(new GridData());
-
- fTextControl= new Text(composite, SWT.SINGLE | SWT.BORDER);
- fTextControl.setText(fProjectName);
- fTextControl.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- if (!fTextControl.isDisposed()) {
- validateText(fTextControl.getText());
- }
- }
- });
- fTextControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- setControl(composite);
-
- }
- private void validateText(String text) {
- IWorkspace workspace= ResourcesPlugin.getWorkspace();
- IStatus status= workspace.validateName(text, IResource.PROJECT);
- if (status.isOK()) {
- if (workspace.getRoot().getProject(text).exists()) {
- status= createStatus(IStatus.ERROR, UIPlugin.getResourceString("ExampleProjectCreationWizardPage.error.alreadyexists")); //$NON-NLS-1$
- }
- }
- updateStatus(status);
-
- fProjectName= text;
- }
-
-
- /*
- * @see WizardPage#becomesVisible
- */
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- fPageVisible= visible;
- // policy: wizards are not allowed to come up with an error message
- if (visible && fCurrStatus.matches(IStatus.ERROR)) {
- // keep the error state, but remove the message
- fCurrStatus= createStatus(IStatus.ERROR, ""); //$NON-NLS-1$
- }
- updateStatus(fCurrStatus);
- }
- /**
- * Updates the status line and the ok button depending on the status
- */
- private void updateStatus(IStatus status) {
- fCurrStatus= status;
- setPageComplete(!status.matches(IStatus.ERROR));
- if (fPageVisible) {
- applyToStatusLine(this, status);
- }
- }
-
- /**
- * Applies the status to a dialog page
- */
- private static void applyToStatusLine(DialogPage page, IStatus status) {
- String errorMessage= null;
- String warningMessage= null;
- String statusMessage= status.getMessage();
- if (statusMessage.length() > 0) {
- if (status.matches(IStatus.ERROR)) {
- errorMessage= statusMessage;
- } else if (!status.isOK()) {
- warningMessage= statusMessage;
- }
- }
- page.setErrorMessage(errorMessage);
- page.setMessage(warningMessage);
- }
-
-
- private static IStatus createStatus(int severity, String message) {
- return new Status(severity, UIPlugin.getPluginId(), severity, message, null);
- }
-
- /**
- * Returns the name entered by the user
- */
- public String getName() {
- return fProjectName;
- }
/**
* Returns the configuration element of this page.
+ *
* @return Returns a IConfigurationElement
*/
public IConfigurationElement getConfigurationElement() {
- return fConfigurationElement;
+ return configurationElement;
}
-
- /*
- * Set the default project name that is to appear on the initialPage
- * page of this wizard.
- */
- public String getInitialProjectName(String projectName)
- {
- IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- if (!projectHandle.exists())
- {
- return projectName;
- }
- else
- {
- // Change the name until it doesn't exists. Try 9 times and then give up.
- for (int i = 1; i < 10; i++)
- {
- projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName + i);
- if (!projectHandle.exists())
- {
- return projectName + i;
- }
- }
- return projectName + "9";
- }
- }
+
+ /**
+ * @see org.eclipse.ui.dialogs.WizardNewProjectCreationPage#validatePage()
+ */
+ protected boolean validatePage() {
+ if (!super.validatePage())
+ return false;
+
+ String projectName = getProjectName();
+ if (projectName == null)
+ return false;
+
+ IWizard wizard = getWizard();
+ if (wizard instanceof ExampleProjectCreationWizard) {
+ IWizardPage[] pages = wizard.getPages();
+ for (int i = 0; i < pages.length; i++) {
+ if ((pages[i] != this) && (pages[i] instanceof ExampleProjectCreationWizardPage)) {
+ if (projectName.equals(((ExampleProjectCreationWizardPage) pages[i]).getProjectName())) {
+ setErrorMessage(UIPlugin.getResourceString("ExampleProjectCreationWizardPage.error.alreadyexists")); //$NON-NLS-1$
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+
}
-