KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jface.dialogs.IDialogSettings;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.viewers.StructuredSelection;
18 import org.eclipse.jface.wizard.Wizard;
19 import org.eclipse.ui.IImportWizard;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.ide.IDE;
22 import org.eclipse.ui.internal.WorkbenchPlugin;
23 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
24 import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
25 import org.eclipse.ui.internal.wizards.datatransfer.WizardArchiveFileResourceImportPage1;
26 import org.eclipse.ui.plugin.AbstractUIPlugin;
27
28 /**
29  * Standard workbench wizard for importing resources from a zip file
30  * into the workspace.
31  * <p>
32  * This class may be instantiated and used without further configuration;
33  * this class is not intended to be subclassed.
34  * </p>
35  * <p>
36  * Example:
37  * <pre>
38  * IWizard wizard = new ZipFileImportWizard();
39  * wizard.init(workbench, selection);
40  * WizardDialog dialog = new WizardDialog(shell, wizard);
41  * dialog.open();
42  * </pre>
43  * During the call to <code>open</code>, the wizard dialog is presented to the
44  * user. When the user hits Finish, the user-selected zip file is imported
45  * into the workspace, the dialog closes, and the call to <code>open</code>
46  * returns.
47  * </p>
48  */

49 public class ZipFileImportWizard extends Wizard implements IImportWizard {
50     private IWorkbench workbench;
51
52     private IStructuredSelection selection;
53
54     private WizardArchiveFileResourceImportPage1 mainPage;
55
56     /**
57      * Creates a wizard for importing resources into the workspace from
58      * a zip file.
59      */

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

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

84     public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
85         this.workbench = workbench;
86         this.selection = currentSelection;
87         List JavaDoc selectedResources = IDE.computeSelectedResources(currentSelection);
88         if (!selectedResources.isEmpty()) {
89             this.selection = new StructuredSelection(selectedResources);
90         }
91
92         setWindowTitle(DataTransferMessages.DataTransfer_importTitle);
93         setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/importzip_wiz.png"));//$NON-NLS-1$
94
setNeedsProgressMonitor(true);
95     }
96
97     /* (non-Javadoc)
98      * Method declared on IWizard.
99      */

100     public boolean performCancel() {
101         return mainPage.cancel();
102     }
103
104     /* (non-Javadoc)
105      * Method declared on IWizard.
106      */

107     public boolean performFinish() {
108         return mainPage.finish();
109     }
110 }
111
Popular Tags