GWT Cell Widgets和双击行为

时间:2012-01-19 11:51:40

标签: gwt click cell double-click

我有一个处理“click”和“dblclick”的Cell。 点击的一种行为,dblclick的不同行为。

双击单元格时会触发3个事件。

单击,单击和dblclick。

有没有办法过滤“点击”事件?

举个例子:

...
public TestCell(EventBus eventBus){
        super("click","keydown", "dblclick");
}

...

public onBrowserEvent( ... ){
   String eventType = event.getType();
   if("click".equals(eventType)){
     //do smthg.
   }
   if("dblclick".equals(eventType)){
     //do smthg different.
   }
} 

三江源。

2 个答案:

答案 0 :(得分:1)

private int clickCount = 0;

public void onBrowserEvent(Event event) { 
  switch (DOM.eventGetType(event)) { 
    case Event.ONCLICK: 
      clickCount++; 
      if (clickCount == 1) {
        Timer timer = new Timer() {
          @Override
          public void run() {
            onClickAction();
          }
        }
        timer.schedule(200);
      }
      break; 

    case Event.ONDBLCLICK:   
      // your handler code here     
      break;
  }
} 

private void onClickAction() {
  if (clickCount == 1) {
    // Do single click actions
  } // If clickCount > 1, don't perform single click operation.
  clickCount = 0;
}

案例单击:

  1. click -> clickCount = 1.
  2. set timer to fire onClick action after 200ms.
  3. 200ms elapse, onClickAction() fires.
  4. clickCount = 1, perform single click actions.
  5. reset clickCount = 0.

案例双击

  1. click -> clickCount = 1.
  2. set timer to fire onClick action after 200ms.
  3. click -> clickCount = 2. No timer set.
  4  200ms elapses from first click. Timer fires onClickAction.
  5. clickCount > 1, actions for single click not performed.
  6. reset clickCount = 0.

答案 1 :(得分:0)

...如果你不想处理dblclick,你就不明白为什么GWT /浏览器只给你一次点击...

正如@ adel-boutros所说,这就是它应该如何工作,你必须忍受它。

检查event.detail的点击次数。不幸的是,你必须使用JSNI,因为GWT似乎没有公开Java中的字段。