KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > wizards > AbstractWizardRegistry


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.wizards;
12
13 import org.eclipse.ui.internal.dialogs.WizardCollectionElement;
14 import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement;
15 import org.eclipse.ui.wizards.IWizardCategory;
16 import org.eclipse.ui.wizards.IWizardDescriptor;
17 import org.eclipse.ui.wizards.IWizardRegistry;
18
19 /**
20  * Abstract base class for various workbench wizards.
21  *
22  * @since 3.1
23  */

24 public abstract class AbstractWizardRegistry implements IWizardRegistry {
25
26     private boolean initialized = false;
27
28     private WorkbenchWizardElement[] primaryWizards;
29
30     private WizardCollectionElement wizardElements;
31
32     /**
33      * Create a new instance of this class.
34      */

35     public AbstractWizardRegistry() {
36         super();
37     }
38     
39     /**
40      * Dispose of this registry.
41      */

42     public void dispose() {
43         primaryWizards = null;
44         wizardElements = null;
45         initialized = false;
46     }
47
48     /**
49      * Perform initialization of this registry. Should never be called by
50      * implementations.
51      */

52     protected abstract void doInitialize();
53
54     /*
55      * (non-Javadoc)
56      *
57      * @see org.eclipse.ui.wizards.IWizardRegistry#findCategory(java.lang.String)
58      */

59     public IWizardCategory findCategory(String JavaDoc id) {
60         initialize();
61         return wizardElements.findCategory(id);
62     }
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see org.eclipse.ui.wizards.IWizardRegistry#findWizard(java.lang.String)
68      */

69     public IWizardDescriptor findWizard(String JavaDoc id) {
70         initialize();
71         return wizardElements.findWizard(id, true);
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.eclipse.ui.wizards.IWizardRegistry#getPrimaryWizards()
78      */

79     public IWizardDescriptor[] getPrimaryWizards() {
80         initialize();
81         return primaryWizards;
82     }
83
84     /*
85      * (non-Javadoc)
86      *
87      * @see org.eclipse.ui.wizards.IWizardRegistry#getRootCategory()
88      */

89     public IWizardCategory getRootCategory() {
90         initialize();
91         return wizardElements;
92     }
93
94     /**
95      * Return the wizard elements.
96      *
97      * @return the wizard elements
98      */

99     protected WizardCollectionElement getWizardElements() {
100         initialize();
101         return wizardElements;
102     }
103
104     /**
105      * Read the contents of the registry if necessary.
106      */

107     protected final synchronized void initialize() {
108         if (isInitialized()) {
109             return;
110         }
111
112         initialized = true;
113         doInitialize();
114     }
115
116     /**
117      * Return whether the registry has been read.
118      *
119      * @return whether the registry has been read
120      */

121     private boolean isInitialized() {
122         return initialized;
123     }
124
125     /**
126      * Set the primary wizards.
127      *
128      * @param primaryWizards
129      * the primary wizards
130      */

131     protected void setPrimaryWizards(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(WizardCollectionElement wizardElements) {
142         this.wizardElements = wizardElements;
143     }
144 }
145
Popular Tags