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.internal.dialogs;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.Path;
014: import org.eclipse.jface.viewers.IStructuredSelection;
015: import org.eclipse.jface.wizard.IWizardNode;
016: import org.eclipse.jface.wizard.Wizard;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.ui.IWorkbench;
019: import org.eclipse.ui.IWorkbenchWizard;
020: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
021: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
022: import org.eclipse.ui.internal.WorkbenchImages;
023: import org.eclipse.ui.internal.WorkbenchMessages;
024: import org.eclipse.ui.internal.WorkbenchPlugin;
025: import org.eclipse.ui.internal.activities.ws.WorkbenchTriggerPoints;
026: import org.eclipse.ui.internal.registry.WizardsRegistryReader;
027: import org.eclipse.ui.model.AdaptableList;
028: import org.eclipse.ui.wizards.IWizardCategory;
029:
030: /**
031: * The import wizard allows the user to choose which nested import wizard to
032: * run. The set of available wizards comes from the import wizard extension
033: * point.
034: */
035: public class ImportWizard extends Wizard {
036:
037: //the list selection page
038: class SelectionPage extends WorkbenchWizardListSelectionPage {
039: SelectionPage(IWorkbench w, IStructuredSelection ss,
040: AdaptableList e, String s) {
041: super (w, ss, e, s, WorkbenchTriggerPoints.IMPORT_WIZARDS);
042: }
043:
044: public void createControl(Composite parent) {
045: super .createControl(parent);
046: getWorkbench()
047: .getHelpSystem()
048: .setHelp(
049: getControl(),
050: IWorkbenchHelpContextIds.IMPORT_WIZARD_SELECTION_WIZARD_PAGE);
051: }
052:
053: public IWizardNode createWizardNode(
054: WorkbenchWizardElement element) {
055: return new WorkbenchWizardNode(this , element) {
056: public IWorkbenchWizard createWizard()
057: throws CoreException {
058: return wizardElement.createWizard();
059: }
060: };
061: }
062:
063: }
064:
065: private IStructuredSelection selection;
066:
067: private IWorkbench workbench;
068:
069: /**
070: * Creates the wizard's pages lazily.
071: */
072: public void addPages() {
073: addPage(new SelectionPage(this .workbench, this .selection,
074: getAvailableImportWizards(),
075: WorkbenchMessages.ImportWizard_selectSource));
076: }
077:
078: /**
079: * Returns the import wizards that are available for invocation.
080: */
081: protected AdaptableList getAvailableImportWizards() {
082: // TODO: imports are still flat - we need to get at the flat list. All
083: // wizards will be in the "other" category.
084: IWizardCategory root = WorkbenchPlugin.getDefault()
085: .getImportWizardRegistry().getRootCategory();
086: WizardCollectionElement otherCategory = (WizardCollectionElement) root
087: .findCategory(new Path(
088: WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY));
089: if (otherCategory == null) {
090: return new AdaptableList();
091: }
092: return otherCategory.getWizardAdaptableList();
093: }
094:
095: /**
096: * Initializes the wizard.
097: *
098: * @param aWorkbench the workbench
099: * @param currentSelection the current selection
100: */
101: public void init(IWorkbench aWorkbench,
102: IStructuredSelection currentSelection) {
103: this .workbench = aWorkbench;
104: this .selection = currentSelection;
105:
106: setWindowTitle(WorkbenchMessages.ImportWizard_title);
107: setDefaultPageImageDescriptor(WorkbenchImages
108: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_WIZ));
109: setNeedsProgressMonitor(true);
110: }
111:
112: /* (non-Javadoc)
113: * @see org.eclipse.jface.wizard.IWizard#performFinish()
114: */
115: public boolean performFinish() {
116: ((SelectionPage) getPages()[0]).saveWidgetValues();
117: return true;
118: }
119: }
|