Wednesday, January 1, 2014

Re: GWT 2.1 MVP Multiple activities clarification help

I know it might be an old topic, but I have tried to implenent thomas idea (http://tbroyer.posterous.com/gwt-21-activities-nesting-yagni ) in this github project. I will be happy to have some comments/suggestions.

https://github.com/ronanquillevere/GWT-Multi-Activities

Regards



On Wednesday, December 15, 2010 3:24:39 PM UTC+1, Milan Cvejic wrote:
Helo,
i tried to understand post at http://tbroyer.posterous.com/gwt-21-activities-nesting-yagni
but with no luck :(

I tried following code:

package com.hellomvp.client;


import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.hellomvp.client.mvp.AppPlaceHistoryMapper;
import com.hellomvp.client.mvp.LeftActivityMapper;
import com.hellomvp.client.mvp.RightActivityMapper;
import com.hellomvp.client.place.HelloPlace;
import com.hellomvp.client.ClientFactory;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */

public class HelloMVP implements EntryPoint {

        private Place defaultPlace = new HelloPlace("World!");
        private LayoutPanel mainLayout = new LayoutPanel();

        SimplePanel leftPanel = new SimplePanel();
        SimplePanel rightPanel = new SimplePanel();

        // Assumes a LayoutPanel is used for the layout, with a SimplePanel
for each display region
    AcceptsOneWidget leftDisplay = new AcceptsOneWidget() {
       public void setWidget(IsWidget activityWidget) {
//               Window.alert("test");
          Widget widget = Widget.asWidgetOrNull(activityWidget);
          mainLayout.setWidgetVisible(leftPanel, widget != null);
          leftPanel.setWidget(widget);
       }
    };

        // Assumes a LayoutPanel is used for the layout, with a SimplePanel
for each display region
    AcceptsOneWidget rightDisplay = new AcceptsOneWidget() {
       public void setWidget(IsWidget activityWidget) {
//               Window.alert("test");
          Widget widget = Widget.asWidgetOrNull(activityWidget);
          mainLayout.setWidgetVisible(rightPanel, widget != null);
          rightPanel.setWidget(widget);
       }
    };

        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {

                // Create ClientFactory using deferred binding so we can replace
with
                // different
                // impls in gwt.xml
                ClientFactory clientFactory = GWT.create(ClientFactory.class);
                EventBus eventBus = clientFactory.getEventBus();
                PlaceController placeController =
clientFactory.getPlaceController();

                // Start ActivityManager for the left widget with our ActivityMapper
                ActivityMapper leftActivityMapper = new LeftActivityMapper(
                                clientFactory);
                ActivityManager leftActivityManager = new ActivityManager(
                                leftActivityMapper, eventBus);
                leftActivityManager.setDisplay(leftDisplay);


                // Start ActivityManager for the right widget with our
ActivityMapper
                ActivityMapper rightActivityMapper = new RightActivityMapper(
                                clientFactory);
                ActivityManager rightActivityManager = new ActivityManager(
                                rightActivityMapper, eventBus);
                rightActivityManager.setDisplay(rightDisplay);

                // Start PlaceHistoryHandler with our PlaceHistoryMapper
                AppPlaceHistoryMapper historyMapper = GWT
                                .create(AppPlaceHistoryMapper.class);

                PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(
                                historyMapper);
                historyHandler.register(placeController, eventBus, defaultPlace);

                DOM.setStyleAttribute(leftPanel.getElement(), "backgroundColor",
                                "#3054A1");
                DOM.setStyleAttribute(rightPanel.getElement(), "backgroundColor",
                                "#ff2e80");

//                mainLayout.addWest(leftPanel, 15);
//                mainLayout.addEast(rightPanel, 15);

                mainLayout.add(leftPanel);
                mainLayout.add(rightPanel);

                mainLayout.setWidgetLeftWidth(leftPanel, 0, Unit.PCT, 50,
Unit.PCT);  // Left panel
                mainLayout.setWidgetRightWidth(rightPanel, 0, Unit.PCT, 50,
Unit.PCT); // Right panel

                RootLayoutPanel.get().add(mainLayout);
                // Goes to place represented on URL or default place
                historyHandler.handleCurrentHistory();
        }

}

But even if rightActivityManager or leftActivityManager return null,
nothing happens with layout, exept that Activity is not run. So the
method in display setWidget is not called, and therefore no action is
happening with widget.

Is there any complete example on this topic?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment