1 19 package org.netbeans.test.editor.app.core.actions; 20 21 import java.util.HashMap ; 22 import java.util.Map ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.Collection ; 26 import java.util.Vector ; 27 import org.netbeans.test.editor.app.gui.actions.TreeNewType; 28 import org.netbeans.test.editor.app.gui.actions.TreeNodeAction; 29 30 35 public class ActionRegistry extends Object { 36 37 HashMap actions; 38 HashMap newTypes; 39 HashMap newClasses; 40 private static ActionRegistry actionRegistry = null; 41 private static Object synchronizeTo = new Object (); 42 43 44 private ActionRegistry() { 45 actions = new HashMap (); 46 newTypes=new HashMap (); 47 newClasses=new HashMap (); 48 } 49 50 public static ActionRegistry getDefault() { 51 if (actionRegistry == null) { 52 synchronized (synchronizeTo) { 53 if (actionRegistry == null) { 54 actionRegistry = new ActionRegistry(); 55 } 56 } 57 } 58 return actionRegistry; 59 } 60 61 public static void clear() { 62 actionRegistry = null; 63 } 64 65 public void addAction(Class cookie, TreeNodeAction action) { 66 Vector v; 67 v=(Vector )(actions.get(cookie)); 68 if (v == null) { 69 v=new Vector (); 70 v.add(action); 71 actions.put(cookie, v); 72 } else { 73 v.add(action); 74 } 75 } 76 77 public Vector getActions(Class cookie) { 78 return (Vector )actions.get(cookie); 79 } 80 81 public Vector getActions(Collection cookieSet) { 82 Vector result = new Vector (); 83 Iterator keys = actions.keySet().iterator(); 84 85 while (keys.hasNext()) { 86 Class key = (Class ) keys.next(); 87 Object o; 88 for (Iterator it=cookieSet.iterator();it.hasNext();) { 89 o=it.next(); 90 if (o.equals(key)) { 91 result.addAll(getActions(key)); 92 break; 93 } 94 } 95 } 96 return result; 97 } 98 99 public void registerNewType(Class newClass,TreeNewType type) { 101 newClasses.put(newClass,type); 102 } 103 104 public TreeNewType getRegisteredNewType(Class newClass) { 105 return (TreeNewType)(newClasses.get(newClass)); 106 } 107 108 public void addRegisteredNewType(Class node,Class newClass) { 109 addNewType(node,getRegisteredNewType(newClass)); 110 } 111 112 public void addNewTypes(Class node,Vector types) { 113 newTypes.put(node, types); 114 } 115 116 public void addNewType(Class node,TreeNewType type) { 117 if (newTypes.get(node) != null) { 118 ((Vector )(newTypes.get(node))).add(type); 119 } else { 120 Vector v=new Vector (); 121 addNewTypes(node,v); 122 v.add(type); 123 } 124 } 125 126 public Vector getNewTypes(Class node) { 127 return (Vector )(newTypes.get(node)); 128 } 129 } 130 | Popular Tags |