Example usage for com.google.gwt.http.client UrlBuilder setParameter

List of usage examples for com.google.gwt.http.client UrlBuilder setParameter

Introduction

In this page you can find the example usage for com.google.gwt.http.client UrlBuilder setParameter.

Prototype

public UrlBuilder setParameter(String key, String... values) 

Source Link

Document

Set a query parameter to a list of values.

Usage

From source file:com.allen_sauer.gwt.voices.crowd.client.VoicesCrowd.java

License:Apache License

private void renderSummary(List<TestResultSummary> list, boolean includeUserAgentDetail) {
    HashSet<TestResults> testResultsSet = getUniqueTestResults(list);

    // Build HTML table
    StringBuffer html = new StringBuffer();

    if (!embed) {
        html.append("<div style='font-weight: bold; font-size: 1.2em;'>")
                .append("<a href='https://github.com/fredsa/gwt-voices'>gwt-voices</a>")
                .append(" - Sound for your Google Web Toolkit projects.</div>")
                .append("<div style='font-style: italic; margin-bottom: 1em;'>by Fred Sauer</div>");

        html.append("<h3>Your user agent</h3>");
        html.append("<div style='margin-left: 1.5em;'>").append(myUserAgent.toString()).append("</div>");

        html.append("<h3>Your browser</h3>");
        String prettyUserAgent = myTestResultSummary.getPrettyUserAgent();
        html.append("<div style='margin-left: 1.5em;'>").append(formatPrettyUserAgentOrNull(prettyUserAgent))
                .append("</div>");

        html.append("<h3 style='margin-top: 3em;'>HTML5 MIME Type support by User-Agent</h3>");
    }//from   w w w  .j av a 2  s.c  om
    UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
    urlBuilder = detail ? urlBuilder.removeParameter("detail") : urlBuilder.setParameter("detail", "1");
    String text = (detail ? "Hide" : "Show full") + " user agent values";
    html.append("<a href='" + urlBuilder.buildString() + "'>" + text + "</a>");

    html.append("<table>");

    for (TestResults testResults : testResultsSet) {
        makeHeaderRow(html, includeUserAgentDetail);
        HashSet<Tuple<String>> tuples = getMatchingTuples(testResults, list, includeUserAgentDetail);

        int count = 0;
        for (Tuple<String> tuple : tuples) {
            count++;
            html.append("<tr>");
            boolean highlightRow = makeTuple(myTestResultSummary, includeUserAgentDetail).equals(tuple);
            makeUserAgentCells(html, tuple, highlightRow);

            if (count == 1) {
                makeResultCells(html, testResults, tuples.size());
            }
            html.append("</tr>");
        }
    }

    html.append("</table>");
    rootPanel.add(new HTML(html.toString()));
}

From source file:com.google.livingstories.client.util.UriParser.java

License:Apache License

public static UrlBuilder parse(String url) {
    UrlBuilder urlBuilder = new UrlBuilder();

    // This utility only needs to support http urls.
    urlBuilder.setProtocol("http");
    urlBuilder.setHost(matchHost(url));/* www . j  a  v  a 2 s .co m*/
    urlBuilder.setPath(matchPath(url));

    String queryString = matchQuery(url);
    if (!queryString.isEmpty()) {
        for (String params : queryString.split("&")) {
            // Doesn't work for urls with multiple values on the same key.
            // But we don't currently need that.
            String[] pair = params.split("=");
            urlBuilder.setParameter(pair[0], pair.length > 1 ? pair[1] : "");
        }
    }

    return urlBuilder;
}

From source file:com.mecatran.otp.gwt.client.controller.PlannerState.java

License:Open Source License

private void buildUrl() {
    UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
    PlanRequestBean planRequest = getPlanRequestBean();
    if (planRequest.getDeparture().isSet(false))
        urlBuilder.setParameter("origin", getLocationAsStringParam(planRequest.getDeparture()));
    if (planRequest.getArrival().isSet(false))
        urlBuilder.setParameter("destination", getLocationAsStringParam(planRequest.getArrival()));
    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd@HH:mm");
    urlBuilder.setParameter(planRequest.isDateDeparture() ? "depart" : "arrive",
            dtf.format(planRequest.getDate()));
    if (planRequest.isWheelchairAccessible())
        urlBuilder.setParameter("wheelchair", "y");
    Set<TransportMode> modes = planRequest.getModes();
    String modesStr = "";
    for (TransportMode mode : modes) {
        modesStr = modesStr + mode.toString() + ",";
    }//from   ww  w .j av a 2  s .  co  m
    modesStr = modesStr.substring(0, modesStr.length() - 1);
    urlBuilder.setParameter("modes", modesStr);
    url = urlBuilder.buildString();
}

From source file:com.vaadin.client.SuperDevMode.java

License:Apache License

protected static void redirect(boolean devModeOn) {
    UrlBuilder createUrlBuilder = Location.createUrlBuilder();
    if (!devModeOn) {
        createUrlBuilder.removeParameter("superdevmode");
    } else {/*from w w w.  jav  a2 s. c o m*/
        createUrlBuilder.setParameter("superdevmode", "");
    }

    Location.assign(createUrlBuilder.buildString());

}

From source file:com.vaadin.client.VDebugConsole.java

License:Apache License

private void addDevMode() {
    actions.add(devMode);//from   ww w  . jav a 2 s .c o m
    if (Location.getParameter("gwt.codesvr") != null) {
        devMode.setValue(true);
    }
    devMode.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (devMode.getValue()) {
                addHMParameter();
            } else {
                removeHMParameter();
            }
        }

        private void addHMParameter() {
            UrlBuilder createUrlBuilder = Location.createUrlBuilder();
            createUrlBuilder.setParameter("gwt.codesvr", "localhost:9997");
            Location.assign(createUrlBuilder.buildString());
        }

        private void removeHMParameter() {
            UrlBuilder createUrlBuilder = Location.createUrlBuilder();
            createUrlBuilder.removeParameter("gwt.codesvr");
            Location.assign(createUrlBuilder.buildString());

        }
    });
}

From source file:com.vaadin.terminal.gwt.client.VDebugConsole.java

License:Open Source License

public void init() {
    panel = new FlowPanel();
    if (!quietMode) {
        DOM.appendChild(getContainerElement(), caption);
        setWidget(panel);/*from   w ww . j  a v  a  2 s .  co m*/
        caption.setClassName("v-debug-console-caption");
        setStyleName("v-debug-console");
        getElement().getStyle().setZIndex(20000);
        getElement().getStyle().setOverflow(Overflow.HIDDEN);

        sinkEvents(Event.ONDBLCLICK);

        sinkEvents(Event.MOUSEEVENTS);

        panel.setStyleName("v-debug-console-content");

        caption.setInnerHTML("Debug window");
        caption.getStyle().setHeight(25, Unit.PX);
        caption.setTitle(help);

        show();
        setToDefaultSizeAndPos();

        actions = new HorizontalPanel();
        Style style = actions.getElement().getStyle();
        style.setPosition(Position.ABSOLUTE);
        style.setBackgroundColor("#666");
        style.setLeft(135, Unit.PX);
        style.setHeight(25, Unit.PX);
        style.setTop(0, Unit.PX);

        actions.add(clear);
        actions.add(restart);
        actions.add(forceLayout);
        actions.add(analyzeLayout);
        actions.add(highlight);
        highlight.setTitle(
                "Select a component and print details about it to the server log and client side console.");
        actions.add(savePosition);
        savePosition.setTitle("Saves the position and size of debug console to a cookie");
        actions.add(autoScroll);
        actions.add(hostedMode);
        if (Location.getParameter("gwt.codesvr") != null) {
            hostedMode.setValue(true);
        }
        hostedMode.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                if (hostedMode.getValue()) {
                    addHMParameter();
                } else {
                    removeHMParameter();
                }
            }

            private void addHMParameter() {
                UrlBuilder createUrlBuilder = Location.createUrlBuilder();
                createUrlBuilder.setParameter("gwt.codesvr", "localhost:9997");
                Location.assign(createUrlBuilder.buildString());
            }

            private void removeHMParameter() {
                UrlBuilder createUrlBuilder = Location.createUrlBuilder();
                createUrlBuilder.removeParameter("gwt.codesvr");
                Location.assign(createUrlBuilder.buildString());

            }
        });

        autoScroll.setTitle("Automatically scroll so that new messages are visible");

        panel.add(actions);

        panel.add(new HTML("<i>" + help + "</i>"));

        clear.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                int width = panel.getOffsetWidth();
                int height = panel.getOffsetHeight();
                panel = new FlowPanel();
                panel.setPixelSize(width, height);
                panel.setStyleName("v-debug-console-content");
                panel.add(actions);
                setWidget(panel);
            }
        });

        restart.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {

                String queryString = Window.Location.getQueryString();
                if (queryString != null && queryString.contains("restartApplications")) {
                    Window.Location.reload();
                } else {
                    String url = Location.getHref();
                    String separator = "?";
                    if (url.contains("?")) {
                        separator = "&";
                    }
                    if (!url.contains("restartApplication")) {
                        url += separator;
                        url += "restartApplication";
                    }
                    if (!"".equals(Location.getHash())) {
                        String hash = Location.getHash();
                        url = url.replace(hash, "") + hash;
                    }
                    Window.Location.replace(url);
                }

            }
        });

        forceLayout.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                // TODO for each client in appconf force layout
                // VDebugConsole.this.client.forceLayout();
            }
        });

        analyzeLayout.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                List<ApplicationConnection> runningApplications = ApplicationConfiguration
                        .getRunningApplications();
                for (ApplicationConnection applicationConnection : runningApplications) {
                    applicationConnection.analyzeLayouts();
                }
            }
        });
        analyzeLayout.setTitle("Analyzes currently rendered view and "
                + "reports possible common problems in usage of relative sizes."
                + "Will cause server visit/rendering of whole screen and loss of"
                + " all non committed variables form client side.");

        savePosition.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                String pos = getAbsoluteLeft() + "," + getAbsoluteTop() + "," + getOffsetWidth() + ","
                        + getOffsetHeight() + "," + autoScroll.getValue();
                Cookies.setCookie(POS_COOKIE_NAME, pos);
            }
        });

        highlight.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                final Label label = new Label("--");
                log("<i>Use mouse to select a component or click ESC to exit highlight mode.</i>");
                panel.add(label);
                highlightModeRegistration = Event.addNativePreviewHandler(new HighlightModeHandler(label));

            }
        });

    }
    log("Starting Vaadin client side engine. Widgetset: " + GWT.getModuleName());

    log("Widget set is built on version: " + ApplicationConfiguration.VERSION);

    logToDebugWindow("<div class=\"v-theme-version v-theme-version-"
            + ApplicationConfiguration.VERSION.replaceAll("\\.", "_") + "\">Warning: widgetset version "
            + ApplicationConfiguration.VERSION + " does not seem to match theme version </div>", true);

}

From source file:cz.cas.lib.proarc.webapp.client.Editor.java

License:Open Source License

/**
 * Switches the application locale./*from  w w w.jav a2s  . c  o  m*/
 * @param locale new locale
 */
private void switchLocale(String locale) {
    UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
    urlBuilder.setParameter(LOCALE_ATTRIBUTE, locale);
    String url = urlBuilder.buildString();
    Window.Location.assign(url);
}

From source file:cz.incad.kramerius.editor.client.presenter.EditorPresenter.java

License:Open Source License

@Override
public void onLanguagesClick(int index) {
    final String selection = Languages.getLocaleName(index);

    Runnable action = new Runnable() {

        @Override/* w ww . ja v a 2  s  .c  o  m*/
        public void run() {
            // XXX it would be nice to keep open editors
            UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
            urlBuilder.setParameter("locale", selection);
            String url = urlBuilder.buildString();
            Window.Location.replace(url);
        }
    };

    saveAttempt(action);
}

From source file:eu.riscoss.client.riskanalysis.RiskAnalysisModule.java

License:Apache License

protected void runAnalysis() {

    String pagename = Window.Location.getPath().substring(0, Window.Location.getPath().lastIndexOf("/"));

    pagename += "/report.jsp";

    UrlBuilder ub = Window.Location.createUrlBuilder();

    ub.setPath(pagename);//from  www  .jav  a2 s  .  c o m
    ub.setParameter("target", entityLabel.getText());
    ub.setParameter("rc", rcLabel.getText());
    Window.Location.replace(ub.buildString());
}

From source file:mx.org.pescadormvp.core.client.placesandactivities.PescadorMVPPlaceMapperImpl.java

License:Open Source License

@Override
public void setupURLInfo(PescadorMVPPlace place) {

    String historyTokenFromPlaceObj = place.getHistoryToken();
    String historyToken = historyTokenFromPlaceObj == null ? getToken(place) : historyTokenFromPlaceObj;

    place.setHistoryToken(historyToken);

    PescadorMVPLocale newLocale = place.getNewLocale();
    if (newLocale == null) {
        place.setURL("#" + historyToken);

        // instructs Session not to reload the whole app when going here
        place.setRequiresReload(false);/*from   w  ww. ja v  a  2  s .c o  m*/

    } else {
        // TODO check that the locale is not the same as the current one (?)
        String queryParam = LocaleInfo.getLocaleQueryParam();
        UrlBuilder builder = Location.createUrlBuilder();
        builder.setParameter(queryParam, newLocale.getLocaleName());
        builder.setHash(historyToken);
        place.setURL(builder.buildString());

        // in this case, do reload the whole app when going here
        place.setRequiresReload(true);

    }
}