1 26 package org.objectweb.util.explorer.core.menu.lib; 27 28 import java.util.List ; 29 import java.util.Vector ; 30 31 import org.objectweb.util.explorer.ExplorerUtils; 32 import org.objectweb.util.explorer.core.common.api.Description; 33 import org.objectweb.util.explorer.core.menu.api.ItemDescription; 34 import org.objectweb.util.explorer.core.menu.api.MenuDescription; 35 import org.objectweb.util.explorer.core.menu.api.MenuElement; 36 37 45 public class BasicMenuDescription 46 implements MenuDescription 47 { 48 49 55 protected boolean inheritTreeMenu_ = true; 56 protected boolean inheritTypeMenu_ = true; 57 protected List menuElements_ = null; 58 protected List childMenuElements_ = null; 59 protected String descriptionType_ = Description.MENU_DESCRIPTION; 60 61 67 public BasicMenuDescription(){ 68 menuElements_ = new Vector (); 69 childMenuElements_ = new Vector (); 70 } 71 72 78 82 protected boolean equals(BasicMenuDescription menuDesc){ 83 if(menuDesc!=null){ 84 return ExplorerUtils.compareObjects(menuElements_, menuDesc.menuElements_) 85 && ExplorerUtils.compareObjects(childMenuElements_, menuDesc.childMenuElements_); 86 } 87 return false; 88 } 89 90 96 99 public String getDescriptionType() { 100 return descriptionType_; 101 } 102 103 106 public boolean isEmpty() { 107 return menuElements_.isEmpty() && childMenuElements_.isEmpty(); 108 } 109 110 116 119 public void setDescriptionType(String descriptionType) { 120 descriptionType_ = descriptionType; 121 } 122 123 126 public void setInheritTreeMenu(boolean inheritTreeMenu) { 127 inheritTreeMenu_ = inheritTreeMenu; 128 } 129 130 133 public boolean getInheritTreeMenu() { 134 return inheritTreeMenu_; 135 } 136 137 140 public void setInheritTypeMenu(boolean inheritTypeMenu) { 141 inheritTypeMenu_ = inheritTypeMenu; 142 } 143 144 147 public boolean getInheritTypeMenu() { 148 return inheritTypeMenu_; 149 } 150 151 154 166 public void addMenuElement(MenuElement menuElement) { 167 if(menuElement!=null && !menuElement.isEmpty()){ 168 if(menuElement instanceof ItemDescription){ 169 ItemDescription itemDesc = (ItemDescription)menuElement; 170 List theList = (itemDesc.getTreeChildVisible())?childMenuElements_:menuElements_; 171 if(!theList.contains(itemDesc)){ 172 theList.add(menuElement); 173 } 174 } else { 175 menuElements_.add(menuElement); 176 } 177 } 178 } 179 180 181 184 public void addMenuElements(MenuElement[] menuElements) { 185 if(menuElements!=null){ 186 for (int i = 0; i < menuElements.length; i++) { 187 addMenuElement(menuElements[i]); 188 } 189 } 190 191 } 192 193 196 public MenuElement[] getMenuElements() { 197 return (MenuElement[])menuElements_.toArray(new MenuElement[menuElements_.size()]); 198 } 199 200 203 public MenuElement[] getChildrenMenuElements() { 204 return (MenuElement[])childMenuElements_.toArray(new MenuElement[childMenuElements_.size()]); 205 } 206 207 210 public MenuElement[] getAllMenuElements() { 211 MenuElement[] menuElement = getMenuElements(); 212 MenuElement[] childrenMenuElement = getChildrenMenuElements(); 213 boolean needSeparator = menuElement.length>0 && childrenMenuElement.length>0; 214 MenuElement[] mergeMenu = new MenuElement[menuElement.length + childrenMenuElement.length + (needSeparator?1:0)]; 215 System.arraycopy(menuElement,0,mergeMenu,0,menuElement.length); 216 if(needSeparator){ 217 mergeMenu[menuElement.length] = new BasicMenuSeparator(); 218 } 219 System.arraycopy(childrenMenuElement,0,mergeMenu,menuElement.length + (needSeparator?1:0),childrenMenuElement.length); 220 return mergeMenu; 221 } 222 223 229 233 public boolean equals(Object o){ 234 if(o!=null && o instanceof BasicMenuDescription){ 235 return equals((BasicMenuDescription)o); 236 } 237 return false; 238 } 239 240 244 public String toString(){ 245 return "BasicMenuDescription[" 246 + "inheritTreeMenu=" + inheritTreeMenu_ + ", " 247 + "inheritTypeMenu=" + inheritTypeMenu_ + ", " 248 + "menuElements=" + ExplorerUtils.arrayToString(menuElements_.toArray()) 249 + "childMenuElements=" + ExplorerUtils.arrayToString(childMenuElements_.toArray()) 250 + "]"; 251 } 252 253 } 254 255 | Popular Tags |