1 26 27 package org.objectweb.util.browser.core.common; 28 29 import javax.swing.JPopupMenu ; 30 import javax.swing.Icon ; 31 import java.util.Vector ; 32 import org.objectweb.util.browser.api.Context; 33 import org.objectweb.util.browser.api.Entry; 34 import org.objectweb.util.browser.api.DropAction; 35 import org.objectweb.util.browser.api.Panel; 36 import org.objectweb.util.browser.api.Info; 37 import org.objectweb.util.browser.core.wrapper.AssociatedContextImpl; 38 import org.objectweb.util.browser.core.naming.DefaultEntry; 39 import org.objectweb.util.browser.core.naming.DefaultName; 40 import org.objectweb.util.browser.core.popup.AssociatedMenuImpl; 41 import org.objectweb.util.browser.core.popup.AdvancedJPopupMenu; 42 import org.objectweb.util.browser.core.popup.DefaultMenuItemTreeView; 43 import org.objectweb.util.browser.core.panel.AssociatedPanelImpl; 44 import org.objectweb.util.browser.core.api.AssociatedContext; 45 import org.objectweb.util.browser.core.api.AssociatedDropAction; 46 import org.objectweb.util.browser.core.api.AssociatedIcon; 47 import org.objectweb.util.browser.core.api.AssociatedInfo; 48 import org.objectweb.util.browser.core.api.AssociatedMenu; 49 import org.objectweb.util.browser.core.api.AssociatedPanel; 50 import org.objectweb.util.browser.core.api.BrowserProperty; 51 import org.objectweb.util.browser.core.api.ExtendedEntry; 52 import org.objectweb.util.browser.core.api.RootFactory; 53 import org.objectweb.util.browser.core.api.Role; 54 import org.objectweb.util.browser.core.dnd.AssociatedDropActionImpl; 55 import org.objectweb.util.browser.core.icon.AssociatedIconImpl; 56 import org.objectweb.util.browser.core.info.AssociatedInfoImpl; 57 58 64 public class AdminCustomization { 65 66 67 protected DynamicTree tree_; 68 69 70 protected AssociatedIcon icons = null; 71 72 73 protected AssociatedPanel panels = null; 74 75 76 protected AssociatedMenu menus = null; 77 78 79 protected AssociatedContext wrappers = null; 80 81 82 protected AssociatedDropAction dropAction = null; 83 84 85 protected AssociatedInfo infos = null; 86 87 88 protected BrowserProperty properties_ = null; 89 90 91 public static final int TREE_TARGET = 0; 92 93 94 public static final int TABLE_TARGET = TREE_TARGET + 1; 95 96 101 public AdminCustomization(BrowserProperty properties, DynamicTree tree) { 102 tree_ = tree; 103 properties_ = properties; 104 if (properties != null) { 105 icons = new AssociatedIconImpl(properties); 106 menus = new AssociatedMenuImpl(properties, tree); 107 panels = new AssociatedPanelImpl(properties); 108 wrappers = new AssociatedContextImpl(properties); 109 dropAction = new AssociatedDropActionImpl(properties); 110 infos = new AssociatedInfoImpl(properties); 111 } else 112 System.out.println("The properties param is null !"); 113 } 114 115 119 public BrowserProperty getBrowserProperty() { 120 return properties_; 121 } 122 123 141 public JPopupMenu getMenu(Object object, int target) { 142 if (object != null) { 143 if(target == TREE_TARGET) { 144 ExtendedEntry entry = (ExtendedEntry)object; 145 AdvancedJPopupMenu objectMenu = menus.getMenu(entry.getWrappedObject(), true, new DefaultMenuItemTreeView(tree_)); 146 AdvancedJPopupMenu compositeMenu = menus.getMenu(entry.getValue(), new DefaultMenuItemTreeView(tree_)); 147 ExtendedEntry parentEntry = (ExtendedEntry) tree_.getSelectedEntryParent(); 148 AdvancedJPopupMenu objectChildMenu = null; 149 AdvancedJPopupMenu compositeChildMenu = null; 150 if (parentEntry != null) { 151 objectChildMenu = menus.getParentMenu(parentEntry.getWrappedObject()); 152 compositeChildMenu = menus.getParentMenu(parentEntry.getValue()); 153 } 154 AdvancedJPopupMenu fusion = new AdvancedJPopupMenu(tree_); 155 fusion.add(objectMenu); 156 fusion.add(compositeMenu); 157 if (objectMenu != null && objectMenu.hasToInheritTreeMenu() || objectMenu == null) { 158 fusion.add(objectChildMenu); 159 fusion.add(compositeChildMenu); 160 } 161 return fusion; 162 } else if(target == TABLE_TARGET) { 163 if(ExtendedEntry.class.isAssignableFrom(object.getClass())){ 164 ExtendedEntry entry = (ExtendedEntry)object; 165 AdvancedJPopupMenu objectMenu = menus.getMenu(entry.getWrappedObject(), true, new DefaultMenuItemTreeView(tree_, entry)); 166 AdvancedJPopupMenu compositeMenu = menus.getMenu(entry.getValue(), new DefaultMenuItemTreeView(tree_, entry)); 167 AdvancedJPopupMenu fusion = new AdvancedJPopupMenu(tree_); 168 fusion.add(objectMenu); 169 fusion.add(compositeMenu); 170 return fusion; 171 } else { 172 return menus.getMenu(object, new DefaultMenuItemTreeView(tree_, new DefaultEntry(object, new DefaultName(object.toString()),null))); 173 } 174 } 175 } 176 return null; 177 } 178 179 183 public JPopupMenu getMenu(Object object) { 184 return getMenu(object,TREE_TARGET); 185 } 186 187 202 public Icon getIcon(Object object){ 203 if(object != null) { 204 Icon icon = null; 205 if(ExtendedEntry.class.isAssignableFrom(object.getClass())){ 206 ExtendedEntry entry = (ExtendedEntry)object; 207 icon = icons.getIcon(entry.getWrappedObject(), true); 208 if (icon == null) 209 icon = icons.getIcon(entry.getValue()); 210 return icon; 211 } else 212 return icons.getIcon(object); 213 } 214 return null; 215 } 216 217 218 227 public Panel getPanel(ExtendedEntry entry) { 228 if (entry != null) { 229 Panel panel = panels.getPanel(entry.getWrappedObject(), true); 230 if (panel == null) 231 panel = panels.getPanel(entry.getValue()); 232 return panel; 233 } 234 return null; 235 } 236 237 241 public Context getContext(Object node) { 242 if (wrappers != null) 243 return wrappers.getContext(node); 244 return null; 245 } 246 247 256 public DropAction getDropAction(ExtendedEntry entry, int theDropAction) { 257 if (entry != null) { 258 DropAction action = dropAction.getDropAction(entry.getWrappedObject(), true, theDropAction); 259 if (action == null) 260 action = dropAction.getDropAction(entry.getValue(), theDropAction); 261 return action; 262 } 263 return null; 264 } 265 266 275 public String getDropLabel(ExtendedEntry entry, int theDropAction) { 276 if (entry != null) { 277 String label = dropAction.getDropLabel(entry.getWrappedObject(), true, theDropAction); 278 if (label == null) 279 label = dropAction.getDropLabel(entry.getValue(), theDropAction); 280 return label; 281 } 282 return ""; 283 } 284 285 294 public Info getInfo(ExtendedEntry entry) { 295 if (entry != null) { 296 Info info = infos.getInfo(entry.getWrappedObject(), true); 297 if (info == null) 298 info = infos.getInfo(entry.getValue()); 299 return info; 300 } 301 return null; 302 } 303 304 307 public Entry[] getRoot() { 308 Role[] roles = properties_.getInheritedRoles(); 309 Vector values = new Vector (); 310 Entry[] entries = null; 311 for(int i = 0 ; i < roles.length ; i++) { 312 RootFactory rootFactory = properties_.getRoot(roles[i]); 313 if(rootFactory!=null){ 314 entries = rootFactory.newRootContext(); 315 for(int j = 0 ; j < entries.length ; j++) 316 values.add(entries[j]); 317 } 318 } 319 return (Entry[])values.toArray(new Entry[0]); 320 } 321 322 325 public void clear(){ 326 icons.clear(); 327 panels.clear(); 328 menus.clear(); 329 wrappers.clear(); 330 dropAction.clear(); 331 infos.clear(); 332 } 333 } 334 | Popular Tags |