replaced a lot of deprecated code; if someone runs into a commit conflict afterwards...
[phpeclipse.git] / net.sourceforge.phpeclipse / 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 /**
32  * Standard workbench wizard for exporting resources from the workspace
33  * to the local file system.
34  * <p>
35  * This class may be instantiated and used without further configuration;
36  * this class is not intended to be subclassed.
37  * </p>
38  * <p>
39  * Example:
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  * During the call to <code>open</code>, the wizard dialog is presented to the
47  * user. When the user hits Finish, the user-selected workspace resources
48  * are exported to the user-specified location in the local file system,
49  * the dialog closes, and the call to <code>open</code> returns.
50  * </p>
51  */
52 public class ObfuscatorExportWizard extends Wizard implements IExportWizard {
53         private IWorkbench workbench;
54         private IStructuredSelection selection;
55         private WizardObfuscatorResourceExportPage1 mainPage;
56 /**
57  * Creates a wizard for exporting workspace resources to the local file system.
58  */
59 public ObfuscatorExportWizard() {
60         AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
61         IDialogSettings workbenchSettings = plugin.getDialogSettings();
62         IDialogSettings section = workbenchSettings.getSection("ObfuscatorExportWizard");//$NON-NLS-1$
63         if(section == null)
64                 section = workbenchSettings.addNewSection("ObfuscatorExportWizard");//$NON-NLS-1$
65         setDialogSettings(section);
66 }
67 /* (non-Javadoc)
68  * Method declared on IWizard.
69  */
70 public void addPages() {
71         super.addPages();
72         mainPage = new WizardObfuscatorResourceExportPage1(selection);
73         addPage(mainPage);
74 }
75 /**
76  * Returns the image descriptor with the given relative path.
77  */
78 private ImageDescriptor getImageDescriptor(String relativePath) {
79         String iconPath = "icons/full/";//$NON-NLS-1$
80         try {
81                 AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
82                 URL installURL = plugin.getBundle().getEntry("/");
83                 URL url = new URL(installURL, iconPath + relativePath);
84                 return ImageDescriptor.createFromURL(url);
85         }
86         catch (MalformedURLException e) {
87                 // Should not happen
88                 return null;
89         }
90 }
91 /* (non-Javadoc)
92  * Method declared on IWorkbenchWizard.
93  */
94 public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
95         this.workbench = workbench;
96
97
98         //Make it the current selection by default but look it up otherwise
99
100         selection = currentSelection;
101
102         if(currentSelection.isEmpty() && workbench.getActiveWorkbenchWindow() != null){
103                 IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
104                 if(page != null){
105                         IEditorPart currentEditor = page.getActiveEditor();
106                         if(currentEditor != null){
107                                 Object selectedResource = currentEditor.getEditorInput().getAdapter(IResource.class);
108                                 if(selectedResource != null)
109                                 selection = new StructuredSelection(selectedResource);
110                         }
111                 }
112         }
113
114         setWindowTitle(ObfuscatorExportMessages.getString("ObfuscatorTransfer.export")); //$NON-NLS-1$
115         setDefaultPageImageDescriptor(getImageDescriptor("wizban/exportdir_wiz.gif"));//$NON-NLS-1$
116         setNeedsProgressMonitor(true);
117 }
118 /* (non-Javadoc)
119  * Method declared on IWizard.
120  */
121 public boolean performFinish() {
122         return mainPage.finish();
123 }
124
125 }