1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import java.util.HashMap ; 21 import java.util.Vector ; 22 import org.apache.log4j.Logger; 23 import org.objectweb.jac.aspects.gui.*; 24 25 public abstract class AbstractMenu extends AbstractView 26 implements MenuView, HTMLViewer, MenuListener 27 { 28 static Logger logger = Logger.getLogger("gui.menu"); 29 static Logger loggerEvents = Logger.getLogger("gui.events"); 30 31 HashMap map = new HashMap (); 33 Vector keys = new Vector (); 35 36 public AbstractMenu(ViewFactory factory, DisplayContext context) { 37 super(factory,context); 38 } 39 40 42 public void addSubMenu(String label, String icon, MenuView submenu) { 43 if (!map.containsKey(label)) { 44 logger.debug(this+".addSubMenu "+label+" -> "+submenu); 45 keys.add(label); 46 map.put(label,submenu); 47 } 48 } 49 50 public void addAction(String label, String icon, Callback callback) { 51 if (!map.containsKey(label)) { 52 logger.debug(this+".addAction "+label+" -> "+callback); 53 keys.add(label); 54 map.put(label,new MenuItem(label,icon,callback)); 55 } 56 } 57 58 public void addSeparator() { 59 } 60 61 String position = org.objectweb.jac.aspects.gui.Menu.LEFT; 62 63 67 public String getPosition() { 68 return position; 69 } 70 71 75 public void setPosition(String v) { 76 this.position = v; 77 if (position==null) 78 position = org.objectweb.jac.aspects.gui.Menu.LEFT; 79 } 80 81 83 public void onMenuClick(String key) { 84 try { 85 loggerEvents.debug(this+".onMenuClick `"+key+"'"); 86 MenuItem item = (MenuItem)map.get(key); 87 if (item!=null && item.callback!=null) 88 EventHandler.get().onInvoke( 89 context, 90 new InvokeEvent(this, 91 item.callback.getObject(), 92 item.callback.getMethod(), 93 item.callback.getParameters()), 94 true, 95 null,null); 96 else { 97 loggerEvents.debug(" No item("+item+") or callback("+ 98 (item==null?"":""+item.callback)+") is null"); 99 context.getDisplay().refresh(); 100 } 101 } catch (Exception e) { 102 context.getDisplay().showError("Menu error","onMenuClick "+key+": "+ 103 e.toString()+"<br><pre>"+map+"</pre>"); 104 logger.error("onMenuClick "+key,e); 105 } 106 } 107 } 108 | Popular Tags |