Domanda

Sto usando tagcloud_0.4.jar per l'utilizzo di Tag Cloud in GWT. Ora, quando si fa clic su un tag all'interno del tag cloud, allora come posso gestire tale evento o come posso fare chiamata RPC quando l'utente selezionare un tag da nuvole?

Grazie.

È stato utile?

Soluzione

Ecco un esempio di prendere un ClickEvent sulla nuvola. Ma questa è una soluzione come la biblioteca può cambiare. Come il developper non offrono per gestire gli eventi sulla nuvola né su tag, questo è forse per una buona ragione ...

Quindi, utilizzare questo codice a proprio rischio. Pregate per nessun cambiamento della struttura DOM del widget. Vi suggerisco di chiedere al developper alcuni miglioramenti sui suoi widget, come la gestione di tali eventi.

    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());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top