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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.obfuscator.export;
13 import java.net.MalformedURLException;
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;
31 * Standard workbench wizard for exporting resources from the workspace to the
34 * This class may be instantiated and used without further configuration; this
35 * class is not intended to be subclassed.
41 * IWizard wizard = new ObfuscatorExportWizard();
42 * wizard.init(workbench, selection);
43 * WizardDialog dialog = new WizardDialog(shell, wizard);
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.
53 public class ObfuscatorExportWizard extends Wizard implements IExportWizard {
54 private IWorkbench workbench;
56 private IStructuredSelection selection;
58 private WizardObfuscatorResourceExportPage1 mainPage;
61 * Creates a wizard for exporting workspace resources to the local file
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$
71 section = workbenchSettings.addNewSection("ObfuscatorExportWizard");//$NON-NLS-1$
72 setDialogSettings(section);
76 * (non-Javadoc) Method declared on IWizard.
78 public void addPages() {
80 mainPage = new WizardObfuscatorResourceExportPage1(selection);
85 * Returns the image descriptor with the given relative path.
87 private ImageDescriptor getImageDescriptor(String relativePath) {
88 String iconPath = "icons/full/";//$NON-NLS-1$
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) {
102 * (non-Javadoc) Method declared on IWorkbenchWizard.
104 public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
105 this.workbench = workbench;
107 // Make it the current selection by default but look it up otherwise
109 selection = currentSelection;
111 if (currentSelection.isEmpty()
112 && workbench.getActiveWorkbenchWindow() != null) {
113 IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
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);
126 setWindowTitle(ObfuscatorExportMessages
127 .getString("ObfuscatorTransfer.export")); //$NON-NLS-1$
128 setDefaultPageImageDescriptor(getImageDescriptor("wizban/exportdir_wiz.gif"));//$NON-NLS-1$
129 setNeedsProgressMonitor(true);
133 * (non-Javadoc) Method declared on IWizard.
135 public boolean performFinish() {
136 return mainPage.finish();