KickJava   Java API By Example, From Geeks To Geeks.

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


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.internal.core.FeatureModelManager;
18 import org.eclipse.pde.internal.core.PDECore;
19 import org.eclipse.pde.internal.core.exports.FeatureExportInfo;
20 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
21 import org.eclipse.pde.internal.ui.PDEPluginImages;
22 import org.eclipse.pde.internal.ui.build.FeatureExportJob;
23 import org.eclipse.ui.progress.IProgressConstants;
24 import org.w3c.dom.DOMException JavaDoc;
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27
28 public class FeatureExportWizard extends AntGeneratingExportWizard {
29     private static final String JavaDoc STORE_SECTION = "FeatureExportWizard"; //$NON-NLS-1$
30
private CrossPlatformExportPage fPage2;
31
32     /**
33      * The constructor.
34      */

35     public FeatureExportWizard() {
36         setDefaultPageImageDescriptor(PDEPluginImages.DESC_FEATURE_EXPORT_WIZ);
37     }
38     
39     public void addPages() {
40         super.addPages();
41         FeatureModelManager manager = PDECore.getDefault().getFeatureModelManager();
42         IFeatureModel model = manager.findFeatureModel("org.eclipse.platform.launchers"); //$NON-NLS-1$
43
if (model != null) {
44             fPage2 = new CrossPlatformExportPage("environment", model); //$NON-NLS-1$
45
addPage(fPage2);
46         }
47     }
48
49     protected BaseExportWizardPage createPage1() {
50         return new FeatureExportWizardPage(getSelection());
51     }
52     
53     protected String JavaDoc getSettingsSectionName() {
54         return STORE_SECTION;
55     }
56     
57     protected void scheduleExportJob() {
58         FeatureExportInfo info = new FeatureExportInfo();
59         info.toDirectory = fPage.doExportToDirectory();
60         info.useJarFormat = fPage.useJARFormat();
61         info.exportSource = fPage.doExportSource();
62         info.destinationDirectory = fPage.getDestination();
63         info.zipFileName = fPage.getFileName();
64         if (fPage2 != null && ((FeatureExportWizardPage)fPage).doMultiPlatform())
65             info.targets = fPage2.getTargets();
66         info.items = fPage.getSelectedItems();
67         info.signingInfo = fPage.getSigningInfo();
68         info.jnlpInfo = ((FeatureExportWizardPage)fPage).getJNLPInfo();
69         info.qualifier = fPage.getQualifier();
70         
71         FeatureExportJob job = new FeatureExportJob(info);
72         job.setUser(true);
73         job.schedule();
74         job.setProperty(IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_FEATURE_OBJ);
75     }
76     
77     protected Document JavaDoc generateAntTask() {
78         try {
79             DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
80             Document JavaDoc doc = factory.newDocumentBuilder().newDocument();
81             Element JavaDoc root = doc.createElement("project"); //$NON-NLS-1$
82
root.setAttribute("name", "build"); //$NON-NLS-1$ //$NON-NLS-2$
83
root.setAttribute("default", "feature_export"); //$NON-NLS-1$ //$NON-NLS-2$
84
doc.appendChild(root);
85             
86             Element JavaDoc target = doc.createElement("target"); //$NON-NLS-1$
87
target.setAttribute("name", "feature_export"); //$NON-NLS-1$ //$NON-NLS-2$
88
root.appendChild(target);
89             
90             Element JavaDoc export = doc.createElement("pde.exportFeatures"); //$NON-NLS-1$
91
export.setAttribute("features", getFeatureIDs()); //$NON-NLS-1$
92
export.setAttribute("destination", fPage.getDestination()); //$NON-NLS-1$
93
String JavaDoc filename = fPage.getFileName();
94             if (filename != null)
95                 export.setAttribute("filename", filename); //$NON-NLS-1$
96
export.setAttribute("exportType", getExportOperation()); //$NON-NLS-1$
97
export.setAttribute("useJARFormat", Boolean.toString(fPage.useJARFormat())); //$NON-NLS-1$
98
export.setAttribute("exportSource", Boolean.toString(fPage.doExportSource())); //$NON-NLS-1$
99
String JavaDoc qualifier = fPage.getQualifier();
100             if (qualifier != null)
101                 export.setAttribute("qualifier", qualifier); //$NON-NLS-1$
102
target.appendChild(export);
103             return doc;
104         } catch (DOMException JavaDoc e) {
105         } catch (FactoryConfigurationError JavaDoc e) {
106         } catch (ParserConfigurationException JavaDoc e) {
107         }
108         return null;
109     }
110     
111     private String JavaDoc getFeatureIDs() {
112         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
113         Object JavaDoc[] objects = fPage.getSelectedItems();
114         for (int i = 0; i < objects.length; i++) {
115             Object JavaDoc object = objects[i];
116             if (object instanceof IFeatureModel) {
117                 buffer.append(((IFeatureModel)object).getFeature().getId());
118                 if (i < objects.length - 1)
119                     buffer.append(","); //$NON-NLS-1$
120
}
121         }
122         return buffer.toString();
123     }
124
125 }
126
Popular Tags