Gwt-query doesn't work for my MVP. - gwt

I dived to the gwt world a few monthes ago and now am trying to use the gwt-query library.
I followed this tutorial: http://code.google.com/p/gwtquery/wiki/GettingStarted
Because I am working in Modle-View-Presenter, I tried implementing the above tutorial in my View (that is bound to the ..View.ui.xml), But it dosent seems to work.
I tried creating a lable, and then run the code:
List allGwtLabels = $(".gwt-Label").widgets();
but it selects nothing!
I think I have to point somehow where I want the qwtQuery to search for the widgets (point to my specific ui.xml file)
What am I doing wrong?
Thanks in advance. Below is my code of my Presenter + View + xml that dosent work:
//================================Presenter=================================:
public class QueryPresenter extends
Presenter<QueryPresenter.MyView, QueryPresenter.MyProxy> {
public interface MyView extends View {
}
#ProxyCodeSplit
#NameToken(NameTokens.query)
public interface MyProxy extends ProxyPlace<QueryPresenter> {
}
#Inject
public QueryPresenter(final EventBus eventBus, final MyView view,
final MyProxy proxy) {
super(eventBus, view, proxy);
}
#Override
protected void revealInParent() {
RevealRootContentEvent.fire(this, this);
}
#Override
protected void onBind() {
super.onBind();
}
}
//====================================View============================================:
public class QueryView extends ViewImpl implements QueryPresenter.MyView {
private final Widget widget;
public interface Binder extends UiBinder<Widget, QueryView> {
}
#Inject
public QueryView(final Binder binder) {
widget = binder.createAndBindUi(this);
List<Widget> allGwtLabels = $(".gwt-Label").widgets(); //Doesn't Work!!
//Also doesn't work!!
Label label = new Label("Click on me and I will disappear");
$(label).click(new Function() {
#Override
public void f(Widget w) {
//fade out the label
$(w).fadeOut(1000);
}
});
_html.add(label);
//retrieve all attached gwt labels
}
#Override
public Widget asWidget() {
return widget;
}
#UiField Label _label;
#UiField HTMLPanel _html;
}
//==================xml file===============================
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default'>
<g:HTMLPanel ui:field="_html">
<script type="text/javascript" language="javascript" src="gquerytest/gquerytest.nocache.js"></script>
<g:Label text="hey" ui:field="_label"/>
</g:HTMLPanel>
</ui:UiBinder>

try : List allGwtLabels = $(".gwt-Label", widget).widgets();
You have to specify the container of your elements as the elements are not attached to the dom when you try to query them.

Related

Why am I not able to update my navigation bar (PermanentSlot)?

Short summary:
I try to update a navigation bar after a place change event. To do so I created a GWTP Test*.java that I try to render in a SLOT_NavBar. However, this is not working. In order to see if I did something wrong I just made itself render in my SLOT_AdminToolMainContent slot which is working perfectly fine. The question is why I can render TestView in one slot but not in the other. GWTP is not giving me any clues about what I'm doing wrong here and I can't find anything in the documention that would help me out here.
I'm sure the problem must be either a misunderstanding from my side or something really stupid that I'm doing but I just fail to see the reason why this is not working.
I'm having here a "root" presenter:
AdminToolPresenter.java
public class AdminToolPresenter extends Presenter<AdminToolPresenter.MyView, AdminToolPresenter.MyProxy> {
public interface MyView extends View {
}
#ProxyStandard
#NameToken(AdminNameTokens.adminTool)
#UseGatekeeper(AdminGatekeeper.class)
public interface MyProxy extends ProxyPlace<AdminToolPresenter> {
}
/** */
public static final PermanentSlot<MenuPresenter> SLOT_Menu = new PermanentSlot<>();
/** */
public static final NestedSlot SLOT_AdminToolMainContent = new NestedSlot();
/** */
private MenuPresenter menuPresenter;
#Inject
public AdminToolPresenter(EventBus eventBus, MyView view, MyProxy proxy, MenuPresenter menuPresenter) {
super(eventBus, view, proxy, RevealType.RootLayout);
this.menuPresenter = menuPresenter;
}
#Override
protected void onBind() {
this.setInSlot(SLOT_Menu, this.menuPresenter);
}
#Override
protected void onReveal() {
LOGGER.fine("AdminToolPresenter.onReveal()");
}
}
and its view:
AdminToolView.java
public class AdminToolView extends ViewImpl implements AdminToolPresenter.MyView {
#SuppressWarnings("unused")
private final static Logger LOGGER = Logger.getLogger(AdminToolView.class.getName());
public interface Binder extends UiBinder<Widget, AdminToolView> {
}
#UiField HTMLPanel menuPanel;
#UiField SimplePanel adminMainContent;
#Inject
public AdminToolView(Binder uiBinder) {
this.initWidget(uiBinder.createAndBindUi(this));
this.bindSlot(AdminToolPresenter.SLOT_Menu, this.menuPanel);
this.bindSlot(AdminToolPresenter.SLOT_AdminToolMainContent, this.adminMainContent);
}
}
Everything I'm doing with this is working just fine for example:
TestPresenter.java
public class TestPresenter extends Presenter<TestPresenter.MyView, TestPresenter.MyProxy> implements TestUiHandlers {
private final static Logger LOGGER = Logger.getLogger(TestPresenter.class.getName());
interface MyView extends View , HasUiHandlers<TestUiHandlers> {
}
#NameToken(AdminNameTokens.test)
#ProxyStandard
interface MyProxy extends ProxyPlace<TestPresenter> {
}
#Inject
TestPresenter(EventBus eventBus, MyView view, MyProxy proxy) {
// This is working just fine. The content gets displayed correctly in the SLOT_AdminToolMainContent slot
super(eventBus, view, proxy, AdminToolPresenter.SLOT_AdminToolMainContent);
this.getView().setUiHandlers(this);
}
#Override
public void prepareFromRequest(PlaceRequest request) {
LOGGER.severe("prepareFromRequest");
super.prepareFromRequest(request);
}
}
TestView.java
class TestView extends ViewWithUiHandlers<TestUiHandlers> implements TestPresenter.MyView {
interface Binder extends UiBinder<Widget, TestView> {
}
#UiField SimplePanel main;
#Inject TestView(Binder uiBinder) {
this.initWidget(uiBinder.createAndBindUi(this));
}
}
No problem at all! However, if I try to bind this to another slot:
The issue
#Inject
TestPresenter(EventBus eventBus, MyView view, MyProxy proxy) {
// MenuPresenter.SLOT_NavBar instead of AdminToolPresenter.SLOT_AdminToolMainContent
super(eventBus, view, proxy, MenuPresenter.SLOT_NavBar);
this.getView().setUiHandlers(this);
}
Then it's simply doing nothing! I only changed the slot - so why is this not working? Here is the MenuPresenter and related code:
MenuPresenter.java
public class MenuPresenter extends PresenterWidget<MenuPresenter.MyView> implements MenuUiHandlers {
private final static Logger LOGGER = Logger.getLogger(MenuPresenter.class.getName());
interface MyView extends View, HasUiHandlers<MenuUiHandlers> {
}
/** Slot for the navigation bar. */
public static final NestedSlot SLOT_NavBar = new NestedSlot();
#Inject
MenuPresenter(EventBus eventBus, MyView view) {
super(eventBus, view);
this.getView().setUiHandlers(this);
}
#Override
protected void onReveal() {
LOGGER.severe("onReveal()");
}
}
MenuView.java
class MenuView extends ViewWithUiHandlers<MenuUiHandlers> implements MenuPresenter.MyView {
interface Binder extends UiBinder<Widget, MenuView> {
}
#UiField HTMLPanel navBarPanel;
#UiField MaterialSideNav sideNav;
private PlaceManager placeManager;
#Inject MenuView(Binder uiBinder, PlaceManager placeManager) {
this.initWidget(uiBinder.createAndBindUi(this));
this.bindSlot(MenuPresenter.SLOT_NavBar, this.navBarPanel);
this.placeManager = placeManager;
}
}
MenuView.ui.xml
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:m="urn:import:gwt.material.design.client.ui"
xmlns:m.addins="urn:import:gwt.material.design.addins.client.ui">
<ui:with field="tokens" type="com.mz.client.admin.place.AdminNameTokens"/>
<ui:style gss="true">
/* .. */
</ui:style>
<g:HTMLPanel ui:field="main">
<g:HTMLPanel addStyleNames="{style.navbar-wrapper}">
<g:SimplePanel ui:field="navBarPanel" />
</g:HTMLPanel>
<m:MaterialHeader>
<m:MaterialNavBar backgroundColor="white" activates="sideNav" layoutPosition="RELATIVE" addStyleNames="{style.nav-bar}">
<m:MaterialNavSection>
</m:MaterialNavSection>
</m:MaterialNavBar >
<m:MaterialSideNav ui:field="sideNav" m:id="sideNav" type="FIXED" alwaysShowActivator="true" width="280" addStyleNames="{style.side-nav}" >
<m:MaterialLink targetHistoryToken="{tokens.getHome}" iconType="HOME" iconPosition="LEFT" textColor="black" text="Home" />
</m:MaterialSideNav>
</m:MaterialHeader>
</g:HTMLPanel>
</ui:UiBinder>
Please explain to me why this is not working - it is driving me nuts. I'm not getting anything from GWTP like "dude, you're trying to do something strange here". No warning, error or info. Just nothing and I don't see what I do wrong here!
To give you an idea how this looks like: The blue bar is the <g:SimplePanel ui:field="navBarPanel"/> which you see in MenuView:
Did You tried to replace PernamentSlot with SingleSlot? I am not sure that you can update PernamentSlot.
Did You tried to replace PresenterWidget with Presenter in class extension in MenuPresenter class?
MenuView is widget, no place, So it seems that You did not add this view anywhere, so it simply doesn't display it self. Try to put some static content to this view and see is it even reveal itself.
Try in main view add in constructor widget.add(new MenuView());. where widget is initialized(using java or uibinder) view element.
To display regular Presenter (which is a place)You have to have a url for it (f.e.: localhost:8080/myApp | localhost:8080/myApp#MenuPresenter).
To display PresenterWidget You have to call it somewhere!
According to documentation here:
NestedSlot: Same as SingleSlot, but can only take Presenters that have
Proxies (no PresenterWidget).
and You try to put there a PresenterWidget- WHICH IS WRONG, try to:
replace NestedSlot with Slot or SingleSlot(accepts PresenterWidget),
or change MenuPresenter to extend regular Presenter instead of PresenterWidget.
Try do this and give me feedback.
You should try to clean and install Your whole application and restart SuperDevMode and Your server.
I've recreate described functionality. It works. I've base on this article
Layout example
Layout example. Hope this will help.
package pl.korbeldaniel.cms.client.place.app;
public class AppModule extends AbstractPresenterModule {
#Override
protected void configure() {
install(new UiModule());
bindPresenter(AppPresenter.class, AppPresenter.MyView.class, AppView.class, AppPresenter.MyProxy.class);
bindPresenter(HomePresenter.class, HomePresenter.MyView.class, HomeView.class, HomePresenter.MyProxy.class);
bindPresenter(ErrorPresenter.class, ErrorPresenter.MyView.class,
bindPresenter(TesttPresenter.class, TesttPresenter.MyView.class, TesttView.class, TesttPresenter.MyProxy.class);
}
}
package pl.korbeldaniel.cms.client.place.app;
public class AppPresenter extends TabContainerPresenter<AppPresenter.MyView, AppPresenter.MyProxy> implements AppUiHandlers, CurrentUserChangedHandler, AsyncCallStartHandler, AsyncCallFailHandler, AsyncCallSucceedHandler {
#ProxyStandard
public interface MyProxy extends Proxy<AppPresenter> {}
public interface MyView extends TabView, HasUiHandlers<AppUiHandlers> {}
public static final NestedSlot SLOT_NavBar = new NestedSlot();
private final TesttPresenter testtPresenter;
#Inject
AppPresenter(EventBus eventBus, MyView view, MyProxy proxy, TesttPresenter testtPresenter) {
super(eventBus, view, proxy, SLOT_TAB_CONTENT, SLOT_REQUEST_TABS, SLOT_CHANGE_TAB, RevealType.Root);
this.testtPresenter = testtPresenter;
getView().setUiHandlers(this);
}
#Override
protected void onBind() {
super.onBind();
setInSlot(SLOT_NavBar, testtPresenter);
}
}
package pl.korbeldaniel.cms.client.place.app;
public class AppView extends ViewWithUiHandlers<AppUiHandlers> implements AppPresenter.MyView {
public interface Binder extends UiBinder<Widget, AppView> {}
#UiField MaterialRow navBarPanel;
#Inject
AppView(Binder uiBinder) {
initWidget(uiBinder.createAndBindUi(this));
bindSlot(AppPresenter.SLOT_NavBar, navBarPanel);
}
}
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:m="urn:import:gwt.material.design.client.ui"
<m:MaterialPanel>
<m:MaterialRow ui:field="navBarPanel" />
</m:MaterialPanel>
</ui:UiBinder>
package pl.korbeldaniel.cms.client.playground.test.testt;
import pl.korbeldaniel.cms.client.place.app.AppPresenter;
public class TesttPresenter extends Presenter<TesttPresenter.MyView, TesttPresenter.MyProxy> {
public interface MyView extends View {}
#ProxyStandard
public interface MyProxy extends Proxy<TesttPresenter> {}
#Inject
public TesttPresenter(EventBus eventBus, MyView view, MyProxy proxy) {
super(eventBus, view, proxy, AppPresenter.SLOT_NavBar);
}
}
package pl.korbeldaniel.cms.client.playground.test.testt;
import pl.korbeldaniel.cms.client.place.app.AppPresenter;
public class TesttView extends ViewImpl implements TesttPresenter.MyView {
public interface Binder extends UiBinder<Widget, TesttView> {}
#UiField
SimplePanel main;
#Inject
public TesttView(Binder uiBinder) {
initWidget(uiBinder.createAndBindUi(this));
main.add(new Label("____________________________________________________________________________________________________________________>TEST "));
Window.alert("TESTT");
this.bindSlot(AppPresenter.SLOT_NavBar, this.main);
}
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:SimplePanel ui:field="main"></g:SimplePanel>
</ui:UiBinder>

GWTP not displaying UI

I'm trying to use GWTP in my GWT 2.7 application but the UI in my uibinder is not displaying. My app compiles and runs in Super dev mode without any errors, but I get a blank screen. I expected the HTML in the LayoutView.ui.xml to show in the browser. I'm sure I'm missing something really basic. Any help would be great.
The following is included in my .gwt.xml file
<inherits name='com.google.gwt.inject.Inject' />
<!-- Other module inherits -->
<inherits name="com.google.gwt.uibinder.UiBinder" />
<inherits name='com.gwtplatform.mvp.Mvp' />
<entry-point class="com.clearwood.client.App" />
<define-configuration-property name="gin.ginjector" is-multi-valued="false" />
<set-configuration-property name="gin.ginjector"
value="com.clearwood.client.gin.MyGinjector" />
client/App.java
public class App implements EntryPoint {
public final MyGinjector ginjector = GWT.create(MyGinjector.class);
#Override
public void onModuleLoad() {
DelayedBindRegistry.bind(ginjector);
ginjector.getPlaceManager().revealCurrentPlace();
}
}
client/gin/ClientModule.java
public class ClientModule extends AbstractPresenterModule {
#Override
protected void configure() {
install(new DefaultModule());
install(new LayoutModule());
bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.LAYOUT);
bindConstant().annotatedWith(ErrorPlace.class).to(NameTokens.LAYOUT);
bindConstant().annotatedWith(UnauthorizedPlace.class).to(NameTokens.LAYOUT);
requestStaticInjection(NameTokens.class);
}
}
client/gin/Ginjector.java
#GinModules({ ClientModule.class })
public interface MyGinjector extends Ginjector {
EventBus getEventBus();
PlaceManager getPlaceManager();
Provider<LayoutPresenter> getLayoutPresenter();
}
client/place/NameTokens.java
public class NameTokens {
public static final String LAYOUT = "LAYOUT";
public static String getLAYOUT() {
return LAYOUT;
}
}
client/layout/LayoutView.ui.xml
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:SimplePanel width="600px" height="auto" ui:field="main">
<g:HTML width="100%" height="100%">TEST</g:HTML>
</g:SimplePanel>
</ui:UiBinder>
client/layout/LayoutView.java
class LayoutView extends ViewImpl implements LayoutPresenter.MyView {
interface Binder extends UiBinder<Widget, LayoutView> {
}
#UiField
SimplePanel main;
#Inject
LayoutView(Binder uiBinder) {
initWidget(uiBinder.createAndBindUi(this));
}
#Override
public void setInSlot(Object slot, IsWidget content) {
if (slot == LayoutPresenter.SLOT_Layout) {
main.setWidget(content);
} else {
super.setInSlot(slot, content);
}
}
}
client/layout/LayoutPresenter.java
public class LayoutPresenter extends Presenter<LayoutPresenter.MyView, LayoutPresenter.MyProxy> {
interface MyView extends View {
}
#ContentSlot
public static final Type<RevealContentHandler<?>> SLOT_Layout = new Type<RevealContentHandler<?>>();
#ProxyStandard
interface MyProxy extends Proxy<LayoutPresenter> {
}
#Inject
LayoutPresenter(
EventBus eventBus,
MyView view,
MyProxy proxy) {
super(eventBus, view, proxy, RevealType.Root);
}
}
client/layout/LayoutModule.java
public class LayoutModule extends AbstractPresenterModule {
#Override
protected void configure() {
bindPresenter(LayoutPresenter.class, LayoutPresenter.MyView.class, LayoutView.class, LayoutPresenter.MyProxy.class);
}
}
I generated the Layout presenter using the GWTP plugin.
I tried to follow the sample tutorials at
http://dev.arcbees.com/gwtp/sampletutorial/
and
https://code.google.com/p/gwt-platform/wiki/GettingStarted#Getting_the_sample_applications
but some of it seems to be deprecated
You don't have a presenter with a ProxyPlace and the annotation #NameToken on it. To get your code working quickly, you can change LayoutPresenter.MyProxy to:
#ProxyStandard
#NameToken(NameTokens.LAYOUT)
interface MyProxy extends ProxyPlace<LayoutPresenter> {}
Also the Google Code documentation is actually outdated by a lot. There are warnings all over the place, so I thought this was obvious.
The documentation on https://dev.arcbees.com/gwtp/sampletutorial/ is recent enough to help you develop a working application. You can also have a look at GWTP's Basic Sample for more examples: https://github.com/ArcBees/GWTP-Samples/tree/master/gwtp-samples/gwtp-sample-basic

GWT's Editor Framework and GWTP

building on this answer, i try to integrate the GWT editors into a popup presenter widget. What is the right way to do that?
My view looks like this:
public class DeviceEditorDialogView extends
PopupViewWithUiHandlers<DeviceEditorDialogUiHandlers> implements
DeviceEditorDialogPresenterWidget.MyView {
interface Binder extends UiBinder<PopupPanel, DeviceEditorDialogView> {
}
public interface Driver extends SimpleBeanEditorDriver<DeviceDto, DeviceEditorDialogView> {
}
#Inject
DeviceEditorDialogView(Binder uiBinder, EventBus eventBus) {
super(eventBus);
initWidget(uiBinder.createAndBindUi(this));
}
#Override
public SimpleBeanEditorDriver<DeviceDto, ?> createEditorDriver() {
Driver driver = GWT.create(Driver.class);
driver.initialize(this);
return driver;
}
}
and my presenter looks like this:
public class DeviceEditorDialogPresenterWidget extends PresenterWidget<DeviceEditorDialogPresenterWidget.MyView> implements
DeviceEditorDialogUiHandlers {
#Inject
DeviceEditorDialogPresenterWidget(EventBus eventBus,
MyView view) {
super(eventBus, view);
getView().setUiHandlers(this);
}
/**
* {#link LocalDialogPresenterWidget}'s PopupView.
*/
public interface MyView extends PopupView, DevicesEditView<DeviceDto>, HasUiHandlers<DeviceEditorDialogUiHandlers> {
}
private DeviceDto currentDeviceDTO = null;
private SimpleBeanEditorDriver<DeviceDto, ?> driver;
public DeviceDto getCurrentDeviceDTO() {
return currentDeviceDTO;
}
public void setCurrentDeviceDTO(DeviceDto currentDeviceDTO) {
this.currentDeviceDTO = currentDeviceDTO;
}
#Override
protected void onBind() {
super.onBind();
driver = getView().createEditorDriver();
}
//UiHandler Method: Person person = driver.flush();
}
Is this the right approach? What is missing? Currently nothing happens when i try to use it like this:
#Override
public void showDeviceDialog() {
deviceEditorDialog.setCurrentDeviceDTO(new DeviceDto());
addToPopupSlot(deviceEditorDialog);
}
showDeviceDialog is in the parent presenter and called when clicking a button in that parent Presenter, that instantiates the dialog with private final DeviceEditorDialogPresenterWidget deviceEditorDialog;
Thanks!
Here are a few key points that are missing from your code above:
Your DeviceEditorDialogView should implement Editor<DeviceDto>. This is required in order for the fields of DeviceEditorDialogView to be populated with data from you POJO.
Your DeviceEditorDialogView should have child editors that are mapped to fields in your POJO. For example, given the field deviceDto.modelName (type String), you could have a GWT Label named modelName in your DeviceEditorDialogView. This Label implements Editor<String> and will be populated with the modelName from your DeviceDto when you call driver.edit(deviceDto)
You should call driver.initialize(this) only once, in DeviceEditorDialogView's constructor
You should override onReveal() like this:
#Override
public void onReveal() {
super.onReveal();
driver.edit(currentDeviceDTO); // this will populate your view with the data from your POJO
}
This method will be called when the popup is displayed, just after your DeviceEditorDialogPresenterWidget has been addToPopupSlot

GWT Resizable Composite

I'm trying a simple experiment with ResizableComposite by logging width & height of the widget, but I'm not getting any response.
ResizableFlowPanel
public class ResizableFlowPanel extends FlowPanel implements RequiresResize, ProvidesResize {
public ResizableFlowPanel() {
super();
}
#Override
public void onResize() {
GWT.log(this.getOffsetHeight() +","+this.getOffsetWidth());
}
}
AppBody.java
public class AppBody extends ResizeComposite implements RequiresResize,
ProvidesResize {
private static AppBodyUiBinder uiBinder = GWT.create(AppBodyUiBinder.class);
public AppBody() {
initWidget(uiBinder.createAndBindUi(this));
}
#Override
public void onResize() {
GWT.log(this.getOffsetHeight() + "," + this.getOffsetWidth());
super.onResize();
}
interface AppBodyUiBinder extends UiBinder<Widget, AppBody> {
}
}
AppBody.ui.xml
<ui:UiBinder ...>
<e:ResizableFlowPanel styleName="{bundle.appBodyStyle.app_body}">
</e:ResizableFlowPanel>
</ui:UiBinder>
When I resize the browser, I'm not getting any log messages.

What is the proper way to use gwt-bootstrap modal with gwt-platform?

I am constructiong an webapp with Google Web Toolkit using GWT-Platform and GWT-Bootstrap frameworks. Mostly it has been almost flawless until I tried to implement a popup. These frameworks' undestanding of popups seems to be quite different.
GWT-Platform expects a popup widget itself to be an instance of com.google.gwt.user.client.ui.PopupPanel when using the GWTP's RevealRootPopupContentEvent.fire(source, content) or a presenter's addToPopupSlot(child) method.
GWT-Bootstrap's Modal is used like any other widget that is added to the underlying panel but my goal is it to have a separate presenter and view and to possibly fetch it asynchrously with AsyncProvider.
I have tried to make it as a PresenterWidget and using addToSlot(slot, content) to reveal it but it doesn't look quite right. Not all of the styles are applied this way and the close icon (×), doesn't work for example.
I think I am not the first one trying to do something like that so maybe someone has figured out a proper way to make it work.
Thanks!
You have to create a view:
public class MyPopupView extends PopupViewImpl implements MyView {
protected Widget widget;
public interface MyPopupViewUiBinder extends
UiBinder<Widget, MyPopupView> {
}
#UiField(provided = true)
Modal dialogBox;
private MyPresenter presenter;
#Inject
public MyPopupView(final MyPopupViewUiBinder uiBinder,
final EventBus eventBus) {
super(eventBus);
setUpDialog(); // Provides UiField => Before initWidgets
initWidget(uiBinder.createAndBindUi(this));
}
// DialogBox must be overridden to let the presenter handle changes onUnload
private void setUpDialog() {
dialogBox = new Modal() {
#Override
protected void onUnload() {
MyPopupView.this.hide();
}
};
dialogBox.setTitle("Some title");
}
#Override
public void setPresenter(final MyPresenter presenter) {
this.presenter = presenter;
}
#Override
public final void hide() {
dialogBox.hide();
presenter.hide();
}
#Override
public void setAutoHideOnNavigationEventEnabled(final boolean autoHide) {
// TODO Auto-generated method stub
}
#Override
public void setCloseHandler(
final PopupViewCloseHandler popupViewCloseHandler) {
// TODO Auto-generated method stub
}
#Override
public void setPosition(final int left, final int top) {
// TODO Auto-generated method stub
}
#Override
public void show() {
dialogBox.show();
}
#Override
public void center() {
dialogBox.show();
}
#Override
public Widget asWidget() {
return widget;
}
protected final void initWidget(final Widget widget) {
this.widget = widget;
}
}
And a UIBinder file:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:b='urn:import:com.github.gwtbootstrap.client.ui'>
<b:Modal title="Some Title" ui:field="dialogBox">
<!-- Your content -->
</b:Modal>
</ui:UiBinder>
Your gwtp popup presenter has a view that extends PopUpViewImpl which implements PopupView, and uses a lot of the methods of that interface for displaying the popup (asPopupPanel(), show(), center(), etc).
I'm just starting to get to know gwt-bootstrap (looks great +caalos0), but it seems that Modal doesn't implement PopupView, and therefore cannot be passed to addToPopupSlot in a way it would be displayed automatically by gwtp.
as for the addToSlot() issue, are you using RootLayoutPanel or RootPanel?
it could be the reason for addToSlot not working properly, since the gwt-bootstrap Modal widget is attached to the RootPanel on initialization, this can cause weird layout behavior along with an application using RootLayoutPanel as base.
I would try to extend the Modal component, let it implement PopUpView, add it as a field on the PopUpViewImpl attached to your popup presenter, and override the PopUpViewImpl asPopupPanel() function to return the new extended Modal.
Based on the answer by #dominik I did some improvements, see my Gist. It contains some abstract base classes that can be used for any Modal/PopupView implementation. It's a bit more complex but also cleaner because we don't pass the whole Presenter to the View. The interface for the View to interact with the Presenter when the modal is closed is HasModalUnbind.
You would use these classes as follows. Example presenter:
public class ErrorModalPresenter extends ModalPopupPresenter<ErrorModalPresenter.MyView> {
public interface MyView extends ModalPopupView {
DivElement getErrorMessage();
}
private final ErrorEvent error;
#Inject
public ErrorModalPresenter(final EventBus eventBus,
final MyView view,
#Assisted final ErrorEvent error) {
super(eventBus, view);
this.error = error;
}
#Override
public void unbindModal() {
ErrorDismissEvent.fire(this, this);
}
#Override
protected void onBind() {
super.onBind();
//noinspection ThrowableResultOfMethodCallIgnored
getView().getErrorMessage().setInnerText(error.getCause().getMessage());
}
}
Example view:
public class ErrorModalView extends ModalPopupViewImpl implements ErrorModalPresenter.MyView {
#UiField(provided = true)
Modal errorModal;
#UiField
DivElement errorMessage;
interface Binder extends UiBinder<Widget, ErrorModalView> {}
#Inject
public ErrorModalView(final EventBus eventBus,
final Binder uiBinder) {
super(eventBus);
errorModal = initModal();
initWidget(uiBinder.createAndBindUi(this));
}
#Override
public DivElement getErrorMessage() {
return errorMessage;
}
}
And the UiBinder XML just for the record:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:b='urn:import:com.github.gwtbootstrap.client.ui'>
<b:Modal ui:field='errorModal' title='Error'>
<g:HTML>
<div ui:field='errorMessage'/>
</g:HTML>
<b:ModalFooter>
<b:Button text='Close' dismiss='MODAL'/>
</b:ModalFooter>
</b:Modal>
</ui:UiBinder>
In unbindModal() of ErrorModalPresenter I fire an event which is caught by the parent presenter of ErrorModalPresenter. There the modal presenter is removed from a container and then unbind() is called on the presenter. Of course any other solution is possible in unbindModal().
The base classes assume that modals are one-shot modals that will be removed once they're hidden. This behaviour can be changed in initModal() of ModalPopupViewImpl.
I believe you will have to made some Glue Code to made it works.
I never used GWT-Platform popups, so I dont know exactly how, but I believe you will have to made a new Class extending PopupPresenter, and made what's needed to made it work.
Also, I was thinking about GWT-Platform days ago... and I'm pretty sure that when first release of GWT-Platform is out, I'll create a new project to made these necessary glue codes.
If you need any help with this, please contact me.
Thanks, sorry about the poor gwt-platform support.