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.runtime.Platform;
015: import org.eclipse.jface.dialogs.IDialogSettings;
016: import org.eclipse.jface.viewers.IStructuredSelection;
017: import org.eclipse.jface.viewers.StructuredSelection;
018: import org.eclipse.jface.wizard.Wizard;
019: import org.eclipse.ui.IImportWizard;
020: import org.eclipse.ui.IWorkbench;
021: import org.eclipse.ui.PlatformUI;
022: import org.eclipse.ui.ide.IDE;
023: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
024: import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
025: import org.eclipse.ui.internal.wizards.datatransfer.WizardFileSystemResourceImportPage1;
026: import org.eclipse.ui.plugin.AbstractUIPlugin;
027:
028: /**
029: * Standard workbench wizard for importing resources from the local file system
030: * into the workspace.
031: * <p>
032: * This class may be instantiated and used without further configuration;
033: * this class is not intended to be subclassed.
034: * </p>
035: * <p>
036: * Example:
037: * <pre>
038: * IWizard wizard = new FileSystemImportWizard();
039: * wizard.init(workbench, selection);
040: * WizardDialog dialog = new WizardDialog(shell, wizard);
041: * dialog.open();
042: * </pre>
043: * During the call to <code>open</code>, the wizard dialog is presented to the
044: * user. When the user hits Finish, the user-selected files are imported
045: * into the workspace, the dialog closes, and the call to <code>open</code>
046: * returns.
047: * </p>
048: */
049: public class FileSystemImportWizard extends Wizard implements
050: IImportWizard {
051: private IWorkbench workbench;
052:
053: private IStructuredSelection selection;
054:
055: private WizardFileSystemResourceImportPage1 mainPage;
056:
057: /**
058: * Creates a wizard for importing resources into the workspace from
059: * the file system.
060: */
061: public FileSystemImportWizard() {
062: AbstractUIPlugin plugin = (AbstractUIPlugin) Platform
063: .getPlugin(PlatformUI.PLUGIN_ID);
064: IDialogSettings workbenchSettings = plugin.getDialogSettings();
065: IDialogSettings section = workbenchSettings
066: .getSection("FileSystemImportWizard");//$NON-NLS-1$
067: if (section == null) {
068: section = workbenchSettings
069: .addNewSection("FileSystemImportWizard");//$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 WizardFileSystemResourceImportPage1(workbench,
080: selection);
081: addPage(mainPage);
082: }
083:
084: /* (non-Javadoc)
085: * Method declared on IWorkbenchWizard.
086: */
087: public void init(IWorkbench workbench,
088: IStructuredSelection currentSelection) {
089: this .workbench = workbench;
090: this .selection = currentSelection;
091:
092: List selectedResources = IDE
093: .computeSelectedResources(currentSelection);
094: if (!selectedResources.isEmpty()) {
095: this .selection = new StructuredSelection(selectedResources);
096: }
097:
098: setWindowTitle(DataTransferMessages.DataTransfer_importTitle);
099: setDefaultPageImageDescriptor(IDEWorkbenchPlugin
100: .getIDEImageDescriptor("wizban/importdir_wiz.png"));//$NON-NLS-1$
101: setNeedsProgressMonitor(true);
102: }
103:
104: /* (non-Javadoc)
105: * Method declared on IWizard.
106: */
107: public boolean performFinish() {
108: return mainPage.finish();
109: }
110: }
|