1 package com.blandware.atleap.webapp.menu; 2 3 import com.blandware.atleap.common.util.ConvertUtil; 4 import org.apache.commons.lang.StringUtils; 5 6 import java.io.Serializable ; 7 import java.util.ArrayList ; 8 import java.util.List ; 9 10 11 21 public class MenuComponent extends MenuBase implements Serializable { 22 protected static MenuComponent[] _menuComponent = new MenuComponent[0]; 24 25 27 protected List menuComponents = new ArrayList (); 28 protected MenuComponent parentMenu = null; 29 30 33 protected transient String ident = null; 34 35 37 40 public MenuComponent() { 41 super(); 42 } 43 44 46 51 public void addMenuComponent(MenuComponent menuComponent) { 52 if ( (menuComponent.getName() == null) || 53 (menuComponent.getName().equals("")) ) { 54 menuComponent.setName(this.name + menuComponents.size()); 55 } 56 57 if ( !menuComponents.contains(menuComponent) ) { 58 menuComponents.add(menuComponent); 59 menuComponent.setParent(this); 60 } 61 } 62 63 68 public MenuComponent[] getMenuComponents() { 69 MenuComponent[] menus = 70 (MenuComponent[]) menuComponents.toArray(_menuComponent); 71 72 return menus; 73 } 74 75 80 public void setParent(MenuComponent parentMenu) { 81 if ( parentMenu != null ) { 82 if ( !parentMenu.getComponents().contains(this) ) { 84 parentMenu.addMenuComponent(this); 85 } 86 } 87 this.parentMenu = parentMenu; 88 } 89 90 95 public MenuComponent getParent() { 96 return parentMenu; 97 } 98 99 104 public List getComponents() { 105 return menuComponents; 106 } 107 108 115 public String getIdent() { 116 if ( ident == null ) { 117 if (parentMenu == null) { 118 ident = "DropdownMenu__" + this.hashCode(); 119 } else { 120 String parentId = parentMenu.getIdent(); 121 if ( parentId != null ) { 122 int pos = parentMenu.getComponents().indexOf(this); 123 ident = parentId + "__" + pos; 124 } 125 } 126 } 127 return ident; 128 } 129 130 137 public List getComponentsAsPlainList() { 138 List result = new ArrayList (); 139 result.add(this); 140 141 for (int i = 0; i < menuComponents.size(); i++) { 142 MenuComponent child = (MenuComponent) menuComponents.get(i); 143 result.addAll(child.getComponentsAsPlainList()); 144 } 145 146 return result; 147 } 148 149 154 public String getJavascriptCode() { 155 StringBuffer code = new StringBuffer ("new DropdownMenuItem("); 156 code.append("\"").append(getIdent()).append("\""); 157 158 for ( int i = 0; i < menuComponents.size(); i++ ) { 160 MenuComponent item = (MenuComponent) menuComponents.get(i); 161 code.append(", "); 162 if ( item != null ) { 163 code.append(item.getJavascriptCode()); 164 } else { 165 code.append(item); 166 } 167 } 168 code.append(")"); 169 return code.toString(); 170 } 171 172 178 public String getRolesWithAncestors() { 179 MenuComponent parent = getParent(); 180 if (parent == null) { 181 return getRoles(); 182 } else { 183 List thisRoles = ConvertUtil.convertStringToList(getRoles(), ",", true); 184 List parentRoles = ConvertUtil.convertStringToList(parent.getRolesWithAncestors(), ",", true); 185 thisRoles.addAll(parentRoles); 186 return ConvertUtil.convertListToString(thisRoles, ","); 187 } 188 } 189 190 196 public boolean equals(Object o) { 197 if ( !(o instanceof MenuComponent) ) { 198 return false; 199 } 200 MenuComponent m = (MenuComponent) o; 201 return StringUtils.equals(m.getAction(), this.action) && 203 StringUtils.equals(m.getAlign(), this.align) && 204 StringUtils.equals(m.getAltImage(), this.altImage) && 205 StringUtils.equals(m.getDescription(), this.description) && 206 StringUtils.equals(m.getForward(), this.forward) && 207 StringUtils.equals(m.getStyle(), this.style) && 208 StringUtils.equals(m.getImage(), this.image) && 209 StringUtils.equals(m.getLocation(), this.location) && 210 StringUtils.equals(m.getName(), this.name) && 211 StringUtils.equals(m.getOnclick(), this.onclick) && 212 StringUtils.equals(m.getOnmouseout(), this.onmouseout) && 213 StringUtils.equals(m.getOnmouseover(), this.onmouseover) && 214 StringUtils.equals(m.getAnchor(), this.anchor) && 215 StringUtils.equals(m.getRoles(), this.roles) && 216 StringUtils.equals(m.getTarget(), this.target) && 217 StringUtils.equals(m.getTitle(), this.title) && 218 StringUtils.equals(m.getToolTip(), this.toolTip) && 219 StringUtils.equals(m.getStyleClass(), this.styleClass); 220 } 221 } 222 | Popular Tags |