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