Pregunta

Estoy utilizando tagcloud_0.4.jar para el uso de la nube de etiquetas en GWT. Ahora, cuando hago clic en cualquier etiqueta dentro de la nube de etiquetas, entonces, ¿cómo puedo manejar ese evento o cómo puedo hacer llamada RPC cuando el usuario seleccione cualquier etiqueta de la nube?

Gracias.

¿Fue útil?

Solución

Este es un ejemplo para coger un ClickEvent en la nube. Pero esto es una solución como la biblioteca puede cambiar. A medida que el revelador no ofrecen para gestionar eventos en la nube ni en las etiquetas, esto es tal vez por una buena razón ...

Así que utilice este código a su propio riesgo. Ore por ningún cambio de la estructura del DOM del widget. Le sugiero que preguntar a la developper algunas mejoras en sus widgets, como la gestión de este tipo de eventos.

    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());
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top