我该如何判断GXT会触发哪些事件? [英] How can I tell what events fire from GXT?

查看:73
本文介绍了我该如何判断GXT会触发哪些事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到有关在GXT中触发什么事件以及何时触发事件的任何文档.

I cannot seem to find any documentation of what events fire and when in GXT.

API文档包含所有可能触发的事件的列表(在Events中).它描述了如何处理您捕获的事件.但是我对另一面感兴趣,当我采取某种行动时会触发哪些事件.

The API docs have lists of all the events that could fire (in Events). And it describes how to handle events that you catch. But I'm interested in the opposite side, which events are fired when I take a certain action.

我可以为各种不同的组件设置一些侦听器,或者可以将addListener与特定的事件代码一起使用以捕获单个事件.那是参差不齐的,而且我似乎正在使用反复试验来猜测我可能想要抓住的东西.

I can set some listeners for various different components, or I can use addListener with a specific event code to catch individual events. That's spotty, and I seem to be using trial-and-error to guess what I might want to catch.

是否有办法记录所有正在触发的事件?还是抓住所有这些,以便我可以在调试器中查看它们?

Is there a way to log all the events that are firing? Or catch all of them so I could look at them in a debugger?

还是我缺少一些包含该信息的文档?类似于当您单击小部件时,会触发ButtonEvent.在悬停时会触发Events.x,在点击时会触发Events.y."

Or is there some documentation I am missing that has the information? Something along the lines of "when you click on a widget, a ButtonEvent is fired. Events.x is fired on the hover, Events.y on the click."

推荐答案

我最终使用了蛮力:创建了EventType和名称的Map,然后为组件可以接收的每种事件类型附加了一个Listener.然后,我只在侦听器中设置一个断点,就可以看到发生任何事件时接收到了什么事件.

I ended up using brute force: Created a Map of EventType and name, then attach a Listener for each type of event that the component could receive. Then I just set a breakpoint inside the Listener, and I could see what events were received when anything happened.

如果没有被丢弃的代码,我会将其清理为实用程序类,而不使用匿名的Listener类,等等.

If it hadn't been throwaway code, I would have cleaned it up into a utility class, not used an anonymous Listener class, etc.

    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();
            }
        });
    }

这篇关于我该如何判断GXT会触发哪些事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆