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.exports;
011:
012: import javax.xml.parsers.DocumentBuilderFactory;
013: import javax.xml.parsers.FactoryConfigurationError;
014: import javax.xml.parsers.ParserConfigurationException;
015:
016: import org.eclipse.pde.internal.core.FeatureModelManager;
017: import org.eclipse.pde.internal.core.PDECore;
018: import org.eclipse.pde.internal.core.exports.FeatureExportInfo;
019: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
020: import org.eclipse.pde.internal.ui.PDEPluginImages;
021: import org.eclipse.pde.internal.ui.build.FeatureExportJob;
022: import org.eclipse.ui.progress.IProgressConstants;
023: import org.w3c.dom.DOMException;
024: import org.w3c.dom.Document;
025: import org.w3c.dom.Element;
026:
027: public class FeatureExportWizard extends AntGeneratingExportWizard {
028: private static final String STORE_SECTION = "FeatureExportWizard"; //$NON-NLS-1$
029: private CrossPlatformExportPage fPage2;
030:
031: /**
032: * The constructor.
033: */
034: public FeatureExportWizard() {
035: setDefaultPageImageDescriptor(PDEPluginImages.DESC_FEATURE_EXPORT_WIZ);
036: }
037:
038: public void addPages() {
039: super .addPages();
040: FeatureModelManager manager = PDECore.getDefault()
041: .getFeatureModelManager();
042: IFeatureModel model = manager.getDeltaPackFeature();
043: if (model != null) {
044: fPage2 = new CrossPlatformExportPage("environment", model); //$NON-NLS-1$
045: addPage(fPage2);
046: }
047: }
048:
049: protected BaseExportWizardPage createPage1() {
050: return new FeatureExportWizardPage(getSelection());
051: }
052:
053: protected String getSettingsSectionName() {
054: return STORE_SECTION;
055: }
056:
057: protected void scheduleExportJob() {
058: FeatureExportInfo info = new FeatureExportInfo();
059: info.toDirectory = fPage.doExportToDirectory();
060: info.useJarFormat = fPage.useJARFormat();
061: info.exportSource = fPage.doExportSource();
062: info.destinationDirectory = fPage.getDestination();
063: info.zipFileName = fPage.getFileName();
064: if (fPage2 != null
065: && ((FeatureExportWizardPage) fPage).doMultiPlatform())
066: info.targets = fPage2.getTargets();
067: info.items = fPage.getSelectedItems();
068: info.signingInfo = fPage.getSigningInfo();
069: info.jnlpInfo = ((FeatureExportWizardPage) fPage).getJNLPInfo();
070: info.qualifier = fPage.getQualifier();
071:
072: FeatureExportJob job = new FeatureExportJob(info);
073: job.setUser(true);
074: job.schedule();
075: job.setProperty(IProgressConstants.ICON_PROPERTY,
076: PDEPluginImages.DESC_FEATURE_OBJ);
077: }
078:
079: protected Document generateAntTask() {
080: try {
081: DocumentBuilderFactory factory = DocumentBuilderFactory
082: .newInstance();
083: Document doc = factory.newDocumentBuilder().newDocument();
084: Element root = doc.createElement("project"); //$NON-NLS-1$
085: root.setAttribute("name", "build"); //$NON-NLS-1$ //$NON-NLS-2$
086: root.setAttribute("default", "feature_export"); //$NON-NLS-1$ //$NON-NLS-2$
087: doc.appendChild(root);
088:
089: Element target = doc.createElement("target"); //$NON-NLS-1$
090: target.setAttribute("name", "feature_export"); //$NON-NLS-1$ //$NON-NLS-2$
091: root.appendChild(target);
092:
093: Element export = doc.createElement("pde.exportFeatures"); //$NON-NLS-1$
094: export.setAttribute("features", getFeatureIDs()); //$NON-NLS-1$
095: export.setAttribute("destination", fPage.getDestination()); //$NON-NLS-1$
096: String filename = fPage.getFileName();
097: if (filename != null)
098: export.setAttribute("filename", filename); //$NON-NLS-1$
099: export.setAttribute("exportType", getExportOperation()); //$NON-NLS-1$
100: export
101: .setAttribute(
102: "useJARFormat", Boolean.toString(fPage.useJARFormat())); //$NON-NLS-1$
103: export
104: .setAttribute(
105: "exportSource", Boolean.toString(fPage.doExportSource())); //$NON-NLS-1$
106: String qualifier = fPage.getQualifier();
107: if (qualifier != null)
108: export.setAttribute("qualifier", qualifier); //$NON-NLS-1$
109: target.appendChild(export);
110: return doc;
111: } catch (DOMException e) {
112: } catch (FactoryConfigurationError e) {
113: } catch (ParserConfigurationException e) {
114: }
115: return null;
116: }
117:
118: private String getFeatureIDs() {
119: StringBuffer buffer = new StringBuffer();
120: Object[] objects = fPage.getSelectedItems();
121: for (int i = 0; i < objects.length; i++) {
122: Object object = objects[i];
123: if (object instanceof IFeatureModel) {
124: buffer.append(((IFeatureModel) object).getFeature()
125: .getId());
126: if (i < objects.length - 1)
127: buffer.append(","); //$NON-NLS-1$
128: }
129: }
130: return buffer.toString();
131: }
132:
133: }
|