KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > ImportWizard


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.internal.dialogs;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.jface.wizard.IWizardNode;
17 import org.eclipse.jface.wizard.Wizard;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.ui.IWorkbench;
20 import org.eclipse.ui.IWorkbenchWizard;
21 import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
22 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
23 import org.eclipse.ui.internal.WorkbenchImages;
24 import org.eclipse.ui.internal.WorkbenchMessages;
25 import org.eclipse.ui.internal.WorkbenchPlugin;
26 import org.eclipse.ui.internal.activities.ws.WorkbenchTriggerPoints;
27 import org.eclipse.ui.internal.registry.WizardsRegistryReader;
28 import org.eclipse.ui.model.AdaptableList;
29 import org.eclipse.ui.wizards.IWizardCategory;
30
31 /**
32  * The import wizard allows the user to choose which nested import wizard to
33  * run. The set of available wizards comes from the import wizard extension
34  * point.
35  */

36 public class ImportWizard extends Wizard {
37
38     //the list selection page
39
class SelectionPage extends WorkbenchWizardListSelectionPage {
40         SelectionPage(IWorkbench w, IStructuredSelection ss, AdaptableList e,
41                 String JavaDoc s) {
42             super(w, ss, e, s, WorkbenchTriggerPoints.IMPORT_WIZARDS);
43         }
44
45         public void createControl(Composite parent) {
46             super.createControl(parent);
47             getWorkbench()
48                     .getHelpSystem()
49                     .setHelp(
50                             getControl(),
51                             IWorkbenchHelpContextIds.IMPORT_WIZARD_SELECTION_WIZARD_PAGE);
52         }
53
54         public IWizardNode createWizardNode(WorkbenchWizardElement element) {
55             return new WorkbenchWizardNode(this, element) {
56                 public IWorkbenchWizard createWizard() throws CoreException {
57                     return wizardElement.createWizard();
58                 }
59             };
60         }
61         
62         
63     }
64
65     private IStructuredSelection selection;
66
67     private IWorkbench workbench;
68
69     /**
70      * Creates the wizard's pages lazily.
71      */

72     public void addPages() {
73         addPage(new SelectionPage(this.workbench, this.selection,
74                 getAvailableImportWizards(), WorkbenchMessages.ImportWizard_selectSource));
75     }
76
77     /**
78      * Returns the import wizards that are available for invocation.
79      */

80     protected AdaptableList getAvailableImportWizards() {
81         // TODO: imports are still flat - we need to get at the flat list. All
82
// wizards will be in the "other" category.
83
IWizardCategory root = WorkbenchPlugin.getDefault()
84                 .getImportWizardRegistry().getRootCategory();
85         WizardCollectionElement otherCategory = (WizardCollectionElement) root
86                 .findCategory(new Path(
87                         WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY));
88         if (otherCategory == null) {
89             return new AdaptableList();
90         }
91         return otherCategory.getWizardAdaptableList();
92     }
93
94     /**
95      * Initializes the wizard.
96      *
97      * @param aWorkbench the workbench
98      * @param currentSelection the current selection
99      */

100     public void init(IWorkbench aWorkbench,
101             IStructuredSelection currentSelection) {
102         this.workbench = aWorkbench;
103         this.selection = currentSelection;
104
105         setWindowTitle(WorkbenchMessages.ImportWizard_title);
106         setDefaultPageImageDescriptor(WorkbenchImages
107                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_WIZ));
108         setNeedsProgressMonitor(true);
109     }
110
111     /* (non-Javadoc)
112      * @see org.eclipse.jface.wizard.IWizard#performFinish()
113      */

114     public boolean performFinish() {
115         ((SelectionPage) getPages()[0]).saveWidgetValues();
116         return true;
117     }
118 }
119
Popular Tags