5111b043722fea7bfbd003aed2f05f9290bfe59c
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / obfuscator / export / ObfuscatorExportWizard.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.obfuscator.export;
12
13 import java.net.MalformedURLException;
14 import java.net.URL;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.jface.dialogs.IDialogSettings;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.jface.wizard.Wizard;
23 import org.eclipse.ui.IEditorPart;
24 import org.eclipse.ui.IExportWizard;
25 import org.eclipse.ui.IWorkbench;
26 import org.eclipse.ui.IWorkbenchPage;
27 import org.eclipse.ui.PlatformUI;
28 import org.eclipse.ui.plugin.AbstractUIPlugin;
29
30 /**
31  * Standard workbench wizard for exporting resources from the workspace to the
32  * local file system.
33  * <p>
34  * This class may be instantiated and used without further configuration; this
35  * class is not intended to be subclassed.
36  * </p>
37  * <p>
38  * Example:
39  * 
40  * <pre>
41  * IWizard wizard = new ObfuscatorExportWizard();
42  * wizard.init(workbench, selection);
43  * WizardDialog dialog = new WizardDialog(shell, wizard);
44  * dialog.open();
45  * </pre>
46  * 
47  * During the call to <code>open</code>, the wizard dialog is presented to
48  * the user. When the user hits Finish, the user-selected workspace resources
49  * are exported to the user-specified location in the local file system, the
50  * dialog closes, and the call to <code>open</code> returns.
51  * </p>
52  */
53 public class ObfuscatorExportWizard extends Wizard implements IExportWizard {
54         private IWorkbench workbench;
55
56         private IStructuredSelection selection;
57
58         private WizardObfuscatorResourceExportPage1 mainPage;
59
60         /**
61          * Creates a wizard for exporting workspace resources to the local file
62          * system.
63          */
64         public ObfuscatorExportWizard() {
65                 AbstractUIPlugin plugin = (AbstractUIPlugin) Platform
66                                 .getPlugin(PlatformUI.PLUGIN_ID);
67                 IDialogSettings workbenchSettings = plugin.getDialogSettings();
68                 IDialogSettings section = workbenchSettings
69                                 .getSection("ObfuscatorExportWizard");//$NON-NLS-1$
70                 if (section == null)
71                         section = workbenchSettings.addNewSection("ObfuscatorExportWizard");//$NON-NLS-1$
72                 setDialogSettings(section);
73         }
74
75         /*
76          * (non-Javadoc) Method declared on IWizard.
77          */
78         public void addPages() {
79                 super.addPages();
80                 mainPage = new WizardObfuscatorResourceExportPage1(selection);
81                 addPage(mainPage);
82         }
83
84         /**
85          * Returns the image descriptor with the given relative path.
86          */
87         private ImageDescriptor getImageDescriptor(String relativePath) {
88                 String iconPath = "icons/full/";//$NON-NLS-1$
89                 try {
90                         AbstractUIPlugin plugin = (AbstractUIPlugin) Platform
91                                         .getPlugin(PlatformUI.PLUGIN_ID);
92                         URL installURL = plugin.getBundle().getEntry("/");
93                         URL url = new URL(installURL, iconPath + relativePath);
94                         return ImageDescriptor.createFromURL(url);
95                 } catch (MalformedURLException e) {
96                         // Should not happen
97                         return null;
98                 }
99         }
100
101         /*
102          * (non-Javadoc) Method declared on IWorkbenchWizard.
103          */
104         public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
105                 this.workbench = workbench;
106
107                 // Make it the current selection by default but look it up otherwise
108
109                 selection = currentSelection;
110
111                 if (currentSelection.isEmpty()
112                                 && workbench.getActiveWorkbenchWindow() != null) {
113                         IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
114                                         .getActivePage();
115                         if (page != null) {
116                                 IEditorPart currentEditor = page.getActiveEditor();
117                                 if (currentEditor != null) {
118                                         Object selectedResource = currentEditor.getEditorInput()
119                                                         .getAdapter(IResource.class);
120                                         if (selectedResource != null)
121                                                 selection = new StructuredSelection(selectedResource);
122                                 }
123                         }
124                 }
125
126                 setWindowTitle(ObfuscatorExportMessages
127                                 .getString("ObfuscatorTransfer.export")); //$NON-NLS-1$
128                 setDefaultPageImageDescriptor(getImageDescriptor("wizban/exportdir_wiz.gif"));//$NON-NLS-1$
129                 setNeedsProgressMonitor(true);
130         }
131
132         /*
133          * (non-Javadoc) Method declared on IWizard.
134          */
135         public boolean performFinish() {
136                 return mainPage.finish();
137         }
138
139 }