我似乎无法找到任何关于什么事件的文件以及在GXT中的时间。
API文档包含可以触发的所有事件的列表(在Events
中)。它描述了如何处理您捕获的事件。但我对相反的一方感兴趣,当我采取某种行动时会发生哪些事件。
我可以为各种不同的组件设置一些监听器,或者我可以使用addListener
和特定的事件代码来捕获单个事件。这很不稳定,而我似乎正在使用反复试验来猜测我可能想要捕获的内容。
有没有办法记录所有被解雇的事件?或者抓住所有这些,以便我可以在调试器中查看它们?
或者是否有一些我遗漏的文件有信息? “当你点击一个小部件时,ButtonEvent
会被触发。Events.x
会在点击时点击悬停Events.y
。”
答案 0 :(得分:12)
也许有人会觉得这很有用,我已经创建了实用工具类来查看上升的事件类型。当然的想法是在接受的答案中提出的。
import java.util.HashMap;
import java.util.Map;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.Component;
/**
* Class for debugging purposes. Sometimes it is hard to tell what type of event
* is invoked and when. During debug process you can just do:
*
* EventUtils.attachDebugListeners(c);
* EventUtils.attachDebugListeners(c, "NAME");
*
* You'll then get information about events as they are invoked.
*
* List of events copied from {@link Events} class.
*
*/
public class EventUtils {
public static void attachDebugListeners(final Component c) {
attachDebugListeners(c, null);
}
public static void attachDebugListeners(final Component c, final String msg) {
for (final EventType type : eventTypeNames.keySet()) {
c.addListener(type, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
String typeName = eventTypeNames.get(type);
if (msg != null)
System.out.print(msg + " -> ");
System.out.println(typeName);
}
});
}
}
final static Map<EventType, String> eventTypeNames = new HashMap<EventType, String>();
static {
eventTypeNames.put(Events.Activate, "Events.Activate");
eventTypeNames.put(Events.Add, "Events.Add");
eventTypeNames.put(Events.Adopt, "Events.Adopt");
eventTypeNames.put(Events.AfterEdit, "Events.AfterEdit");
eventTypeNames.put(Events.AfterLayout, "Events.AfterLayout");
eventTypeNames.put(Events.ArrowClick, "Events.ArrowClick");
eventTypeNames.put(Events.Attach, "Events.Attach");
eventTypeNames.put(Events.AutoHide, "Events.AutoHide");
eventTypeNames.put(Events.BeforeAdd, "Events.BeforeAdd");
eventTypeNames.put(Events.BeforeAdopt, "Events.BeforeAdopt");
eventTypeNames.put(Events.BeforeBind, "Events.BeforeBind");
eventTypeNames.put(Events.BeforeCancelEdit, "Events.BeforeCancelEdit");
eventTypeNames.put(Events.BeforeChange, "Events.BeforeChange");
eventTypeNames
.put(Events.BeforeCheckChange, "Events.BeforeCheckChange");
eventTypeNames.put(Events.BeforeClose, "Events.BeforeClose");
eventTypeNames.put(Events.BeforeCollapse, "Events.BeforeCollapse");
eventTypeNames.put(Events.BeforeComplete, "Events.BeforeComplete");
eventTypeNames.put(Events.BeforeEdit, "Events.BeforeEdit");
eventTypeNames.put(Events.BeforeExpand, "Events.BeforeExpand");
eventTypeNames.put(Events.BeforeHide, "Events.BeforeHide");
eventTypeNames.put(Events.BeforeLayout, "Events.BeforeLayout");
eventTypeNames.put(Events.BeforeOpen, "Events.BeforeOpen");
eventTypeNames.put(Events.BeforeOrphan, "Events.BeforeOrphan");
eventTypeNames.put(Events.BeforeQuery, "Events.BeforeQuery");
eventTypeNames.put(Events.BeforeRemove, "Events.BeforeRemove");
eventTypeNames.put(Events.BeforeRender, "Events.BeforeRender");
eventTypeNames.put(Events.BeforeSelect, "Events.BeforeSelect");
eventTypeNames.put(Events.BeforeShow, "Events.BeforeShow");
eventTypeNames.put(Events.BeforeStartEdit, "Events.BeforeStartEdit");
eventTypeNames.put(Events.BeforeStateRestore,
"Events.BeforeStateRestore");
eventTypeNames.put(Events.BeforeStateSave, "Events.BeforeStateSave");
eventTypeNames.put(Events.BeforeSubmit, "Events.BeforeSubmit");
eventTypeNames.put(Events.Bind, "Events.Bind");
eventTypeNames.put(Events.Blur, "Events.Blur");
eventTypeNames.put(Events.BodyScroll, "Events.BodyScroll");
eventTypeNames.put(Events.BrowserEvent, "Events.BrowserEvent");
eventTypeNames.put(Events.CancelEdit, "Events.CancelEdit");
eventTypeNames.put(Events.CellClick, "Events.CellClick");
eventTypeNames.put(Events.CellDoubleClick, "Events.CellDoubleClick");
eventTypeNames.put(Events.CellMouseDown, "Events.CellMouseDown");
eventTypeNames.put(Events.CellMouseUp, "Events.CellMouseUp");
eventTypeNames.put(Events.Change, "Events.Change");
eventTypeNames.put(Events.CheckChange, "Events.CheckChange");
eventTypeNames.put(Events.CheckChanged, "Events.CheckChanged");
eventTypeNames.put(Events.Clear, "Events.Clear");
eventTypeNames.put(Events.Close, "Events.Close");
eventTypeNames.put(Events.Collapse, "Events.Collapse");
eventTypeNames.put(Events.ColumnClick, "Events.ColumnClick");
eventTypeNames.put(Events.ColumnResize, "Events.ColumnResize");
eventTypeNames.put(Events.Complete, "Events.Complete");
eventTypeNames.put(Events.ContextMenu, "Events.ContextMenu");
eventTypeNames.put(Events.Deactivate, "Events.Deactivate");
eventTypeNames.put(Events.Detach, "Events.Detach");
eventTypeNames.put(Events.Disable, "Events.Disable");
eventTypeNames.put(Events.DoubleClick, "Events.DoubleClick");
eventTypeNames.put(Events.DragCancel, "Events.DragCancel");
eventTypeNames.put(Events.DragEnd, "Events.DragEnd");
eventTypeNames.put(Events.DragEnter, "Events.DragEnter");
eventTypeNames.put(Events.DragFail, "Events.DragFail");
eventTypeNames.put(Events.DragLeave, "Events.DragLeave");
eventTypeNames.put(Events.DragMove, "Events.DragMove");
eventTypeNames.put(Events.DragStart, "Events.DragStart");
eventTypeNames.put(Events.Drop, "Events.Drop");
eventTypeNames.put(Events.EffectCancel, "Events.EffectCancel");
eventTypeNames.put(Events.EffectComplete, "Events.EffectComplete");
eventTypeNames.put(Events.EffectStart, "Events.EffectStart");
eventTypeNames.put(Events.Enable, "Events.Enable");
eventTypeNames.put(Events.Exception, "Events.Exception");
eventTypeNames.put(Events.Expand, "Events.Expand");
eventTypeNames.put(Events.Focus, "Events.Focus");
eventTypeNames.put(Events.HeaderChange, "Events.HeaderChange");
eventTypeNames.put(Events.HeaderClick, "Events.HeaderClick");
eventTypeNames
.put(Events.HeaderContextMenu, "Events.HeaderContextMenu");
eventTypeNames
.put(Events.HeaderDoubleClick, "Events.HeaderDoubleClick");
eventTypeNames.put(Events.HeaderMouseDown, "Events.HeaderMouseDown");
eventTypeNames.put(Events.HiddenChange, "Events.HiddenChange");
eventTypeNames.put(Events.Hide, "Events.Hide");
eventTypeNames.put(Events.Invalid, "Events.Invalid");
eventTypeNames.put(Events.KeyDown, "Events.KeyDown");
eventTypeNames.put(Events.KeyPress, "Events.KeyPress");
eventTypeNames.put(Events.KeyUp, "Events.KeyUp");
eventTypeNames.put(Events.LiveGridViewUpdate,
"Events.LiveGridViewUpdate");
eventTypeNames.put(Events.Maximize, "Events.Maximize");
eventTypeNames.put(Events.MenuHide, "Events.MenuHide");
eventTypeNames.put(Events.MenuShow, "Events.MenuShow");
eventTypeNames.put(Events.Minimize, "Events.Minimize");
eventTypeNames.put(Events.Move, "Events.Move");
eventTypeNames.put(Events.OnBlur, "Events.OnBlur");
eventTypeNames.put(Events.OnChange, "Events.OnChange");
eventTypeNames.put(Events.OnClick, "Events.OnClick");
eventTypeNames.put(Events.OnContextMenu, "Events.OnContextMenu");
eventTypeNames.put(Events.OnDoubleClick, "Events.OnDoubleClick");
eventTypeNames.put(Events.OnError, "Events.OnError");
eventTypeNames.put(Events.OnFocus, "Events.OnFocus");
eventTypeNames.put(Events.OnKeyDown, "Events.OnKeyDown");
eventTypeNames.put(Events.OnKeyPress, "Events.OnKeyPress");
eventTypeNames.put(Events.OnKeyUp, "Events.OnKeyUp");
eventTypeNames.put(Events.OnLoad, "Events.OnLoad");
eventTypeNames.put(Events.OnLoseCapture, "Events.OnLoseCapture");
eventTypeNames.put(Events.OnMouseDown, "Events.OnMouseDown");
eventTypeNames.put(Events.OnMouseMove, "Events.OnMouseMove");
eventTypeNames.put(Events.OnMouseOut, "Events.OnMouseOut");
eventTypeNames.put(Events.OnMouseOver, "Events.OnMouseOver");
eventTypeNames.put(Events.OnMouseUp, "Events.OnMouseUp");
eventTypeNames.put(Events.OnMouseWheel, "Events.OnMouseWheel");
eventTypeNames.put(Events.OnScroll, "Events.OnScroll");
eventTypeNames.put(Events.Open, "Events.Open");
eventTypeNames.put(Events.Orphan, "Events.Orphan");
eventTypeNames.put(Events.Ready, "Events.Ready");
eventTypeNames.put(Events.Refresh, "Events.Refresh");
eventTypeNames.put(Events.Register, "Events.Register");
eventTypeNames.put(Events.Remove, "Events.Remove");
eventTypeNames.put(Events.Render, "Events.Render");
eventTypeNames.put(Events.Resize, "Events.Resize");
eventTypeNames.put(Events.ResizeEnd, "Events.ResizeEnd");
eventTypeNames.put(Events.ResizeStart, "Events.ResizeStart");
eventTypeNames.put(Events.Restore, "Events.Restore");
eventTypeNames.put(Events.RowClick, "Events.RowClick");
eventTypeNames.put(Events.RowDoubleClick, "Events.RowDoubleClick");
eventTypeNames.put(Events.RowMouseDown, "Events.RowMouseDown");
eventTypeNames.put(Events.RowMouseUp, "Events.RowMouseUp");
eventTypeNames.put(Events.RowUpdated, "Events.RowUpdated");
eventTypeNames.put(Events.Scroll, "Events.Scroll");
eventTypeNames.put(Events.Select, "Events.Select");
eventTypeNames.put(Events.SelectionChange, "Events.SelectionChange");
eventTypeNames.put(Events.Show, "Events.Show");
eventTypeNames.put(Events.SortChange, "Events.SortChange");
eventTypeNames.put(Events.SpecialKey, "Events.SpecialKey");
eventTypeNames.put(Events.StartEdit, "Events.StartEdit");
eventTypeNames.put(Events.StateChange, "Events.StateChange");
eventTypeNames.put(Events.StateRestore, "Events.StateRestore");
eventTypeNames.put(Events.StateSave, "Events.StateSave");
eventTypeNames.put(Events.Submit, "Events.Submit");
eventTypeNames.put(Events.Toggle, "Events.Toggle");
eventTypeNames.put(Events.TriggerClick, "Events.TriggerClick");
eventTypeNames.put(Events.TwinTriggerClick, "Events.TwinTriggerClick");
eventTypeNames.put(Events.UnBind, "Events.UnBind");
eventTypeNames.put(Events.Unregister, "Events.Unregister");
eventTypeNames.put(Events.Update, "Events.Update");
eventTypeNames.put(Events.Valid, "Events.Valid");
eventTypeNames.put(Events.ValidateDrop, "Events.ValidateDrop");
eventTypeNames.put(Events.ValidateEdit, "Events.ValidateEdit");
eventTypeNames.put(Events.ViewReady, "Events.ViewReady");
}
}
答案 1 :(得分:8)
我最终使用暴力:创建了一个EventType和name的Map,然后为组件可以接收的每种类型的事件附加一个Listener。然后我只在Listener中设置一个断点,我可以看到发生了什么事件。
如果它不是一次性代码,我会把它清理成实用程序类,而不是使用匿名监听器类等。
final Map<EventType, String> eventTypeNames = new HashMap<EventType, String>();
eventTypeNames.put(Events.BeforeExpand, "BeforeExpand");
eventTypeNames.put(Events.Expand, "Expand");
...
eventTypeNames.put(Events.BeforeStateSave, "BeforeStateSave");
eventTypeNames.put(Events.StateSave, "StateSave");
for (EventType eventType : Arrays.asList(
Events.BeforeExpand,
Events.Expand,
...
Events.BeforeStateSave,
Events.StateSave
)) {
this.addListener(eventType, new Listener<BaseEvent>() {
public void handleEvent(final BaseEvent be) {
String type = eventTypeNames.get(be.getType());
String ev = be.toString();
}
});
}
答案 2 :(得分:5)
各种小部件的API文档描述了将触发的事件以及触发的时间。例如,假设我们希望在用户选择TabItem
中的新TabPanel
时执行操作。
TabPanel
的API文档(位于http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/TabPanel.html)显示了几个事件;我们对Select
:
选择:TabPanelEvent(容器,项目)
选择项目后触发。
- 容器:这个
- item:已选择的项目
因此,为了捕获事件(它看起来你理解,但我将包括完整性),过程是向TabPanel
添加一个监听器,专门观察Events.Select
事件:
tp.addListener(Events.Select, new Listener<TabPanelEvent>(){
public void handleEvent(TabPanelEvent be)
{
MessageBox.alert("Test", be.item.getText(), null);
}
});
请注意,许多事件都有一个名为doit
的属性,您可以将其设置为false以取消该事件。
完整的代码清单:
package edu.fresno.client;
import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TabPanelEvent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
public class GWTSandbox implements EntryPoint {
public void onModuleLoad() {
TabPanel tp = new TabPanel();
TabItem ti1 = new TabItem("TabItem1");
TabItem ti2 = new TabItem("TabItem2");
tp.add(ti1);
tp.add(ti2);
tp.addListener(Events.Select, new Listener<TabPanelEvent>(){
public void handleEvent(TabPanelEvent be)
{
MessageBox.alert("Test", be.item.getText(), null);
}
});
ContentPanel panel = new ContentPanel();
panel.setLayout(new FitLayout());
panel.add(tp);
RootPanel.get().add(panel);
}
}
答案 3 :(得分:3)
您可以为构造函数添加以下代码:
ContentPanel panel =new ContentPanel(){
public boolean fireEvent(EventType type) {
System.out.println(type.getEventCode());
return super.fireEvent(type);
}
public boolean fireEvent(EventType eventType, BaseEvent be) {
System.out.println(eventType.getEventCode());
return super.fireEvent(eventType, be);
}
public boolean fireEvent(EventType type, ComponentEvent ce) {
System.out.println(type.getEventCode());
return super.fireEvent(type, ce);
}
};
然后它将打印此组件可以接收的任何事件。