Integrating GWT-EXT - ToolTip

Hi again,

I decided to create a new topic to be more specific, the component I’m trying to integrate now is the ToolTip: http://gwt-ext.com/demo/#tooltips

But I am already facing some problems. To use this ToolTip you need to pass it a parameter in the method “applyTo()” that corresponds to the component it will be anchored, and this parameter can be:
1 - com.google.gwt.user.client.Element
2 - java.lang.String elementID
3 - com.gwtext.client.widgets.Component (discarded)

I was searching in the ITMill API how could I get any of this informations from an ITMill class like: com.itmill.toolkit.ui.AbstractComponent, but I found nothing.

Do you know how could I get this information?

You should do that on client-side. Each widget on the widget set has getElement() that returns com.google.gwt.user.client.Element.

My guess is that the problem that you are facing is that the tooltip is more like a feature of each component than component itself? So there is no point in creating just a tooltip, but you need a context for it to appear in. Could you the API you are trying to create so that I could help you better.

BTW: If you are porting Tooltips just because they look simple excercise, I would suggest to start with an easier widget (that is more self-contained). Especially when the tooltips are already implemented in IT Mill Toolkit.

I understood that, but how could I get the widget in the client side when an ITMill component was passed to the ToolTip in the server-side?

Assuming I understand what you’re trying to do, I’d say that’s not possible (not easily right now, anyway): you can not pass a “reference” to another component from the server to the client, because the components do not have an ID that could be used as reference client-side.

Not having component id:s is a decision made a long time ago, but perhaps we should revisit the subject again - or look into some other way to pass component references to the client…

//Marc

Hi!

This sounds to me that the feature you need here is kind of inter component communication on client side. Although toolkit is server side framework, we have noticed the need for this kind of things. Especially if you are making your own custom components where you are trying to optimize the last milliseconds by avoiding server round trip.

One could do this by building some hacks, but this really ought to be much simpler. Inspired by your messages I pushed this planned feature forward a bit. In next nightly build PaintTarget has a new method called paintReference that can be used to add reference identifiers to UIDL messages.

A simple example code is below (both server and client components without imports)



public class ICollapseButton extends Button implements Paintable {

    private ApplicationConnection client;
    private String collapsedComponentId;

    public ICollapseButton() {
        addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                if (collapsedComponentId == null || client == null) {
                    return;
                }

                Widget w = (Widget) client.getPaintable(collapsedComponentId);
                w.setVisible(!w.isVisible());

            }
        });

    }

    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
        this.client = client;
        collapsedComponentId = uidl.getStringAttribute("cc");
        setText(uidl.getStringAttribute("caption"));
    }

}


public class CollapseButton extends Button {

    private Component component;

    public String getTag() {
        return "cbutton";
    }

    public CollapseButton(String caption) {
        super(caption);
    }

    public void setComponentToBeCollapsed(Component c) {
        component = c;
    }

    public void paintContent(PaintTarget target) throws PaintException {
        super.paintContent(target);
        target.paintReference(component, "cc");
    }

}

BTW. This method might require to build your stuff with DeferredCommand. The referenced component does not necessary exist at the time you are doing you logic (render phase).