Example usage for com.google.gwt.user.client History getToken

List of usage examples for com.google.gwt.user.client History getToken

Introduction

In this page you can find the example usage for com.google.gwt.user.client History getToken.

Prototype

public static String getToken() 

Source Link

Document

Gets the current history token.

Usage

From source file:TaskListPresenter.java

License:Open Source License

private void updateCurrentUrlForQuery(QueryRequest request) {
    // FIXME / TODO use the logic in ProjectTasksPlace.
    // Get our current page URL

    SortInfo sortInfo = request.getSortInfo();
    // Get our current parameters.
    Map<String, List<String>> urlParamMap = Navigation.getNavigationParameterMap();

    // Append our parameters as appropriate
    if (sortInfo != null) {
        updateParamInMap(urlParamMap, ProjectTasksPlace.SORTFIELD_URLPARAM, sortInfo.getSortField(),
                sortInfo.getSortField() != null);
        updateParamInMap(urlParamMap, ProjectTasksPlace.SORTORDER_URLPARAM,
                String.valueOf(sortInfo.getSortOrder()), sortInfo.getSortOrder() != null);
    }//from   ww w  . j  a  v a2s . c  o  m

    Region requestRegion = request.getPageInfo();
    updateParamInMap(urlParamMap, ProjectTasksPlace.NUMRESULTS_URLPARAM,
            String.valueOf(requestRegion.getSize()),
            requestRegion.getSize() != ProjectTasksPlace.DEFAULT_PAGESIZE);
    updateParamInMap(urlParamMap, ProjectTasksPlace.STARTINDEX_URLPARAM,
            String.valueOf(requestRegion.getOffset()), requestRegion.getOffset() > 0);

    String updatedUrl = History.getToken();

    // Strip off the set of URL parameters on the current history token if they exist.
    if (updatedUrl.indexOf('?') > 0) {
        updatedUrl = updatedUrl.substring(0, updatedUrl.indexOf('?'));
    }

    // Now, loop through and write all of our parameters to our URL.
    for (String curParamName : urlParamMap.keySet()) {
        for (String curParamValue : urlParamMap.get(curParamName)) {
            updatedUrl = Navigation.appendQueryParameterToUrl(updatedUrl, curParamName, curParamValue);
        }
    }

    // Update our URL, but don't trigger a page navigation - it's already in progress.
    History.newItem(updatedUrl, false);
}

From source file:ar.com.kyol.jet.client.JetPaginatedTable.java

License:Open Source License

/**
 * Check the requested page from the History token and returns a value for FROM.
 * If useHyperlinks is disabled, return the FROM according to current page.
 * /*from   ww w  .j  a v  a  2 s  . c o  m*/
 * @return from
 */
protected int getRequestedPageFrom() {
    if (useHyperlinks) {
        String token = History.getToken();
        int pagePos = token.indexOf("/p") + 2;
        if (pagePos > 1 && !token.equals("")) {
            String sPage = token.substring(pagePos);
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < sPage.length(); i++) {
                if (!Character.isDigit(sPage.charAt(i)))
                    break;
                sb.append(sPage.substring(i, i + 1));
            }
            if (sb.length() > 0) {
                page = Integer.parseInt(sb.toString());
            } else {
                page = 1;
            }
        } else {
            page = 1;
        }
    }
    return (page * qty) - qty;
}

From source file:ar.com.kyol.jet.client.JetPaginatedTable.java

License:Open Source License

/**
 * Returns the token without page parameters.
 * //from ww w.  ja  v  a2 s  .c o m
 * @return
 */
protected String getPlainToken() {
    int pos = History.getToken().indexOf("/p");
    if (pos != -1) {
        return History.getToken().substring(0, pos);
    }
    return History.getToken();
}

From source file:asquare.gwt.tests.history.client.Demo.java

License:Apache License

public void onModuleLoad() {
    TabCollection tabSet = new TabCollection();
    tabSet.add("grains", "Grains", createGrains());
    tabSet.add("vegetables", "Vegetables", createVegetables());
    tabSet.add("fruit", "Fruit", createFruit());
    tabSet.add("stimulants", "Stimulants", createStimulants());

    TabPanel tabPanel = new TabPanel();
    for (int i = 0; i < tabSet.size(); i++) {
        tabPanel.add(tabSet.getWidget(i), tabSet.getDescription(i));
    }/*w w w .j  a v a  2  s . c o m*/

    String initialTabToken = History.getToken();
    if (initialTabToken.length() == 0) {
        initialTabToken = tabSet.getToken(0);
    }
    TabController controller = new TabController(tabSet, tabPanel, initialTabToken);
    tabPanel.addSelectionHandler(controller);
    History.addValueChangeHandler(controller);

    RootPanel.get().add(tabPanel);
}

From source file:asquare.gwt.tk.demo.client.Demo.java

License:Apache License

public void onModuleLoad() {
    TabCollection tabs = new TabCollection();
    tabs.add("dropdown", "Drop Down Panel", new DropDownPanelPanel());
    tabs.add("debug", "Debug Utilities", new DebugPanel());
    tabs.add("misc", "Misc", new MiscPanel());

    BorderPanel outer = new BorderPanel();
    DOM.setAttribute(outer.getElement(), "id", "main");

    final TabPanel tabPanel = new TabPanel();
    tabPanel.setWidth("100%");
    for (int i = 0; i < tabs.size(); i++) {
        tabPanel.add(tabs.getWidget(i), tabs.getDescription(i));
    }//  w w  w. j a  v  a 2 s.  com
    outer.add(tabPanel);

    String initialTabToken = History.getToken();
    if (initialTabToken.length() == 0) {
        initialTabToken = tabs.getToken(0);
    }
    TabController controller = new TabController(tabs, tabPanel, initialTabToken);
    tabPanel.addTabListener(controller);
    History.addHistoryListener(controller);

    RootPanel.get().add(outer);
    Debug.enableSilently();
}

From source file:asquare.gwt.tkdemo.client.Demo.java

License:Apache License

public void onModuleLoad() {
    Debug.enableSilently();/*ww w . j av  a 2  s  .  com*/

    final AppPanelCollection panels = new DemoPanelCollection();

    String initialTabToken = History.getToken();
    int initialIndex = panels.getIndexForToken(initialTabToken);
    if (initialIndex == -1) {
        initialIndex = 0;
    }

    // use a table for border to work around bugs with 100% child width
    RowPanel outer = new RowPanel();
    DomUtil.setAttribute(outer, "id", "main");
    outer.setWidth("100%");

    ExposedCellPanel tabPanel = new ColumnPanel();
    tabPanel.setSize("100%", "100%");

    CTabBar tabbar = new CTabBar(new ListWidgetVTable(), new SideTabRenderer3());
    tabbar.removeController(tabbar.getController(CompositeCellViewHoverController.class));
    tabbar.setStyleName("DemoTabBar");
    History.addValueChangeHandler(new TabModelUpdateController(panels, tabbar.getListModel()));
    tabPanel.add(tabbar);
    tabPanel.setCellStyleName("DemoTabPanel-tabBar");

    tabPanel.add(new HTML("<h2 style='text-align: center; width: 100%; height: 100%;'>Loading...</h2>"));
    tabPanel.setCellStyleName("DemoTabPanel-tabBody");
    tabPanel.setCellWidth("100%");
    new TabBodyUpdateController(tabbar.getListModel(), tabPanel, panels);

    outer.add(tabPanel);
    RootPanel.get().add(outer);

    BrowserInfo browserInfo = (BrowserInfo) GWT.create(BrowserInfo.class);
    String compatMode = describeCompatMode();
    Label env = new Label(compatMode + " (" + browserInfo.getUserAgent() + ")");
    env.setStyleName("compatMode");
    outer.add(env);

    new DebugElementDumpInspector().install();

    /**
    * Incrementally add tabs to TabBar, allowing the UI to redraw to show
    * progress.
    */
    DeferredCommand.addCommand(new LoadUICommand(panels, tabbar, initialIndex));
}

From source file:br.org.olimpiabarbacena.client.Menu.java

License:Apache License

public Menu(Principal principal) {
    this.principal = principal;
    initWidget(uiBinder.createAndBindUi(this));

    // If the application starts with no history token, redirect to a new
    // 'acervo' state.
    String initToken = History.getToken();
    if ((initToken.length() == 0) || (initToken.equals("acervo"))) {
        History.newItem("acervo");
        onLinkAcervoClick(null);/*www  .  j a v a2  s. co m*/
    } else if (initToken.equals("membro")) {
        onLinkMembroClick(null);
    }

    // Now that we've setup our listener, fire the initial history state.
    History.fireCurrentHistoryState();
}

From source file:cc.alcina.framework.gwt.client.ClientBase.java

License:Apache License

protected void initInitialTokenHandler0() {
    initialHistoryToken = History.getToken();
    isFirstHistoryTokenHandlerRegistration = History.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override// ww  w  . j  a v  a2  s  .  c o m
        public void onValueChange(ValueChangeEvent<String> event) {
            if (History.getToken().equals(initialHistoryToken)) {
                return;
            }
            isFirstHistoryToken = false;
            if (isFirstHistoryTokenHandlerRegistration != null) {
                isFirstHistoryTokenHandlerRegistration.removeHandler();
                isFirstHistoryTokenHandlerRegistration = null;
            }
        }
    });
}

From source file:cc.alcina.framework.gwt.client.logic.AlcinaHistory.java

License:Apache License

public static void initialiseDebugIds() {
    String token = History.getToken();
    if (token != null) {
        AlcinaHistoryItem currentEvent = AlcinaHistory.get().parseToken(token);
        if (currentEvent != null) {
            for (String dbgId : AlcinaDebugIds.DEBUG_IDS) {
                if (currentEvent.hasParameter(dbgId)) {
                    AlcinaDebugIds.setFlag(dbgId);
                }/* w  w  w . j a  v a  2  s .c  o m*/
            }
        }
    }
}

From source file:cc.alcina.framework.gwt.client.logic.AlcinaHistory.java

License:Apache License

public I ensureEventFromCurrentToken() {
    onHistoryChanged(History.getToken());
    return getCurrentEvent();
}