1 6 package com.nightlabs.base.entitylist; 7 8 import java.util.HashMap ; 9 import java.util.HashSet ; 10 import java.util.Map ; 11 import java.util.Set ; 12 13 import org.eclipse.core.runtime.IConfigurationElement; 14 15 import com.nightlabs.rcp.extensionpoint.AbstractEPProcessor; 16 import com.nightlabs.rcp.extensionpoint.EPProcessorException; 17 18 24 public class EntityManagerViewRegistry extends AbstractEPProcessor { 25 26 public static final String EXTENSION_POINT_ID = "com.nightlabs.base.entitymanagerview"; 27 28 34 private Map managedEntitiesByListViews = new HashMap (); 35 36 40 private Map listViewsByManager = new HashMap (); 41 42 48 private Map managerViewsByWrappedEntities = new HashMap (); 49 50 54 private Map managerViewsByEntities = new HashMap (); 55 56 60 private Map managedEnitiesByManagerView = new HashMap (); 61 62 public EntityManagerViewRegistry() { 63 super(); 64 } 65 66 69 public String getExtensionPointID() { 70 return EXTENSION_POINT_ID; 71 } 72 73 80 public Set getManagerViewsForEntityID(String entityID) { 81 if (!isProcessed()) 82 try { 83 process(); 84 } catch (EPProcessorException e) { 85 throw new RuntimeException (e); 86 } 87 return (Set )managerViewsByEntities.get(entityID); 88 } 89 90 98 public Set getManagerViewsForEntityID(String listViewID, String entityID) { 99 if (!isProcessed()) 100 try { 101 process(); 102 } catch (EPProcessorException e) { 103 throw new RuntimeException (e); 104 } 105 Map managerViewsMap = (Map )managerViewsByWrappedEntities.get(listViewID); 106 if (managerViewsMap == null) 107 return null; 108 109 return (Set )managerViewsMap.get(entityID); 110 } 111 112 120 public Set getManagedEntitiesForManagerViewID(String managerViewID) { 121 if (!isProcessed()) 122 try { 123 process(); 124 } catch (EPProcessorException e) { 125 throw new RuntimeException (e); 126 } 127 return (Set )managedEnitiesByManagerView.get(managerViewID); 128 } 129 130 137 public Set getListViewsForManagerView(String managerViewID) { 138 if (!isProcessed()) 139 try { 140 process(); 141 } catch (EPProcessorException e) { 142 throw new RuntimeException (e); 143 } 144 return (Set )listViewsByManager.get(managerViewID); 145 } 146 149 public void processElement(IConfigurationElement element) 150 throws EPProcessorException { 151 if (element.getName().equalsIgnoreCase("entityManagerView")) { 152 153 String entityID = element.getAttribute("entityID"); 154 if (entityID == null || "".equals(entityID)) 155 throw new EPProcessorException("Element entityManagerView has to define an attribute entityID"); 156 157 String listViewID = element.getAttribute("listViewID"); 158 if (listViewID == null || "".equals(listViewID)) 159 throw new EPProcessorException("Element entityManagerView has to define an attribute listViewID"); 160 161 String managerViewID = element.getAttribute("managerViewID"); 162 if (managerViewID == null || "".equals(managerViewID)) 163 throw new EPProcessorException("Element entityManagerView has to define an attribute managerViewID"); 164 165 166 172 { 173 Map managerViewEntities = (Map )managedEntitiesByListViews.get(listViewID); 174 if (managerViewEntities == null) { 175 managerViewEntities = new HashMap (); 176 managedEntitiesByListViews.put(listViewID, managerViewEntities); 177 } 178 Set entities = (Set )managerViewEntities.get(managerViewID); 179 if (entities == null) { 180 entities = new HashSet (); 181 managerViewEntities.put(managerViewID, entities); 182 } 183 entities.add(entityID); 184 } 185 186 190 { 191 Set listViews = (Set )listViewsByManager.get(managerViewID); 192 if (listViews == null) { 193 listViews = new HashSet (); 194 listViewsByManager.put(managerViewID, listViews); 195 } 196 listViews.add(listViewID); 197 } 198 199 205 { 206 Map managerMap = (Map )managerViewsByWrappedEntities.get(listViewID); 207 if (managerMap == null) { 208 managerMap = new HashMap (); 209 managerViewsByWrappedEntities.put(listViewID, managerMap); 210 } 211 Set managers = (Set )managerMap.get(entityID); 212 if (managers == null) { 213 managers = new HashSet (); 214 managerMap.put(entityID, managers); 215 } 216 managers.add(managerViewID); 217 } 218 219 223 { 224 Set managers = (Set )managerViewsByEntities.get(entityID); 225 if (managers == null) { 226 managers = new HashSet (); 227 managerViewsByEntities.put(entityID, managers); 228 } 229 managers.add(managerViewID); 230 } 231 232 236 { 237 Set entities = (Set )managedEnitiesByManagerView.get(managerViewID); 238 if (entities == null) { 239 entities = new HashSet (); 240 managedEnitiesByManagerView.put(managerViewID, entities); 241 } 242 entities.add(entityID); 243 } 244 245 } 246 } 247 248 249 private static EntityManagerViewRegistry sharedInstance; 250 251 public static EntityManagerViewRegistry getSharedInstance() { 252 if (sharedInstance == null) 253 sharedInstance = new EntityManagerViewRegistry(); 254 return sharedInstance; 255 } 256 257 } 258 | Popular Tags |