001: /*******************************************************************************
002: * Copyright (c) 2004, 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.wizards;
011:
012: import org.eclipse.ui.internal.dialogs.WizardCollectionElement;
013: import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement;
014: import org.eclipse.ui.wizards.IWizardCategory;
015: import org.eclipse.ui.wizards.IWizardDescriptor;
016: import org.eclipse.ui.wizards.IWizardRegistry;
017:
018: /**
019: * Abstract base class for various workbench wizards.
020: *
021: * @since 3.1
022: */
023: public abstract class AbstractWizardRegistry implements IWizardRegistry {
024:
025: private boolean initialized = false;
026:
027: private WorkbenchWizardElement[] primaryWizards;
028:
029: private WizardCollectionElement wizardElements;
030:
031: /**
032: * Create a new instance of this class.
033: */
034: public AbstractWizardRegistry() {
035: super ();
036: }
037:
038: /**
039: * Dispose of this registry.
040: */
041: public void dispose() {
042: primaryWizards = null;
043: wizardElements = null;
044: initialized = false;
045: }
046:
047: /**
048: * Perform initialization of this registry. Should never be called by
049: * implementations.
050: */
051: protected abstract void doInitialize();
052:
053: /*
054: * (non-Javadoc)
055: *
056: * @see org.eclipse.ui.wizards.IWizardRegistry#findCategory(java.lang.String)
057: */
058: public IWizardCategory findCategory(String id) {
059: initialize();
060: return wizardElements.findCategory(id);
061: }
062:
063: /*
064: * (non-Javadoc)
065: *
066: * @see org.eclipse.ui.wizards.IWizardRegistry#findWizard(java.lang.String)
067: */
068: public IWizardDescriptor findWizard(String id) {
069: initialize();
070: return wizardElements.findWizard(id, true);
071: }
072:
073: /*
074: * (non-Javadoc)
075: *
076: * @see org.eclipse.ui.wizards.IWizardRegistry#getPrimaryWizards()
077: */
078: public IWizardDescriptor[] getPrimaryWizards() {
079: initialize();
080: return primaryWizards;
081: }
082:
083: /*
084: * (non-Javadoc)
085: *
086: * @see org.eclipse.ui.wizards.IWizardRegistry#getRootCategory()
087: */
088: public IWizardCategory getRootCategory() {
089: initialize();
090: return wizardElements;
091: }
092:
093: /**
094: * Return the wizard elements.
095: *
096: * @return the wizard elements
097: */
098: protected WizardCollectionElement getWizardElements() {
099: initialize();
100: return wizardElements;
101: }
102:
103: /**
104: * Read the contents of the registry if necessary.
105: */
106: protected final synchronized void initialize() {
107: if (isInitialized()) {
108: return;
109: }
110:
111: initialized = true;
112: doInitialize();
113: }
114:
115: /**
116: * Return whether the registry has been read.
117: *
118: * @return whether the registry has been read
119: */
120: private boolean isInitialized() {
121: return initialized;
122: }
123:
124: /**
125: * Set the primary wizards.
126: *
127: * @param primaryWizards
128: * the primary wizards
129: */
130: protected void setPrimaryWizards(
131: WorkbenchWizardElement[] primaryWizards) {
132: this .primaryWizards = primaryWizards;
133: }
134:
135: /**
136: * Set the wizard elements.
137: *
138: * @param wizardElements
139: * the wizard elements
140: */
141: protected void setWizardElements(
142: WizardCollectionElement wizardElements) {
143: this.wizardElements = wizardElements;
144: }
145: }
|