KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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 java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15
16 import org.eclipse.core.resources.IContainer;
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.Path;
22 import org.eclipse.jface.dialogs.MessageDialog;
23 import org.eclipse.osgi.util.NLS;
24 import org.eclipse.pde.internal.core.XMLPrintHandler;
25 import org.eclipse.pde.internal.ui.PDEPlugin;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27 import org.eclipse.pde.internal.ui.build.BaseBuildAction;
28 import org.w3c.dom.Document JavaDoc;
29
30 public abstract class AntGeneratingExportWizard extends BaseExportWizard {
31     
32     protected BaseExportWizardPage fPage;
33
34     public void addPages() {
35         fPage = createPage1();
36         addPage(fPage);
37     }
38     
39     protected abstract BaseExportWizardPage createPage1();
40
41     protected boolean performPreliminaryChecks() {
42         if (fPage.doGenerateAntFile())
43             generateAntBuildFile(fPage.getAntBuildFileName());
44         return true;
45     }
46     
47     protected boolean confirmDelete() {
48         if (!fPage.doExportToDirectory()) {
49             File JavaDoc zipFile = new File JavaDoc(fPage.getDestination(), fPage.getFileName());
50             if (zipFile.exists()) {
51                 if (!MessageDialog.openQuestion(getContainer().getShell(),
52                         PDEUIMessages.BaseExportWizard_confirmReplace_title,
53                         NLS.bind(PDEUIMessages.BaseExportWizard_confirmReplace_desc, zipFile.getAbsolutePath())))
54                     return false;
55                 zipFile.delete();
56             }
57         }
58         return true;
59     }
60
61     protected abstract Document JavaDoc generateAntTask();
62     
63     protected void generateAntBuildFile(String JavaDoc filename) {
64         String JavaDoc parent = new Path(filename).removeLastSegments(1).toOSString();
65         String JavaDoc buildFilename = new Path(filename).lastSegment();
66         if (!buildFilename.endsWith(".xml")) //$NON-NLS-1$
67
buildFilename += ".xml"; //$NON-NLS-1$
68
File JavaDoc dir = new File JavaDoc(new File JavaDoc(parent).getAbsolutePath());
69         if (!dir.exists())
70             dir.mkdirs();
71
72         try {
73             Document JavaDoc task = generateAntTask();
74             if (task != null) {
75                 File JavaDoc buildFile = new File JavaDoc(dir, buildFilename);
76                 XMLPrintHandler.writeFile(task, buildFile);
77                 generateAntTask();
78                 setDefaultValues(dir, buildFilename);
79             }
80         } catch (IOException JavaDoc e) {
81         }
82     }
83     
84     private void setDefaultValues(File JavaDoc dir, String JavaDoc buildFilename) {
85         try {
86             IContainer container = PDEPlugin.getWorkspace().getRoot().getContainerForLocation(new Path(dir.toString()));
87             if (container != null && container.exists()) {
88                 IProject project = container.getProject();
89                 if (project != null) {
90                     project.refreshLocal(IResource.DEPTH_INFINITE, null);
91                     IFile file = container.getFile(new Path(buildFilename));
92                     if (file.exists())
93                         BaseBuildAction.setDefaultValues(file);
94                 }
95             }
96         } catch (CoreException e) {
97         }
98     }
99     
100     protected String JavaDoc getExportOperation() {
101         return fPage.doExportToDirectory() ? "directory" : "zip"; //$NON-NLS-1$ //$NON-NLS-2$
102
}
103     
104 }
105
Popular Tags