1 26 27 package org.objectweb.util.browser.core.popup; 28 29 30 import org.objectweb.util.browser.api.Context; 31 import org.objectweb.util.browser.api.Entry; 32 import org.objectweb.util.browser.api.MenuItemTreeView; 33 import org.objectweb.util.browser.core.api.MenuFactory; 34 import org.objectweb.util.browser.core.api.MenuFactoryConfiguration; 35 import org.objectweb.util.browser.core.common.DynamicTree; 36 37 44 public class DefaultMenuFactory 45 implements MenuFactory, MenuFactoryConfiguration { 46 47 48 protected String className_; 49 50 51 protected boolean inheritTreeMenu_; 52 53 54 protected boolean inheritTypeMenu_; 55 56 57 protected Context items_; 58 59 60 protected Context childItems_; 61 62 63 protected Context[] inheritTypeMenuFactory_; 64 65 66 protected Context[] inheritTreeMenuFactory_; 67 68 71 protected void addItems(AdvancedJPopupMenu menu,Context itemList,DynamicTree tree,boolean hisMenu) { 72 if (itemList != null) { 73 Entry[] entries = itemList.getEntries(); 74 for (int i = 0; i < entries.length; i++) { 75 Entry entry = entries[i]; 76 ItemProperty ip = (ItemProperty) entry.getValue(); 77 if (hisMenu || (!hisMenu && ip.isTypeChildVisible()) || (!hisMenu && ip.isTreeChildVisible())) 78 menu.addMenuItem(entry.getName().toString(), ip, tree); 79 } 80 } 81 } 82 83 87 protected boolean isEmpty(Context context) { 88 if (context != null) { 89 Entry[] entries = context.getEntries(); 90 return entries.length == 0; 91 } 92 return true; 93 } 94 95 102 public AdvancedJPopupMenu newMenu(Object object, DynamicTree tree, MenuItemTreeView treeView) { 103 104 AdvancedJPopupMenu popupMenu = 105 new AdvancedJPopupMenu(tree, treeView, inheritTreeMenu_); 106 boolean isFirst = true; 108 addItems(popupMenu,items_,tree,object.getClass().getName().equals(className_)); 111 112 if (inheritTypeMenu_ && inheritTypeMenuFactory_ != null) { 114 for (int i = 0; i < inheritTypeMenuFactory_.length; i++) { 115 if ((isFirst && !isEmpty(items_)) || !isFirst) { 116 popupMenu.addSeparator(); 117 isFirst = false; 118 } 119 addItems(popupMenu, inheritTypeMenuFactory_[i], tree, false); 120 } 121 } 122 123 return popupMenu; 124 } 125 126 132 public AdvancedJPopupMenu newParentMenu(DynamicTree tree) { 133 134 AdvancedJPopupMenu popupMenu = new AdvancedJPopupMenu(tree); 135 boolean isFirst = true; 137 addItems(popupMenu, childItems_, tree, false); 139 140 if (inheritTreeMenuFactory_ != null) { 142 for (int i = 0; i < inheritTreeMenuFactory_.length; i++) { 143 if ((isFirst && !isEmpty(childItems_)) || !isFirst) { 144 popupMenu.addSeparator(); 145 isFirst = false; 146 } 147 addItems(popupMenu, inheritTreeMenuFactory_[i], tree, false); 148 } 149 } 150 151 return popupMenu; 152 } 153 154 158 public void setInheritTreeMenu(boolean inheritTreeMenu) { 159 inheritTreeMenu_ = inheritTreeMenu; 160 } 161 162 166 public void setInheritTypeMenu(boolean inheritTypeMenu) { 167 inheritTypeMenu_ = inheritTypeMenu; 168 } 169 170 174 public void setInheritTypeMenu(Context[] inheritMenu) { 175 inheritTypeMenuFactory_ = inheritMenu; 176 } 177 178 182 public void setInheritTreeMenu(Context[] inheritMenu) { 183 inheritTreeMenuFactory_ = inheritMenu; 184 } 185 186 191 public void setItems(Context items) { 192 items_ = items; 193 } 194 195 199 public Context getItems() { 200 return items_; 201 } 202 203 207 public void setChildItems(Context childItems) { 208 childItems_ = childItems; 209 } 210 211 215 public Context getChildItems() { 216 return childItems_; 217 } 218 219 223 public void setClassName(String className) { 224 className_ = className; 225 } 226 227 } 228 | Popular Tags |