1 13 package info.magnolia.cms.gui.control; 14 15 import java.util.ArrayList ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 20 25 public class ContextMenu extends ControlImpl { 26 27 30 private List menuItems = new ArrayList (); 31 32 36 public ContextMenu(String menuName) { 37 super(); 38 this.setName(menuName); 39 } 40 41 44 public List getMenuItems() { 45 return this.menuItems; 46 } 47 48 52 public void setMenuItems(List menuItems) { 53 this.menuItems = menuItems; 54 } 55 56 60 public ContextMenuItem getMenuItem(int col) { 61 return (ContextMenuItem) this.getMenuItems().get(col); 62 } 63 64 68 public ContextMenuItem getMenuItemByName(String name) { 69 java.util.List menuItems = this.getMenuItems(); 70 for (Iterator iter = menuItems.iterator(); iter.hasNext();) { 71 ContextMenuItem menuItem = (ContextMenuItem) iter.next(); 72 if (menuItem != null && menuItem.getName() != null && menuItem.getName() == name) { 73 return menuItem; 74 } 75 } 76 return null; 77 } 78 79 83 public void addMenuItem(ContextMenuItem item) { 84 this.getMenuItems().add(item); 85 } 86 87 91 public String getHtml() { 92 StringBuffer html = new StringBuffer (); 93 html 94 .append("<div id=\"" + getName() + "_DivMenu\" class=\"mgnlTreeMenu\" onmouseover=\"" + getName() + ".keepShowing();\" onmouseout=\"" + getName() + ".hide();\" >"); int counter = 0; 96 97 for (int i = 0; i < this.getMenuItems().size(); i++) { 98 ContextMenuItem item = this.getMenuItem(i); 99 if (item == null) { 100 html.append("<div class=\"mgnlTreeMenuLine\"><!-- ie --></div>"); } 102 else { 103 item.setJavascriptMenuName(getName()); 104 String id = getName() + "_MenuItem" + i; item.setId(id); 106 html.append(item.getHtml()); 107 counter++; 108 } 109 html.append("\n"); 110 } 111 112 html.append("</div>"); return html.toString(); 114 } 115 116 public String getJavascript() { 117 StringBuffer menuJavascript = new StringBuffer (); 118 menuJavascript.append("var " + getName() + "= new mgnlContextMenu('" + getName() + "');"); 119 int counter = 0; 120 for (int i = 0; i < this.getMenuItems().size(); i++) { 121 ContextMenuItem item = this.getMenuItem(i); 122 if (item != null) { 123 item.setJavascriptMenuName(getName()); 124 String id = getName() + "_MenuItem" + i; item.setId(id); 126 menuJavascript.append(getName() + ".menuItems[" + counter 128 + "]=new mgnlContextMenuItem('" + id 130 + "');\n"); menuJavascript.append(getName() + ".menuItems[" + counter + "].conditions=new Object();"); for (int cond = 0; cond < item.getJavascriptConditions().size(); cond++) { 133 menuJavascript.append(getName() + ".menuItems[" + counter 135 + "].conditions[" + cond 137 + "]=" + item.getJavascriptCondition(cond) 139 + ";"); } 141 counter++; 142 } 143 } 144 145 return menuJavascript.toString(); 146 } 147 } | Popular Tags |