1 11 package org.eclipse.ui.internal.components.registry; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.ui.internal.components.framework.ClassIdentifier; 17 import org.eclipse.ui.internal.components.framework.ComponentFactory; 18 19 22 public class ComponentRegistry { 23 private Map scopes = new HashMap (); 24 25 public ComponentScope getScope(String scopeId) { 26 return (ComponentScope) scopes.get(scopeId); 27 } 28 29 public void loadScope(String scopeId, ScopeDefinition def) { 30 ComponentScope scope = createScope(scopeId); 31 32 scope.load(def, this); 33 } 34 35 public void unloadScope(String 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 65 public void addType(String scopeId, ClassIdentifier type, ComponentFactory factory) { 66 ComponentScope scope = createScope(scopeId); 67 68 scope.put(type, factory); 69 } 70 71 public void removeType(String 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 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 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 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 |