001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.wizards.datatransfer;
011:
012: import java.util.List;
013:
014: import org.eclipse.core.resources.IResource;
015: import org.eclipse.core.runtime.Platform;
016: import org.eclipse.jface.dialogs.IDialogSettings;
017: import org.eclipse.jface.viewers.IStructuredSelection;
018: import org.eclipse.jface.viewers.StructuredSelection;
019: import org.eclipse.jface.wizard.Wizard;
020: import org.eclipse.ui.IEditorPart;
021: import org.eclipse.ui.IExportWizard;
022: import org.eclipse.ui.IWorkbench;
023: import org.eclipse.ui.IWorkbenchPage;
024: import org.eclipse.ui.PlatformUI;
025: import org.eclipse.ui.ide.IDE;
026: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
027: import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
028: import org.eclipse.ui.internal.wizards.datatransfer.WizardFileSystemResourceExportPage1;
029: import org.eclipse.ui.plugin.AbstractUIPlugin;
030:
031: /**
032: * Standard workbench wizard for exporting resources from the workspace
033: * to the local file system.
034: * <p>
035: * This class may be instantiated and used without further configuration;
036: * this class is not intended to be subclassed.
037: * </p>
038: * <p>
039: * Example:
040: * <pre>
041: * IWizard wizard = new FileSystemExportWizard();
042: * wizard.init(workbench, selection);
043: * WizardDialog dialog = new WizardDialog(shell, wizard);
044: * dialog.open();
045: * </pre>
046: * During the call to <code>open</code>, the wizard dialog is presented to the
047: * user. When the user hits Finish, the user-selected workspace resources
048: * are exported to the user-specified location in the local file system,
049: * the dialog closes, and the call to <code>open</code> returns.
050: * </p>
051: */
052: public class FileSystemExportWizard extends Wizard implements
053: IExportWizard {
054: private IStructuredSelection selection;
055:
056: private WizardFileSystemResourceExportPage1 mainPage;
057:
058: /**
059: * Creates a wizard for exporting workspace resources to the local file system.
060: */
061: public FileSystemExportWizard() {
062: AbstractUIPlugin plugin = (AbstractUIPlugin) Platform
063: .getPlugin(PlatformUI.PLUGIN_ID);
064: IDialogSettings workbenchSettings = plugin.getDialogSettings();
065: IDialogSettings section = workbenchSettings
066: .getSection("FileSystemExportWizard");//$NON-NLS-1$
067: if (section == null) {
068: section = workbenchSettings
069: .addNewSection("FileSystemExportWizard");//$NON-NLS-1$
070: }
071: setDialogSettings(section);
072: }
073:
074: /* (non-Javadoc)
075: * Method declared on IWizard.
076: */
077: public void addPages() {
078: super .addPages();
079: mainPage = new WizardFileSystemResourceExportPage1(selection);
080: addPage(mainPage);
081: }
082:
083: /* (non-Javadoc)
084: * Method declared on IWorkbenchWizard.
085: */
086: public void init(IWorkbench workbench,
087: IStructuredSelection currentSelection) {
088: this .selection = currentSelection;
089: List selectedResources = IDE
090: .computeSelectedResources(currentSelection);
091: if (!selectedResources.isEmpty()) {
092: this .selection = new StructuredSelection(selectedResources);
093: }
094:
095: // look it up if current selection (after resource adapting) is empty
096: if (selection.isEmpty()
097: && workbench.getActiveWorkbenchWindow() != null) {
098: IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
099: .getActivePage();
100: if (page != null) {
101: IEditorPart currentEditor = page.getActiveEditor();
102: if (currentEditor != null) {
103: Object selectedResource = currentEditor
104: .getEditorInput().getAdapter(
105: IResource.class);
106: if (selectedResource != null) {
107: selection = new StructuredSelection(
108: selectedResource);
109: }
110: }
111: }
112: }
113:
114: setWindowTitle(DataTransferMessages.DataTransfer_export);
115: setDefaultPageImageDescriptor(IDEWorkbenchPlugin
116: .getIDEImageDescriptor("wizban/exportdir_wiz.png"));//$NON-NLS-1$
117: setNeedsProgressMonitor(true);
118: }
119:
120: /* (non-Javadoc)
121: * Method declared on IWizard.
122: */
123: public boolean performFinish() {
124: return mainPage.finish();
125: }
126: }
|