2010-12-02 13 views
0

私はGWTでタグクラウドを使用するためにtagcloud_0.4.jarを使用しています。今、タグクラウド内の任意のタグをクリックすると、そのイベントをどのように処理できますか、またはユーザーがクラウドから任意のタグを選択したときにRPC呼び出しを行う方法はありますか?GWTクラウドでClickイベントや他のイベントを処理する方法は?

ありがとうございました。

答えて

0

ここでは、クラウド上でClickEventをキャッチする例を示します。しかし、これはライブラリが変更される可能性のある回避策です。デベロッパーはタグでもなくクラウド上のイベントも管理しないので、これはおそらく理由があります。

このコードは、自己責任で使用してください。ウィジェットの構造DOMを変更しないように祈ってください。デベロッパーに、そのようなイベントの管理など、ウィジェットのいくつかの機能強化を依頼することをお勧めします。

final TagCloud cloud = new TagCloud(); 

    cloud.addWord(new WordTag("AAA")); 
    cloud.addWord(new WordTag("AAA")); 
    cloud.addWord(new WordTag("BBB")); 
    cloud.addWord(new WordTag("CCC")); 
    cloud.addWord(new WordTag("CCC")); 
    cloud.addWord(new WordTag("CCC")); 

    cloud.addDomHandler(new ClickHandler() { 
     @Override 
     public void onClick(ClickEvent event) { 
      // Prevent the click from the tag to be executed 
      event.preventDefault(); 

      Element e; 
      // For each tag present in the cloud, look for the one that is triggered 
      for (int i = 0; i < cloud.getTags().size(); ++i) { 
       // Gets the element in the cloud, this really is the unsafe part of the code 
       // if the developer change the dom of its widget 
       e = DOM.getChild(DOM.getChild(cloud.getElement(), 0), i); 
       // Is the current element targeted by the event? 
       if (event.getClientX() >= e.getOffsetLeft() && event.getClientY() >= e.getOffsetTop() 
         && event.getClientX() <= e.getOffsetLeft() + e.getOffsetWidth() 
         && event.getClientY() <= e.getOffsetTop() + e.getOffsetHeight()) { 
        // Gets the abstract tag 
        Tag t = cloud.getTags().get(i); 
        // Gets tag descendant 
        if (t instanceof WordTag) { 
         // Do what you want with your WordTag, maybe an RPC call 
        } else if (t instanceof ImageTag) { 
         // Do what you want with your ImageTag, maybe an RPC call 
        } 

        break; 
       } 
      } 
     } 
    }, ClickEvent.getType()); 
関連する問題