Error in GWT MapWidget - gwt

I am trying to add MapWidget to VerticalPanel but the map added on the
left corner:
And I added marker and the marker should be centered on the image
I can't see the marker when I load the map. I should navigate to this
location to show map.
The code for this
private FormPanel form = new FormPanel();
private VerticalPanel main = new VerticalPanel();
public Map(){
ScrollPanel container = new ScrollPanel();
initWidget(container);
container.setStyleName("FuoEgForm");
form.setWidget(main);
main.setSpacing(6);
container.add(main);
}
public MapWidget addMapWidget(){
MapWidget map = new MapWidget();
//map.setSize("100%", "100%");
map.setStyleName("gwt-map");
map.removeMapType(MapType.getNormalMap());
map.removeMapType(MapType.getSatelliteMap());
map.addMapType(MapType.getPhysicalMap());
map.addMapType(MapType.getHybridMap());
map.setCurrentMapType(MapType.getHybridMap());
//map.setSize("100%", "100%");
map.setWidth("500px");
map.setHeight("500px");
main.add(map);
}
How can I solve this issue? The map should fill the gray
boundary?

As of gwt-maps-1.1, the MapWidget implements the RequiresResize interface. When added to a panel that supports this interface (such as DockLayoutPanel), the widget automatically calls map.checkResizeAndCenter() whenever the panel containing the widget is resized. This new feature makes it possible to set your map size to 100% in both directions and fill up the available space on the screen. To use LayoutPanel subclasses properly, make sure your html page is set to use standards mode by adding as the first line in the document.
In gwt-maps 1.0, it may be necessary to force the map to resize its layout after the map is initially added. you can use the MapWidget.checkResizeAndCenter() method to clean this up. You may need to delay calling this function using a DeferredCommand or other mechanism to wait until after the DOM layout pass that resizes the map is called.
or you can find unexpected another unexpected reason that happened with me
i made the map invisible #constructor
and then set it visible if clicked on a button
the solution
make the map always visible :)

I insert these line below the add(map) :
LatLng c = mapWidget.getCenter();
resizeMap(mapWidget.getMVCObject());
mapWidget.setCenter(c);

Related

View size not match with layoutPanel container in GWT MVP and SmartGWT

I'm new in GWT, and have problem with view implementation... I use MVP, and SmartGWT. I'll expose this by defining how I settle my MVP and what its weird.
In my onModule, I define class builded with UIbinder. I've declared a LayoutPanel and set it like this in the constructor of the class.
layoutPanel = binder.createAndBindUi(this);
I have container in this class:
public void setBodyLayout() {
panel.setWidgetLeftWidth(menuPanel, xx, PCT, xxx, PCT);
panel.setWidgetRightWidth(bodyPanel, xx, PCT, xx, PCT);
}
menuPanel and bodyPanel are both simplePanel declared in the class above(UIfield use with UIbinder). There are in LayoutPanel. For the method display of my ActivityMapper I've got this method (In reality I have two ActivityMappers, two method that like below and two containers, for menu and body)
public AcceptsOneWidget getBodyContainer() {
return new AcceptsOneWidget() {
#Override
public void setWidget(IsWidget w) {
Widget widget = Widget.asWidgetOrNull(w);
bodyPanel.setWidget(widget);
}
};}
return in my onModule, I declared my ActivityMapper like this
BodyActivityMapper bodyContainerActivityMapper = new BodyActivityMapper(clientFactory);
ActivityManager bodyContainerActivityManager = new ActivityManager(bodyContainerActivityMapper, eventBus);
bodyContainerActivityManager.setDisplay(my_class_described_above.getBodyContainer());
the same work was done with MenuActivityMapper...
Finally
RootLayoutPanel.get().add(my_class_described_above.getLayoutPanel());
when getLayoutPanel() return my layoutPanel declared in the class that I have declared above.
So, each region have its own ActivityMapper.ActivityMapper for the menu have only one activity, and "ActivityMapperBody" have sevral activities triggered by menu.
Utility of container are to settle my layout for different "action". I defined zone with it, in order to receive view started with activity.
But this configuration work only with view builded with UIbinder... In each view, I declare a Layout and return it like this
public Widget asWidget() {
return my_layout_declared;
}
When I return my layout, nothing works. I really don't understand why, and I figure that its worse with smartgwt. All I want its just retrieve my layout and put it in my container... Work with smartgwt can save a lot of time...
I've more detailed my issue to make sure that anyone understand. And ask to you Chris Lercher if your post can help me.
Thank for reading
The Smart GWT FAQ mentions a solution:
If you absolutely must place a Smart GWT interface inside a GWT container and you want it to
fill the container, the best approach is to listen for a window-level resize event and run
your own layout calculations that ultimately call resizeTo() on your topmost Smart GWT
widget.
However, it is wrong by saying that
...GWT containers [do not] fire events when they are resized
Layout panels (the "new" panels since GWT 2.0, which was released on Dec 08, 2009) actually do (see the ProvidesResize and RequiresResize interfaces). So if you have such a panel as your MVP body container (and if its parents are also LayoutPanels up to a top RootLayoutPanel), then you can also override the body container's onResize() method instead of listening to the Window resize event.
So how can you solve your concrete problem?
You need to call resizeTo(width, height) on your topmost Smart GWT layout
When you put in a (new) Smart GWT layout, e.g. maybe you put in a new one when the Place changes.
When the window resizes, or when other things happen that change the size of the container (alternatively, if you're using Layout Panels, you can use its onResize())
For the resizeTo(width, height) call, you'll have to determine the width and height by asking the surrounding container, e.g. by using
container.getElement().getClientWidth()

GXT ScrollBar overlapping content

I'm using setScrollMode(ScrollMode.AUTOY) to enable vertical scrolling when necessary on a VerticalLayoutContainer. However, the scrollbar overlaps the content of the container. The only way around this that I've seen is to call setAdjustForScroll(true). The problem with this is that The panel will then always reserve space for a scrollbar even when one is not present.
Is there a way to tell GXT to only adjust for a scrollbar when one is present? Or perhaps use an event handler (eg ResizeHandler) and check if the scrollbar is currently visible?
Instead of trying to check in a handler if the scrollbar is visible, isn't it just easier to not have the content in the VerticalLayoutContainer?
For example I have:
VerticalLayoutContainer vp = new VerticalLayoutContainer();
vp.setScrollMode(ScrollMode.AUTO);
vp.add(layer1, new VerticalLayoutData(1, -1));
vp.add(layer2, new VerticalLayoutData(1, -1));
vp.add(layer3, new VerticalLayoutData(1, -1));
the layers(1-3) contain the actual content and are different types Ex. VBoxLayoutContainer, Container, VerticalLayoutContainer.
It works for me. I don't think it is relevant but I am adding the vp to a CenterLayoutContainer that is added to the root panel.

Display SimplePager Pagination menu both at the top and bottom of the data

I have some data that I'm displaying in a CellTable which is inside a SimplePager. The pagination navigation options are shown in the bottom, I was wondering if it would be possible to show these on the top as well as the bottom of the data.
I want to do this because depending on the browser size, the user may not be able to see the controls.
I want the navigation controls to show both before and after the table data.
Yes, just add two pagers:
final AbstractPager pager = new SimplePager();
pager.setDisplay(cellTable);
contentPanel.add(pager);
contentPanel.add(cellTable);
final AbstractPager pager2 = new SimplePager();
pager2.setDisplay(cellTable);
contentPanel.add(pager2);
The pager shows on top if you add pager before adding celltable in layout.
CellTable table=new CellTable();
VerticalPanel containerPanel = new VerticalPanel();
SimplePager pager1 = new SimplePager(TextLocation.CENTER);
containerPanel.add(pager);
containerPanel.add(table);
SimplePager pager2 = new SimplePager(TextLocation.CENTER)
containerPanel.add(pager2)
Thus, you have to create two pager and add celltable in between of those.

Gwt get Components

I have a Vertiacal panel object and This object contains many radiobuttons
So can i get those radioButton objects through Vertiacal panel object.
Maybe via iteration or ?
private void initCourse() {
coursePopupPanel.clear();
VerticalPanel verticalPanel = new VerticalPanel();
coursePopupPanel.setWidget(verticalPanel);
JsArray<JCourse> jCourseArray = JCourse.getList(stringMainData);
for (int i = 0; i < jCourseArray.length(); i++) {
final RadioButton courseRadioButton = new RadioButton("course");
courseRadioButton.setText(jCourseArray.get(i).getName());
courseRadioButton.getElement().setId(jCourseArray.get(i).getView());
verticalPanel.add(courseRadioButton);
//handler of course radio buttons
courseRadioButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
}
});
}
}
I have a reference to coursePopupPanel. but i have not reference to vertical panel, so can i get elements of vertical panel sonce holding reference to coursePopupPanel.
A GWT VerticalPanel is a subclass of ComplexPanel, an abstract class for Panels that contain more than one child widget. In ComplexPanel (and so inherited by VerticalPanel) are methods for getting the number of child widgets, getting references to them by index, and so on. You could build an iterator something like this:
Iterator<Widget> vPanelWidgets = myVerticalPanel.iterator();
while (vPanelWidgets.hasNext()){
Widget childWidget = vPanelWidgets.next();
if (childWidget instanceof RadioButton) {
...do stuff
}
}
I tend not to query a widget for its members. That ties me to the decisions I made about how to display the RadioButtons, following your example. What if you decide later to display your radio buttons in the cells of a FlexTable in order to control vertical and horizontal arrangement? To make that change means your widget iterator won't work. FlexTable is a Panel but not a ComplexPanel. The code I wrote above won't work if you decide to replace the VerticalPanel with a FlexTable.
If was to take something like this approach, I would keep my lists of related widgets (like a group of RadioButtons) in some sort of Java Collection. I pass that Collection to my presentation class, and inside there I write the code to do the layout. Usually that's a UiBinder class, with "#UiField(provided = true)" for these RadioButtons. The code in the presenter then associates the RadioButton elements of the Collection I passed in to the UiField placeholders for the RadioButtons in the UiBinder layout. So all my layout decisions are actually in the UiBinder xml file. If I decide to rip out my Vertical Panel and replace it with a FlexTable, I might not have to touch a single line of Java code, assuming I separated things out correctly.
[Actually, I would probably keep my decision to use RadioButtons inside the presentation layer, and inside the XML file in particular. That presentation class would fire a message on the EventBus to indicate the user had made a selection via a RadioButton ValueChangeHandler, and I wouldn't care if I used RadioButtons in a VerticalPanel or ToggleButtons in a FlexTable.]
You're not being to specific, add more details and maybe a code example.
I'm gonan try to guesstimate what you're trying to say here: You have a verticalPanel object. To it you add several radioButton objects. Later you want to retrive those radioButton objects (to maybe check if they're selected or not), right? There's several ways to do this. At any rate, why don't you check the code examples at the Gwt Showcase site here:
http://gwt.google.com/samples/Showcase/Showcase.html?locale=en_UM#!CwRadioButton
it has tons of visual examples, each with the attached code and css.
Since PopupPanel implements HasOneWidget interface you can coursePopupPanel.getWidget() to get a reference to your verticalPanel. And iterate widgets in it simply using
for (Widget w : verticalPanel){
//Do Stuff
}

Dynamically updating content of GWT Composite widgets

I created a widget that is a subclass of Composite and has a com.extjs.gxt.ui.client.widget.Viewport in it. Into this viewport I added my header component, a LayoutComponent (initially empty) and my footer component. I initialized the composite widget by calling initWidget at the end of the constructor that sets everything up ... something like this (some code removed for readability):
public class MyComposite extends Composite {
...
public MyComposite(...) {
viewport = new Viewport();
viewport.add(new Header());
content = new LayoutContainer();
viewport.add(content);
viewport.add(new Footer());
initWidget(viewport);
}
public void show(Widget... widgets) {
content.removeAll();
for (Widget widget: widgets) content.add(widget);
}
}
Then I add an instance of this to the RootPanel:
MyComposite myComposite = new MyComposite(...);
RootPanel.get("myComposite").add(myComposite);
And guess what... that works! I see it. The header shows, the footer shows, and the content is blank at this point. Good. Then I make the call to show and add stuff to it. Not exactly as follows but for example:
myComposite.show(new Label(...));
But nothing happens. The code does run, the add(...) method gets called from the show(...) method, there are no exceptions, but nothing (new) shows up. I don't use a Label, but that is not the problem (verified, that works elsewhere). When I inspect the DOM in the browser, I see that there is a div for the content, like there was initially, but it remained empty (i.e. no body content).
What am I missing?
Thanks!
First off, are you extending GWT Composite or GXT Composite? If it is the GXT type you will need to call initComponent() on the viewport (rather than initWidget) as described here: http://dev.sencha.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/Composite.html
Also, try adding the following line to the end of your show method:
content.layout(true);
This will force GXT to layour the contents of your LayoutContainer, and you should at least see the new elements added to the DOM. If they still don't appear on the screen you need to change your Layout of your LayoutContainer.