KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > wizards > datatransfer > FileSystemExportWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.wizards.datatransfer;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.jface.dialogs.IDialogSettings;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.jface.wizard.Wizard;
21 import org.eclipse.ui.IEditorPart;
22 import org.eclipse.ui.IExportWizard;
23 import org.eclipse.ui.IWorkbench;
24 import org.eclipse.ui.IWorkbenchPage;
25 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ui.ide.IDE;
27 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
28 import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
29 import org.eclipse.ui.internal.wizards.datatransfer.WizardFileSystemResourceExportPage1;
30 import org.eclipse.ui.plugin.AbstractUIPlugin;
31
32 /**
33  * Standard workbench wizard for exporting resources from the workspace
34  * to the local file system.
35  * <p>
36  * This class may be instantiated and used without further configuration;
37  * this class is not intended to be subclassed.
38  * </p>
39  * <p>
40  * Example:
41  * <pre>
42  * IWizard wizard = new FileSystemExportWizard();
43  * wizard.init(workbench, selection);
44  * WizardDialog dialog = new WizardDialog(shell, wizard);
45  * dialog.open();
46  * </pre>
47  * During the call to <code>open</code>, the wizard dialog is presented to the
48  * user. When the user hits Finish, the user-selected workspace resources
49  * are exported to the user-specified location in the local file system,
50  * the dialog closes, and the call to <code>open</code> returns.
51  * </p>
52  */

53 public class FileSystemExportWizard extends Wizard implements IExportWizard {
54     private IStructuredSelection selection;
55
56     private WizardFileSystemResourceExportPage1 mainPage;
57
58     /**
59      * Creates a wizard for exporting workspace resources to the local file system.
60      */

61     public FileSystemExportWizard() {
62         AbstractUIPlugin plugin = (AbstractUIPlugin) Platform
63                 .getPlugin(PlatformUI.PLUGIN_ID);
64         IDialogSettings workbenchSettings = plugin.getDialogSettings();
65         IDialogSettings section = workbenchSettings
66                 .getSection("FileSystemExportWizard");//$NON-NLS-1$
67
if (section == null) {
68             section = workbenchSettings.addNewSection("FileSystemExportWizard");//$NON-NLS-1$
69
}
70         setDialogSettings(section);
71     }
72
73     /* (non-Javadoc)
74      * Method declared on IWizard.
75      */

76     public void addPages() {
77         super.addPages();
78         mainPage = new WizardFileSystemResourceExportPage1(selection);
79         addPage(mainPage);
80     }
81
82
83     /* (non-Javadoc)
84      * Method declared on IWorkbenchWizard.
85      */

86     public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
87         this.selection = currentSelection;
88         List JavaDoc selectedResources = IDE.computeSelectedResources(currentSelection);
89         if (!selectedResources.isEmpty()) {
90             this.selection = new StructuredSelection(selectedResources);
91         }
92
93         // look it up if current selection (after resource adapting) is empty
94
if (selection.isEmpty() && workbench.getActiveWorkbenchWindow() != null) {
95             IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
96                     .getActivePage();
97             if (page != null) {
98                 IEditorPart currentEditor = page.getActiveEditor();
99                 if (currentEditor != null) {
100                     Object JavaDoc selectedResource = currentEditor.getEditorInput()
101                             .getAdapter(IResource.class);
102                     if (selectedResource != null) {
103                         selection = new StructuredSelection(selectedResource);
104                     }
105                 }
106             }
107         }
108
109         setWindowTitle(DataTransferMessages.DataTransfer_export);
110         setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/exportdir_wiz.png"));//$NON-NLS-1$
111
setNeedsProgressMonitor(true);
112     }
113
114     /* (non-Javadoc)
115      * Method declared on IWizard.
116      */

117     public boolean performFinish() {
118         return mainPage.finish();
119     }
120 }
121
Popular Tags