KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > components > registry > ComponentRegistry


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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.components.registry;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.ui.internal.components.framework.ClassIdentifier;
17 import org.eclipse.ui.internal.components.framework.ComponentFactory;
18
19 /**
20  * @since 3.1
21  */

22 public class ComponentRegistry {
23     private Map JavaDoc scopes = new HashMap JavaDoc();
24     
25     public ComponentScope getScope(String JavaDoc scopeId) {
26         return (ComponentScope) scopes.get(scopeId);
27     }
28     
29     public void loadScope(String JavaDoc scopeId, ScopeDefinition def) {
30         ComponentScope scope = createScope(scopeId);
31         
32         scope.load(def, this);
33     }
34     
35     public void unloadScope(String JavaDoc scopeId) {
36         ComponentScope scope = (ComponentScope)scopes.get(scopeId);
37         
38         if (scope != null) {
39             scope.unload(this);
40             if (scope.isRedundant()) {
41                 scopes.remove(scopeId);
42             }
43         }
44     }
45     
46 // public void addModifier(String scopeId, IComponentType componentType, IComponentType protocol, IModifierFactory factory) {
47
// ComponentScope scope = createScope(scopeId);
48
//
49
// scope.putModifier(componentType, protocol, factory);
50
// }
51
//
52
// public void removeModifier(String scopeId, IComponentType componentType, IComponentType protocol) {
53
// ComponentScope scope = getScope(scopeId);
54
//
55
// if (scope == null) {
56
// return;
57
// }
58
//
59
// scope.removeModifier(componentType, protocol);
60
// if (scope.isRedundant()) {
61
// scopes.remove(scopeId);
62
// }
63
// }
64

65     public void addType(String JavaDoc scopeId, ClassIdentifier type, ComponentFactory factory) {
66         ComponentScope scope = createScope(scopeId);
67         
68         scope.put(type, factory);
69     }
70     
71     public void removeType(String JavaDoc scopeId, ClassIdentifier type) {
72         ComponentScope scope = (ComponentScope)scopes.get(scopeId);
73         
74         if (scope != null) {
75             scope.remove(type);
76             if (scope.isRedundant()) {
77                 scopes.remove(scopeId);
78             }
79         }
80     }
81     
82     public ComponentScope linkSubScope(String JavaDoc parentScope, ComponentScope child, int relationship) {
83         ComponentScope scope = createScope(parentScope);
84         
85         scope.addChild(child, relationship);
86         
87         return scope;
88     }
89     
90     public void unlinkSubScope(String JavaDoc parentScope, ComponentScope child) {
91         ComponentScope scope = getScope(parentScope);
92         if (scope != null) {
93             scope.removeChild(child);
94             if (scope.isRedundant()) {
95                 scopes.remove(parentScope);
96             }
97         }
98     }
99     
100     private ComponentScope createScope(String JavaDoc scopeId) {
101         ComponentScope result = getScope(scopeId);
102         if (result == null) {
103             result = new ComponentScope(scopeId);
104             scopes.put(scopeId, result);
105         }
106         
107         return result;
108     }
109     
110 }
111
Popular Tags