GWT maps v3 click handler does not work in InfoWindow - gwt

GWT maps v2 InfoWindow had InfoWindowContent. GWT maps v3 InfoWindow doesn't have InfoWindowContent. I have found this code, but the click handler is not working:
InfoWindow info = new InfoWindow();
VerticalPanel verticalPanel = new VerticalPanel();
Label addressLabel = new Label("Address: " + address);
Label coordinatesLabel = new Label("Position: " + gLatLng.toUrlValue());
verticalPanel.add(addressLabel);
verticalPanel.add(coordinatesLabel);
HorizontalPanel horizontalPanel = new HorizontalPanel();
Button newAsociation = new Button("Add house");
Button deleteMarker = new Button("Delete");
newAsociation.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
System.out.println("Add house");
}
});
horizontalPanel.add(newAsociation);
horizontalPanel.add(deleteMarker);
verticalPanel.add(horizontalPanel);
info.setContent(verticalPanel.getElement().toString());
info.open(mapWidget.getMap(), marker);
How do I fix that?

If you are using maps v3 from gwt-google-apis you can find a solution here.

Related

How to create a toolbar inside viewpart (Not use plugin.xml)

I Created a ToolItem "Save As" like image above, But it not display at toolbar position. So how to create a toolbar inside viewpart (Not use plugin.xml)
IMAGE EXAMPLE
This is my code Create Toolbar:
public void createToolbar(Composite parent) {
// Create composite Toolbar and set layout
toolBarComposite = new Composite(parent, SWT.NONE);
gridLayout = new GridLayout(1, false);
toolBarComposite.setLayout(gridLayout);
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBarComposite.setLayoutData(gridData);
// Create Toolbar
gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
toolBar = new ToolBar(toolBarComposite, SWT.FLAT);
toolBar.setLayoutData(gridData);
// Create Item
item = new ToolItem(toolBar, SWT.PUSH);
item.setImage(SAVE_IMAGE);
item.setToolTipText("Save (Ctrl + S)");
item.setEnabled(true);
item.addSelectionListener(new SelectionAdapter() {
private static final long serialVersionUID = -102212312093090431L;
#Override
public void widgetSelected(SelectionEvent e) {
}
#Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
Thank for your advance !
You're going to have to use contributions on the view site's action bar.
Example
// Copy-pasted from an existing project, so the code can be made nicer
private void createAdditionalToolbarActions()
{
getViewSite().getActionBars().getToolBarManager().add(new GroupMarker("additions")); //$NON-NLS-1$
getViewSite().getActionBars().getToolBarManager().prependToGroup("additions", new SaveAction()); //$NON-NLS-1$
getViewSite().getActionBars().updateActionBars();
}
The method getViewSite is part of ViewPart. Call this after the contents of the view have been created.
The SaveAction must implement IAction or IContributionItem. For convenience, just extend the SaveAction from org.eclipse.jface.action.Action and call methods such as setImageDescriptor and setToolTipText.
Do all your business login in the run override.

GWT : Return VerticalPanel from a function in ClickHandler

I am trying to get a pop up when an image is clicked. below is the piece of code:
while(index<bookList.size()){
if(cellCount<4){
image[index] = new Image(imageList.get(index));
final int imageIndex = index;
table.setWidget(row, cellCount, new Image(bookList.get(index)));
table.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
VerticalPanel vPanel = new VerticalPanel();
vPanel = imageDetail.getPopup(popup, image[imageIndex]);
popup.setAnimationEnabled(true);
popup.setGlassEnabled(true);
popup.setAutoHideEnabled(false);
popup.setWidth("300px");
popup.setHeight("300px");
popup.add(vPanel);
popup.center();
}});
table.getFlexCellFormatter().setStyleName(row, cellCount, "ImageCell");
cellCount++;
index++;
}
Above code contain clickhandler which calls "getPopup" of imageDetail object. "getPopup" function returns a vertical Panel which is added to PopupPanel. ImageDetail class is as follows
public class ImageDetails extends Composite {
private Image closeButton;
VerticalPanel getPopup(final PopupPanel popup, Image image){
VerticalPanel vPanel = new VerticalPanel();
//Close Button
HorizontalPanel closePanel = new HorizontalPanel();
closeButton = new Image("/Images/closebutton.jpg");
closeButton.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
popup.hide();
}});
closePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
closePanel.add(closeButton);
vPanel.add(closePanel);
VerticalPanel imagePanel = new VerticalPanel();
imagePanel.add(image);
vPanel.add(imagePanel);
return vPanel;
}
My questions are as following :
1) Is it ok to return panels from a function? If no, then why? If yes, why above code gives "Uncaught exception escaped com.google.gwt.event.shared.UmbrellaException: 3 exceptions caught: null; null; null"?
2) When i try to add vertical panel to popup panel in "getPopup" function and get popup panel from there, code returning same error as mentioned in first question. What am I missing?
Am i missing any initWidget(w) function call?
Thank you

how to pop up calendar when button is clicked in Java SWT?

I am trying to develop Java SWT application in eclipse.
I need to populate text box using DateTime Calendar in SWT when a button is clicked.
I tried the following code but not able to see the Calendar, though it is created.
Any help would be appreciated.
Thanks
public void createPartControl(final Composite parent) {
Button button;
Label label;
final Display dev = parent.getDisplay();
Image image = new Image(dev,"C:\\Users\\rm186021\\Desktop\\Calendar.gif");
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
parent.setLayout(gridLayout);
label = new Label(parent, SWT.NULL);
label.setText("Start date ");
final Text start = new Text(parent, SWT.SINGLE | SWT.BORDER);
Button calButton = new Button(parent, SWT.PUSH);
calButton.setImage(image);
calButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
final Display display = new Display();
final Shell shell2 = new Shell(display);
shell2.addListener(SWT.CALENDAR, new Listener() {
public void handleEvent(Event event) {
final DateTime calendar = new DateTime(shell2,SWT.CALENDAR | SWT.POP_UP);
calendar.addSelectionListener (new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
start.setData(" " + calendar.getYear() + "-" + (calendar.getMonth() + 1) + "-" + calendar.getDay());
System.out.println(start.getData());
//calendar.dispose();
}
});
}
});
}
});
You're creating a Shell, but never even opening it. Try calling shell2.open().
You're adding an SWT.CALENDAR listener to the Shell. This isn't going to do what you want to do. Or anything, for that matter, since Shell doesn't fire SWT.CALENDAR events. Instead, you simply need to add the DateTime to a container and hook up selection listeners to the Calendar.
SWT.POP_UP is not an appropriate style bit for Calendar.
I would recommend subclassing Dialog (call it CalendarDialog, for example), setting a FillLayout on it, adding a Calendar to it and hooking up listeners that way. Then call CalendarDialog.open().
The DateTime really shouldn't be created with code like that :) Try this instead:
calButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
final Shell shell2 = new Shell(dev.getActiveShell());
// new Display() won't work on many platforms if one already exists
final DateTime calendar = new DateTime(shell2, SWT.CALENDAR);
// no need to add a listener to shell2, and POP_UP doesn't work for DateTime
calendar.addSelectionListener(...);
shell2.open();
// Edward Thomson noticed it wasn't called, I missed it
}
};

GWT Tab panel close

I am building an application in GWT. I have a decorated tabpanel in
my application.Where in am adding panels to it dynamically.Now i want
to achieve the closing of these tabs. I want to add a close image to
the tab bar and event to that image for closing. I am using UIbinder.
the working code is like that;
private Widget getTabTitle(final Widget widget, final String title) {
final HorizontalPanel hPanel = new HorizontalPanel();
final Label label = new Label(title);
DOM.setStyleAttribute(label.getElement(), "whiteSpace", "nowrap");
ImageAnchor closeBtn = new ImageAnchor();
closeBtn.setResource(images.cross());
closeBtn.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
int widgetIndex = tabs.getWidgetIndex(widget);
if (widgetIndex == tabs.getSelectedIndex()) {
tabs.selectTab(widgetIndex - 1);
}
tabs.remove(widgetIndex);
}
});
hPanel.add(label);
hPanel.add(new HTML("&nbsp&nbsp&nbsp"));
hPanel.add(closeBtn);
hPanel.setStyleName("gwt-TabLayoutPanelTab");
return hPanel;
}
In order to add tab,
public void addTab() {
TabWriting tw = new TabWriting(); /* TabWriting in my case, this can be any widget */
tabs.add(tw, getTabTitle(tw, "Writing"));
tabs.selectTab(tw);
}
You'll going to need, ImageAnchorClass
public class ImageAnchor extends Anchor {
public ImageAnchor() {
}
public void setResource(ImageResource imageResource) {
Image img = new Image(imageResource);
img.setStyleName("navbarimg");
DOM.insertBefore(getElement(), img.getElement(), DOM
.getFirstChild(getElement()));
}}
It isn't supported natively in GWT.
You can manually try to add it.
Read this - http://groups.google.com/group/google-web-toolkit/browse_thread/thread/006bc886c1ccf5e1?pli=1
I haven't tried it personally, but look at the solution by gregor (last one).
You kinda need to do something along the lines of this
GWT Close button in title bar of DialogBox
First you need to pass in the tab header when you create the new tab. The header you pass in should have your tab text and also an X image or text label to click on. Then add a event handler on the close object that gets the widget you are adding to the tabPanel and removes it. Here is some inline code that works
public void loadTab(final Widget widget, String headingText, String tooltip) {
HorizontalPanel panel = new HorizontalPanel();
panel.setStyleName("tabHeader");
panel.setTitle(tooltip);
Label text = new Label();
text.setText(headingText);
text.setStyleDependentName("text", true);
Label close = new Label();
close.setText("X");
close.setTitle(closeText_ + headingText);
text.setStyleDependentName("close", true);
close.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("close this tab");
ClientGlobal.LOG.info("widget : " + tabPanel_.getWidgetIndex(widget));
tabPanel_.remove(tabPanel_.getWidgetIndex(widget));
}
});
panel.add(text);
panel.add(close);
panel.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_LEFT);
panel.setCellHorizontalAlignment(close, HasHorizontalAlignment.ALIGN_RIGHT);
tabPanel_.add(widget, panel);
tabPanel_.getTabWidget(widget).setTitle(tooltip);
tabPanel_.selectTab(widget);
}

DOM.getElementById in GWT doesn't seem to work

I've the following code snippet:
myPanel.getElement().setId("left-content");
//...
//...
Element e = DOM.getElementById("left-content");// this returns NULL!
Update
Here is a longer code snippet:
public class RootComposite extends Composite
{
public RootComposite(int comboSelectedIndex)
{
VerticalPanel verticalPanel = new VerticalPanel();
initWidget(verticalPanel);
VerticalPanel containerPanel = new VerticalPanel();
containerPanel.setSpacing(1);
verticalPanel.add(containerPanel);
verticalPanel.setSize("100%", "100%");
RightPanelMainComposite rightPanelMainComposite = new RightPanelMainComposite();
VerticalPanel rightcolVerticalPanel = new VerticalPanel();
rightcolVerticalPanel.setStyleName("rightcol");
VerticalPanel searchVerticalPanel = new VerticalPanel();
searchVerticalPanel.setStyleName("search");
rightcolVerticalPanel.add(searchVerticalPanel);
searchVerticalPanel.add(rightPanelMainComposite);
ContentComposite contentComposite = new ContentComposite();
HorizontalPanel leftContentPanel = new HorizontalPanel();
containerPanel.add(leftContentPanel);
leftContentPanel.getElement().setAttribute("id", "left-content");
DOM.getElementById("left-content"); // returns NULL !!!
// ....
}
The above Composite is being added to the RootPanel.
You can use DOM.getElementById only if the requested widget is actually attached to the DOM.
Your code shows that you set the id in the constructor and request the correspondant element right after when the widget is not attached yet. Your widget is actually attached only when its onLoad method is called.
I assume, that you didn't add myPanel to the DOM (e.g. RootPanel.get().add(myPanel)) before calling DOM.getElementById("left-content").