Help!

50 views
Skip to first unread message

Thomas Lefort

unread,
Aug 4, 2011, 9:45:14 AM8/4/11
to Google Web Toolkit
If anybody can help, I am really pulling my hairs...

I am on my last bit of my jsni integration with maps v3. I want a
widget to appear in an infowindow. The widget has buttons and links.
All elements appear fine in the infowindow except that none of the
links, buttons work anymore.

This is what I do:

public native void openInfoWindowWidget(EOLatLng markerPosition,
Element element) /*-{
var myElement = element;

$wnd.mapsJSNI.openInfoWindowWidget(markerPosition.@com.metaaps.webapps.earthimages.shared.domain.EOLatLng::lat,
markerPosition.@com.metaaps.webapps.earthimages.shared.domain.EOLatLng::lng,
myElement);
}-*/;

public final void openPropertiesWindow(EOLatLng currentCoordinate,
List<Property> properties, PropertiesChange callBack) {
FlowPanel panel = new FlowPanel();
openInfoWindowWidget(currentCoordinate, panel.getElement());
panel.add(propertiesEditor);
}


propertiesEditor is my widget, it's a field. I am adding the flowpanel
in between to avoid a call to getElement on the widget itself.

I would really appreciate any ideas!!!

Thanks

Juan Pablo Gardella

unread,
Aug 4, 2011, 10:01:44 AM8/4/11
to google-we...@googlegroups.com
Are you debbug with firebug or similar to see the error?

2011/8/4 Thomas Lefort <lefor...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Thomas Lefort

unread,
Aug 4, 2011, 10:06:30 AM8/4/11
to Google Web Toolkit
I am debugging with firefox but I do not see any error. It's more like
all handlers have been wiped out, when I click on a link it doesn't do
anything anymore. If I try the exact same widget by adding it to
another widget or via uibinder all the links and buttons work fine.



On Aug 4, 4:01 pm, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> Are you debbug with firebug or similar to see the error?
>
> 2011/8/4 Thomas Lefort <lefortho...@gmail.com>
>
>
>
>
>
>
>
> > If anybody can help, I am really pulling my hairs...
>
> > I am on my last bit of my jsni integration with maps v3. I want a
> > widget to appear in an infowindow. The widget has buttons and links.
> > All elements appear fine in the infowindow except that none of the
> > links, buttons work anymore.
>
> > This is what I do:
>
> > public native void openInfoWindowWidget(EOLatLng markerPosition,
> > Element element) /*-{
> >                var myElement = element;
>
> > $wnd.mapsJSNI.openInfoWindowWidget(markerPositi...@com.metaaps.webapps.earthimages.shared.domain.EOLatLng
> > ::lat,
> > markerPositi...@com.metaaps.webapps.earthimages.shared.domain.EOLatLng

John Ho

unread,
Aug 4, 2011, 10:40:09 AM8/4/11
to google-we...@googlegroups.com
Because you are passing an Element, any handlers that were added to your Widget do not get passed along. To get around this, you will need to create a native JSNI function for your buttons and links.

Example:

yourButton.getElement().setPropertyJSO("onclick", yourClickFunction);

Where yourClickFunction is defined in JSNI.

Thomas Lefort

unread,
Aug 4, 2011, 11:05:10 AM8/4/11
to Google Web Toolkit
You are right and this is why I pass a flow panel first as an element
and then I add the widget itself to the flow panel using
FlowPanel.add(widget). I could get that to work on a "normal" div that
I had in my HTML file but with the map infoWindow it just won't work
and I really can't see the difference.


On Aug 4, 4:40 pm, John Ho <jzho...@gmail.com> wrote:
> Because you are passing an Element, any handlers that were added to your
> Widget do not get passed along. To get around this, you will need to create
> a native JSNI function for your buttons and links.
>
> Example:
>
> yourButton.getElement().setPropertyJSO("onclick", yourClickFunction);
>
> Where yourClickFunction is defined in JSNI.
>

Thomas Lefort

unread,
Aug 4, 2011, 4:40:13 PM8/4/11
to Google Web Toolkit
I have been through the v2 map jsni library and I am struggling to
understand the difference.
On the other hand I really stripped it down to teh bare minimum and I
am now just adding a button. The button appears in the bubble but the
click event is never triggered...

John Ho

unread,
Aug 4, 2011, 5:06:34 PM8/4/11
to google-we...@googlegroups.com
Even though you are creating a new FlowPanel and adding your propertiesEditor widget after passing it into the popup, it still doesn't matter because you are passing the panel as an Element in your openInfoWindowWidget method.

But to elaborate on the approach I mentioned, try this as an example:

public class YourPanel extends Composite {
JavaScriptObject clickFunction;

{
createJSNIBridge();
}

public YourPanel() {
Button button = new Button("Button");
button.getElement().setPropertyJSO("onclick", clickFunction);

FlowPanel panel = new FlowPanel();
panel.add(button);
initWidget(panel);
}

native void createJSNIBridge()/*-{
this.@your.package.location.YourPanel::clickFunction = function() {
alert("Clicked!");
}
}-*/;
}

And then call openInfoWindowWidget(currentCoordinate, new YourPanel().getElement()); 

Thomas Lefort

unread,
Aug 5, 2011, 4:06:32 AM8/5/11
to Google Web Toolkit
Hi John,

Thanks again for your help and patience.

The problem I have is that my widget is really quite a complex one,
with in place field edits, help links etc... I really cannot
reimplement, or bridge, every one handler of my widget, that's just
not possible.

There are two things that really puzzle me:
- what exactly is going on? why do I loose all handlers when passing
it as an element? I have not found much documentation on that.
- how come it works when I use the map v2 infoWindow from the google
gwt map library? There has to be some kind of trick.

Cheers


On Aug 4, 11:06 pm, John Ho <jzho...@gmail.com> wrote:
> Even though you are creating a new FlowPanel and adding your
> propertiesEditor widget after passing it into the popup, it still doesn't
> matter because you are passing the panel as an Element in your openInfoWindowWidget
> method.
>
> But to elaborate on the approach I mentioned, try this as an example:
>
> public class YourPanel extends Composite {
> JavaScriptObject clickFunction;
>
> {
> createJSNIBridge();
>
> }
>
> public YourPanel() {
> Button button = new Button("Button");
> button.getElement().setPropertyJSO("onclick", clickFunction);
>
> FlowPanel panel = new FlowPanel();
> panel.add(button);
> initWidget(panel);
>
> }
>
> native void createJSNIBridge()/*-{
> th...@your.package.location.YourPanel::clickFunction = function() {

Thomas Lefort

unread,
Aug 5, 2011, 4:35:24 AM8/5/11
to Google Web Toolkit
Okaaaaay now I have it working, the trick is in this StackOverflow
post:

http://stackoverflow.com/questions/6183181/how-to-add-a-custom-widget-to-an-element

So in the end I did the following

in my jsni function

var newDiv = $doc.createElement('div');

the function returns the div as an Element which I in turn wrap in an
HTMLPanel using HTMLPanel.wrap and then I add the widget!

JHM

unread,
Aug 27, 2011, 2:46:57 PM8/27/11
to Google Web Toolkit
Hello,

I am using com.googlecode.maps3 to get Maps V3
into GWT, and InfoWindows through this library have
worked well so far. Here is a smippet of code for setting
up an InfoWindow (JSO == JavaScriptObject):

import com.googlecode.maps3.client.MapWidget;
import com.googlecode.maps3.client.MapJSO;
import com.googlecode.maps3.client.LatLng;
import com.googlecode.maps3.client.InfoWindowJSO;

void startInfoWindow(ContentRecord record, LatLng center)
{
HTML contentHTML = new HTML();
InfoWindowJSO infoWindow = InfoWindowJSO.newInstance();
infoWindow.setContent(contentHTML.getElement());

contentHTML.setHTML(formatRecord(contentRecord));
infoWindow.setPosition(center);
infoWindow.open(mapWidget.getMapJSO());
}


On Aug 4, 6:45 am, Thomas Lefort <lefortho...@gmail.com> wrote:
> If anybody can help, I am really pulling my hairs...
>
> I am on my last bit of my jsni integration withmapsv3. I want a
> widget to appear in an infowindow. The widget has buttons and links.
> All elements appear fine in the infowindow except that none of the
> links, buttons work anymore.
>
> This is what I do:
>
> public native void openInfoWindowWidget(EOLatLng markerPosition,
> Element element) /*-{
>                 var myElement = element;
>
> $wnd.mapsJSNI.openInfoWindowWidget(markerPositi...@com.metaaps.webapps.earthimages.shared.domain.EOLatLng::lat,
> markerPositi...@com.metaaps.webapps.earthimages.shared.domain.EOLatLng::lng,
Reply all
Reply to author
Forward
0 new messages