KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > PluginExportWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.wizards.exports;
12
13 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
14 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
15 import javax.xml.parsers.ParserConfigurationException JavaDoc;
16
17 import org.eclipse.pde.core.plugin.IPluginModelBase;
18 import org.eclipse.pde.internal.core.exports.FeatureExportInfo;
19 import org.eclipse.pde.internal.ui.PDEPluginImages;
20 import org.eclipse.pde.internal.ui.build.PluginExportJob;
21 import org.eclipse.ui.progress.IProgressConstants;
22 import org.w3c.dom.DOMException JavaDoc;
23 import org.w3c.dom.Document JavaDoc;
24 import org.w3c.dom.Element JavaDoc;
25
26 public class PluginExportWizard extends AntGeneratingExportWizard {
27     private static final String JavaDoc STORE_SECTION = "PluginExportWizard"; //$NON-NLS-1$
28

29     public PluginExportWizard() {
30         setDefaultPageImageDescriptor(PDEPluginImages.DESC_PLUGIN_EXPORT_WIZ);
31     }
32
33     protected BaseExportWizardPage createPage1() {
34         return new PluginExportWizardPage(getSelection());
35     }
36
37     protected String JavaDoc getSettingsSectionName() {
38         return STORE_SECTION;
39     }
40
41     protected void scheduleExportJob() {
42         FeatureExportInfo info = new FeatureExportInfo();
43         info.toDirectory = fPage.doExportToDirectory();
44         info.useJarFormat = fPage.useJARFormat();
45         info.exportSource = fPage.doExportSource();
46         info.destinationDirectory = fPage.getDestination();
47         info.zipFileName = fPage.getFileName();
48         info.items = fPage.getSelectedItems();
49         info.signingInfo = fPage.useJARFormat() ? fPage.getSigningInfo() : null;
50         info.qualifier = fPage.getQualifier();
51
52         PluginExportJob job = new PluginExportJob(info);
53         job.setUser(true);
54         job.schedule();
55         job.setProperty(IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_PLUGIN_OBJ);
56     }
57
58     protected Document JavaDoc generateAntTask() {
59         try {
60             DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
61             Document JavaDoc doc = factory.newDocumentBuilder().newDocument();
62             Element JavaDoc root = doc.createElement("project"); //$NON-NLS-1$
63
root.setAttribute("name", "build"); //$NON-NLS-1$ //$NON-NLS-2$
64
root.setAttribute("default", "plugin_export"); //$NON-NLS-1$ //$NON-NLS-2$
65
doc.appendChild(root);
66
67             Element JavaDoc target = doc.createElement("target"); //$NON-NLS-1$
68
target.setAttribute("name", "plugin_export"); //$NON-NLS-1$ //$NON-NLS-2$
69
root.appendChild(target);
70
71             Element JavaDoc export = doc.createElement("pde.exportPlugins"); //$NON-NLS-1$
72
export.setAttribute("plugins", getPluginIDs()); //$NON-NLS-1$
73
export.setAttribute("destination", fPage.getDestination()); //$NON-NLS-1$
74
String JavaDoc filename = fPage.getFileName();
75             if (filename != null)
76                 export.setAttribute("filename", filename); //$NON-NLS-1$
77
export.setAttribute("exportType", getExportOperation()); //$NON-NLS-1$
78
export.setAttribute("useJARFormat", Boolean.toString(fPage.useJARFormat())); //$NON-NLS-1$
79
export.setAttribute("exportSource", Boolean.toString(fPage.doExportSource())); //$NON-NLS-1$
80
String JavaDoc qualifier = fPage.getQualifier();
81             if (qualifier != null)
82                 export.setAttribute("qualifier", qualifier); //$NON-NLS-1$
83
target.appendChild(export);
84             return doc;
85         } catch (DOMException JavaDoc e) {
86         } catch (FactoryConfigurationError JavaDoc e) {
87         } catch (ParserConfigurationException JavaDoc e) {
88         }
89         return null;
90     }
91
92     private String JavaDoc getPluginIDs() {
93         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
94         Object JavaDoc[] objects = fPage.getSelectedItems();
95         for (int i = 0; i < objects.length; i++) {
96             Object JavaDoc object = objects[i];
97             if (object instanceof IPluginModelBase) {
98                 buffer.append(((IPluginModelBase)object).getPluginBase().getId());
99                 if (i < objects.length - 1)
100                     buffer.append(","); //$NON-NLS-1$
101
}
102         }
103         return buffer.toString();
104     }
105
106 }
107
Popular Tags