转GWTEXT中增加tool的控制
转自这个文章
http://code.google.com/p/gwt-ext/issues/detail?id=406
Added a new Interface that implementors should implement the onClick event. This
event does pass the necessary information to the Tool.
The new interface is ToolHandler and the signature of the onclick event is:
public void onClick(EventObject e, ExtElement toolEl, Panel panel);
With this, now the you can change the icon and toggle it as it is the case of
pin/unpin.
Here is an example of how to change the pin/unpin icon when using ToolHandler:
public class myToolHandler implements ToolHandler{ boolean pin = false; ExtElement ele = null; public void setElement(){ EventManager.addListener(ele.getDOM(), "mouseover", new EventCallback(){ public void execute(EventObject e) { if(pin){ ele.removeClass("x-tool-unpin-over"); ele.addClassOnOver("x-tool-pin-over"); }else{ ele.removeClass("x-tool-pin-over"); ele.addClassOnOver("x-tool-unpin-over"); } } }, new ListenerConfig(){ { setStopEvent(true); } }); } public void onClick(EventObject e, ExtElement toolEl, Panel panel) { if(pin){ Ext.fly(toolEl.getDOM()).replaceClass("x-tool x-tool-pin", "x-tool x-tool-unpin"); }else{ Ext.fly(toolEl.getDOM()).replaceClass("x-tool x-tool-unpin", "x-tool x-tool-pin"); } pin = !pin; if(ele == null){ ele = toolEl; setElement(); } }}