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;
32 * Standard workbench wizard for exporting resources from the workspace
33 * to the local file system.
35 * This class may be instantiated and used without further configuration;
36 * this class is not intended to be subclassed.
41 * IWizard wizard = new ObfuscatorExportWizard();
42 * wizard.init(workbench, selection);
43 * WizardDialog dialog = new WizardDialog(shell, wizard);
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.
52 public class ObfuscatorExportWizard extends Wizard implements IExportWizard {
53 private IWorkbench workbench;
54 private IStructuredSelection selection;
55 private WizardObfuscatorResourceExportPage1 mainPage;
57 * Creates a wizard for exporting workspace resources to the local file system.
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$
64 section = workbenchSettings.addNewSection("ObfuscatorExportWizard");//$NON-NLS-1$
65 setDialogSettings(section);
68 * Method declared on IWizard.
70 public void addPages() {
72 mainPage = new WizardObfuscatorResourceExportPage1(selection);
76 * Returns the image descriptor with the given relative path.
78 private ImageDescriptor getImageDescriptor(String relativePath) {
79 String iconPath = "icons/full/";//$NON-NLS-1$
81 AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
82 URL installURL = plugin.getDescriptor().getInstallURL();
83 URL url = new URL(installURL, iconPath + relativePath);
84 return ImageDescriptor.createFromURL(url);
86 catch (MalformedURLException e) {
92 * Method declared on IWorkbenchWizard.
94 public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
95 this.workbench = workbench;
98 //Make it the current selection by default but look it up otherwise
100 selection = currentSelection;
102 if(currentSelection.isEmpty() && workbench.getActiveWorkbenchWindow() != null){
103 IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
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);
114 setWindowTitle(ObfuscatorExportMessages.getString("ObfuscatorTransfer.export")); //$NON-NLS-1$
115 setDefaultPageImageDescriptor(getImageDescriptor("wizban/exportdir_wiz.gif"));//$NON-NLS-1$
116 setNeedsProgressMonitor(true);
119 * Method declared on IWizard.
121 public boolean performFinish() {
122 return mainPage.finish();