001: /*******************************************************************************
002: * Copyright (c) 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.registry;
011:
012: import java.util.HashMap;
013: import java.util.Map;
014:
015: import org.eclipse.core.commands.IParameterValues;
016: import org.eclipse.ui.PlatformUI;
017: import org.eclipse.ui.wizards.IWizardCategory;
018: import org.eclipse.ui.wizards.IWizardDescriptor;
019: import org.eclipse.ui.wizards.IWizardRegistry;
020:
021: /**
022: * Provides the parameter values for a show wizard command.
023: * <p>
024: * This class is only intended to be extended by the three inner classes (<code>Export</code>,
025: * <code>Import</code> and <code>New</code>) defined here.
026: * </p>
027: *
028: * @since 3.2
029: */
030: public abstract class WizardParameterValues implements IParameterValues {
031:
032: /**
033: * Provides the parameter values for export wizards.
034: */
035: public static final class Export extends WizardParameterValues {
036: protected IWizardRegistry getWizardRegistry() {
037: return PlatformUI.getWorkbench().getExportWizardRegistry();
038: }
039: }
040:
041: /**
042: * Provides the parameter values for import wizards.
043: */
044: public static final class Import extends WizardParameterValues {
045: protected IWizardRegistry getWizardRegistry() {
046: return PlatformUI.getWorkbench().getImportWizardRegistry();
047: }
048: }
049:
050: /**
051: * Provides the parameter values for new wizards.
052: */
053: public static final class New extends WizardParameterValues {
054: protected IWizardRegistry getWizardRegistry() {
055: return PlatformUI.getWorkbench().getNewWizardRegistry();
056: }
057: }
058:
059: private void addParameterValues(Map values,
060: IWizardCategory wizardCategory) {
061:
062: final IWizardDescriptor[] wizardDescriptors = wizardCategory
063: .getWizards();
064: for (int i = 0; i < wizardDescriptors.length; i++) {
065: final IWizardDescriptor wizardDescriptor = wizardDescriptors[i];
066:
067: // Note: using description instead of label for the name
068: // to reduce possibilities of key collision in the map
069: // final String name = wizardDescriptor.getDescription();
070:
071: // by request
072: String name = wizardDescriptor.getLabel();
073: final String id = wizardDescriptor.getId();
074: final String value = (String) values.get(name);
075: if (value != null && !value.equals(id)) {
076: name = name + " (" + id + ")"; //$NON-NLS-1$//$NON-NLS-2$
077: }
078: values.put(name, id);
079: }
080:
081: final IWizardCategory[] childCategories = wizardCategory
082: .getCategories();
083: for (int i = 0; i < childCategories.length; i++) {
084: final IWizardCategory childCategory = childCategories[i];
085: addParameterValues(values, childCategory);
086: }
087: }
088:
089: public Map getParameterValues() {
090: final Map values = new HashMap();
091:
092: final IWizardRegistry wizardRegistry = getWizardRegistry();
093: addParameterValues(values, wizardRegistry.getRootCategory());
094:
095: return values;
096: }
097:
098: /**
099: * Returns the wizard registry for the concrete
100: * <code>WizardParameterValues</code> implementation class.
101: *
102: * @return The wizard registry for the concrete
103: * <code>WizardParameterValues</code> implementation class.
104: */
105: protected abstract IWizardRegistry getWizardRegistry();
106:
107: }
|