Question

J'utilise tagcloud_0.4.jar pour utiliser Tag Cloud GWT. Maintenant, quand je clique sur une étiquette à l'intérieur du nuage de tags, alors comment puis-je gérer cet événement ou comment puis-je faire appel RPC lorsque l'utilisateur sélectionner une balise de nuage?

Merci.

Était-ce utile?

La solution

Voici un exemple pour attraper un ClickEvent sur le nuage. Mais ceci est une solution que la bibliothèque peut changer. En tant que developpeur ne proposent pas de gérer les événements sur le nuage ni sur les étiquettes, c'est peut-être pour une bonne raison ...

Alors utilisez ce code à vos propres risques. Priez pour aucun changement de la structure du widget de DOM. Je vous suggère de demander quelques améliorations au developpeur sur ses widgets, comme la gestion de tels événements.

    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());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top