質問

GWTでTag Cloudを使用するためにTagCloud_0.4.jarを使用しています。次に、タグクラウド内のタグをクリックすると、そのイベントを処理するにはどうすればよいか、ユーザーがクラウドからタグを選択したときにRPC通話を行うにはどうすればよいですか?

ありがとう。

役に立ちましたか?

解決

クラウドでクリッケベントをキャッチする例を次に示します。しかし、これはライブラリが変わる可能性があるため、回避策です。 DevelopPerはクラウド上のイベントをタグで管理することを提供していないため、これはおそらく正当な理由です...

したがって、あなた自身の責任でこのコードを使用してください。ウィジェットの構造DOMの変更がないために祈ります。そのようなイベントの管理など、Widgetのいくつかの強化を開発者に尋ねることをお勧めします。

    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());
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top