Example usage for com.google.gwt.place.shared PlaceChangeEvent getNewPlace

List of usage examples for com.google.gwt.place.shared PlaceChangeEvent getNewPlace

Introduction

In this page you can find the example usage for com.google.gwt.place.shared PlaceChangeEvent getNewPlace.

Prototype

public Place getNewPlace() 

Source Link

Document

Return the new Place .

Usage

From source file:accelerator.client.view.desktop.DesktopMainMenuView.java

License:Open Source License

public void setPresenter(Presenter presenter) {
    this.handler = presenter;

    presenter.getClientFactory().getEventBus().addHandler(PlaceChangeEvent.TYPE,
            new PlaceChangeEvent.Handler() {
                public void onPlaceChange(PlaceChangeEvent event) {
                    Place place = event.getNewPlace();
                    for (MainMenuItem s : treeViewModel.getMainMenuItemList()) {
                        if (s.mapsToPlace(place)) {
                            selectionModel.setSelected(s, true);
                            return;
                        }/*  w w  w  .  ja  v a  2  s  .c  o m*/
                    }
                    selectionModel.setSelected(null, true);
                }
            });
}

From source file:client.application.header.HeaderPresenter.java

License:Apache License

@Inject
HeaderPresenter(EventBus eventBus, MyView view, MyProxy proxy) {
    super(eventBus, view, proxy, ApplicationPresenter.SLOT_HeaderContent);
    eventBus.addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {
        @Override/*from  w  w w .  j  ava  2 s  .  c  o  m*/
        public void onPlaceChange(PlaceChangeEvent event) {
            getView().placeChanged(event.getNewPlace());
        }
    });
    getView().setEventBus(eventBus);
}

From source file:com.eucalyptus.webui.client.ExPlaceHistoryHandler.java

License:Open Source License

/**
 * Initialize this place history handler.
 * // ww  w .  j  a  v a  2s  .com
 * @return a registration object to de-register the handler
 */
public HandlerRegistration register(PlaceController placeController, EventBus eventBus, Place defaultPlace,
        Place errorPlace) {
    this.placeController = placeController;
    this.defaultPlace = defaultPlace;
    this.errorPlace = errorPlace;

    final HandlerRegistration placeReg = eventBus.addHandler(PlaceChangeEvent.TYPE,
            new PlaceChangeEvent.Handler() {
                public void onPlaceChange(PlaceChangeEvent event) {
                    log().log(Level.INFO, "Place changed");
                    Place newPlace = event.getNewPlace();
                    historian.newItem(tokenForPlace(newPlace), false);
                }
            });

    final HandlerRegistration historyReg = historian.addValueChangeHandler(new ValueChangeHandler<String>() {
        public void onValueChange(ValueChangeEvent<String> event) {
            String token = event.getValue();
            log().log(Level.INFO, "History changed: " + token);
            handleHistoryToken(token);
        }
    });

    return new HandlerRegistration() {
        public void removeHandler() {
            ExPlaceHistoryHandler.this.defaultPlace = Place.NOWHERE;
            ExPlaceHistoryHandler.this.placeController = null;
            placeReg.removeHandler();
            historyReg.removeHandler();
        }
    };
}

From source file:com.github.gwtbootstrap.showcase.client.Showcase.java

License:Apache License

public void onModuleLoad() {

    CustomResources res = GWT.create(CustomResources.class);
    res.showcase().ensureInjected();/*from  ww  w  . j  av a 2 s  .c o  m*/
    ClientFactory factory = GWT.create(ClientFactory.class);

    subnav = factory.getSubnav();

    initWidget(uiBinder.createAndBindUi(this));

    ActivityMapper activityMapper = new AppActivityMapper(factory);

    ActivityManager activityManager = new ActivityManager(activityMapper, factory.getEventBus());

    activityManager.setDisplay(main);
    PlaceHistoryMapper mapper = factory.getPlaceHistoryMapper();
    final PlaceHistoryHandler handler = new PlaceHistoryHandler(mapper);
    handler.register(factory.getPlaceController(), factory.getEventBus(), new OverviewPlace(""));

    final Map<Menus, NavLink> map = new EnumMap<Menus, NavLink>(Menus.class);
    for (Menus menu : Menus.values()) {
        NavLink link = new NavLink(menu.getDisplay());
        link.setHref("#" + menu.getName() + ":");

        if (menu == Menus.GWT) {
            nav.add(new Divider());
        }
        nav.add(link);

        map.put(menu, link);
    }

    factory.getEventBus().addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {

        @Override
        public void onPlaceChange(PlaceChangeEvent event) {
            Place place = event.getNewPlace();

            if (place instanceof HasMenuPlace) {
                HasMenuPlace menuPlace = (HasMenuPlace) place;

                for (Map.Entry<Menus, NavLink> entry : map.entrySet()) {
                    if (entry.getKey().equals(menuPlace.getMenu())) {
                        entry.getValue().setActive(true);
                    } else {
                        entry.getValue().setActive(false);
                    }
                }

            }
        }
    });

    // addSectionToContainer("Get Started", "setup", new Setup());
    // addSectionToContainer("Get Support", "support", new Support());
    // addSectionToContainer("Buttons", "buttons", new Buttons());
    // addSectionToContainer("Grid System", "gridSystem", new GridSystem());
    // addSectionToContainer("Navigation", "navigation", new Navigation());
    // addSectionToContainer("Hero Unit", "hero", new HeroUnit());
    // addSectionToContainer("Forms", "forms", new Forms());
    // addSectionToContainer("Page Header", "pageheader", new PageHeader());
    // addSectionToContainer("Progress Bar", "progressbar", new
    // ProgressBar());
    // addSectionToContainer("Alerts", "alerts", new Alerts());
    // addSectionToContainer("Pagination", "pagination", new Pagination());
    // addSectionToContainer("Dropdown", "dropdown", new Dropdown());
    // addSectionToContainer("Modal", "modal", new Modal());
    // addSectionToContainer("Datepicker", "datepicker", new Datepicker());
    // addSectionToContainer("Tooltip", "tooltip", new Tooltips());
    // addSectionToContainer("Popover", "popover", new Popovers());
    // addSectionToContainer("Icons", "icons", new Icons());

    RootPanel.get("content").add(this);
    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("https://apis.google.com/js/plusone.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);

    //        github_buttons
    //                .getElement()
    //                .setInnerHTML(
    //                        "<iframe src=\"http://ghbtns.com/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=watch&count=true\"\n"
    //                                + "                                allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"110px\" height=\"20px\"></iframe>"
    //                                + "<br /><iframe src=\"http://ghbtns.com/github-btn.html?user=gwtbootstrap&repo=gwt-bootstrap&type=fork&count=true\"\n"
    //                                + "  allowtransparency=\"true\" frameborder=\"0\" scrolling=\"0\" width=\"95px\" height=\"20px\"></iframe>");

    JavaScriptInjector.inject(
            "!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");");
    JavaScriptInjector.inject(
            "(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1\";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));");

    String token = History.getToken();
    if (!token.equals("")) {
        History.newItem("");
        History.newItem(token);
    }
}

From source file:com.google.gwt.sample.expenses.client.place.ProxyListPlacePicker.java

License:Apache License

public void onPlaceChange(PlaceChangeEvent event) {
    view.setValue(proxyPlaceToListPlace.proxyListPlaceFor(event.getNewPlace()), false);
}

From source file:com.google.gwt.sample.mobilewebapp.client.App.java

License:Apache License

/**
 * Initialize browser history / bookmarking. If LocalStorage is available, use
 * it to make the user's default location in the app the last one seen.
 *///ww w  .  j  a v  a  2s . c om
private void initBrowserHistory(final AppPlaceHistoryMapper historyMapper, PlaceHistoryHandler historyHandler,
        TaskListPlace defaultPlace) {

    Place savedPlace = null;
    if (storage != null) {
        try {
            // wrap in try-catch in case stored value is invalid
            savedPlace = historyMapper.getPlace(storage.getItem(HISTORY_SAVE_KEY));
        } catch (Throwable t) {
            // ignore error and use the default-default
        }
    }
    if (savedPlace == null) {
        savedPlace = defaultPlace;
    }
    historyHandler.register(placeController, eventBus, savedPlace);

    /*
     * Go to the place represented in the URL. This is what makes bookmarks
     * work.
     */
    historyHandler.handleCurrentHistory();

    /*
     * Monitor the eventbus for place changes and note them in LocalStorage for
     * the next launch.
     */
    if (storage != null) {
        eventBus.addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {
            public void onPlaceChange(PlaceChangeEvent event) {
                storage.setItem(HISTORY_SAVE_KEY, historyMapper.getToken(event.getNewPlace()));
            }
        });
    }
}

From source file:com.googlecode.mgwt.mvp.client.AnimatingActivityManager.java

License:Apache License

/**
 * {@inheritDoc}/*from w  w  w .  j a va2 s .  com*/
 *
 * Deactivate the current activity, find the next one from our
 * ActivityMapper, and start it.
 * <p>
 * The current activity's widget will be hidden immediately, which can cause
 * flicker if the next activity provides its widget asynchronously. That can
 * be minimized by decent caching. Perenially slow activities might mitigate
 * this by providing a widget immediately, with some kind of "loading"
 * treatment.
 *
 * @see com.google.gwt.place.shared.PlaceChangeEvent.Handler#onPlaceChange(PlaceChangeEvent)
 */
public void onPlaceChange(PlaceChangeEvent event) {
    if (ignorePlaceChange) {
        //remember the place change event to be executed after the current one is done
        placeChangeStack.add(event);
        return;
    }

    Activity nextActivity = getNextActivity(event);
    Animation animation = getAnimation(event);

    Throwable caughtOnStop = null;
    Throwable caughtOnStart = null;

    if (nextActivity == null) {
        nextActivity = NULL_ACTIVITY;
    }

    if (currentActivity.equals(nextActivity)) {
        return;
    }

    if (startingNext) {
        // The place changed again before the new current activity showed
        // its
        // widget
        currentActivity.onCancel();
        currentActivity = NULL_ACTIVITY;
        startingNext = false;
    } else {

        /*
         * Kill off the activity's handlers, so it doesn't have to worry
         * about them accidentally firing as a side effect of its tear down
         */
        stopperedEventBus.removeHandlers();

        try {
            currentActivity.onStop();
        } catch (Throwable t) {
            caughtOnStop = t;
        } finally {
            /*
             * And kill them off again in case it was naughty and added new
             * ones during onstop
             */
            stopperedEventBus.removeHandlers();
        }
    }

    currentActivity = nextActivity;
    currentPlace = event.getNewPlace();

    if (animation != null) {
        currentIsFirst = !currentIsFirst;
    }

    startingNext = true;

    /*
     * Now start the thing. Wrap the actual display with a per-call instance
     * that protects the display from canceled or stopped activities, and
     * which maintains our startingNext state.
     */
    try {
        currentActivity.start(new ProtectedDisplay(currentActivity), stopperedEventBus);
    } catch (Throwable t) {
        caughtOnStart = t;
    }

    if (caughtOnStart != null || caughtOnStop != null) {
        Set<Throwable> causes = new LinkedHashSet<Throwable>();
        if (caughtOnStop != null) {
            causes.add(caughtOnStop);
        }
        if (caughtOnStart != null) {
            causes.add(caughtOnStart);
        }

        throw new UmbrellaException(causes);
    }

    // animate
    animate(animation);
}

From source file:com.googlecode.mgwt.mvp.client.AnimatingActivityManager.java

License:Apache License

private Animation getAnimation(PlaceChangeEvent event) {
    Place newPlace = event.getNewPlace();
    return animationMapper.getAnimation(currentPlace, newPlace);
}

From source file:com.googlecode.mgwt.mvp.client.AnimatingActivityManager.java

License:Apache License

private Activity getNextActivity(PlaceChangeEvent event) {
    if (display == null) {
        /*//from   ww  w  . j  a  v  a  2s.  co m
         * Display may have been nulled during PlaceChangeEvent dispatch.
         * Don't bother the mapper, just return a null to ensure we shut
         * down the current activity
         */
        return null;
    }
    return mapper.getActivity(event.getNewPlace());
}

From source file:com.googlecode.mgwt.mvp.client.history.MGWTPlaceHistoryHandler.java

License:Apache License

protected void onPlaceChangeEvent(PlaceChangeEvent event) {

    if (ignore) {
        ignore = false;// www  . j av  a2s .  c om
        return;
    }

    Place newPlace = event.getNewPlace();

    historyObserver.onPlaceChange(newPlace, defaultHistoryHandler);

    pushToken(tokenForPlace(newPlace));
}