Search in sources :

Example 1 with UrlBuilder

use of com.google.gwt.http.client.UrlBuilder in project perun by CESNET.

the class UiElements method getToggleLanguageButton.

/**
	 * Setup and return button with "change language" ability
	 *
	 * @return button widget
	 */
public ToggleButton getToggleLanguageButton() {
    // translation not supported
    if (Utils.getNativeLanguage().isEmpty()) {
        languageButton.setVisible(false);
        languageButton.setEnabled(false);
        return languageButton;
    }
    // display for perun admin only in WebGui.class
    languageButton.setVisible(true);
    if (!LocaleInfo.getCurrentLocale().getLocaleName().equals(Utils.getNativeLanguage().get(0))) {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToCzech(Utils.getNativeLanguage().get(1)));
    } else {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToEnglish());
    }
    languageButton.setPixelSize(16, 16);
    languageButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Confirm conf = new Confirm(languageButton.getTitle(), new HTML(WidgetTranslation.INSTANCE.changeLanguageConfirmText()), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    // on OK
                    // set proper locale
                    String localeName = LocaleInfo.getCurrentLocale().getLocaleName();
                    if (!localeName.equals(Utils.getNativeLanguage().get(0))) {
                        localeName = Utils.getNativeLanguage().get(0);
                        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToEnglish());
                    } else {
                        localeName = "en";
                        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToCzech(Utils.getNativeLanguage().get(1)));
                    }
                    // set locale param to URL or local storage
                    try {
                        Storage localStorage;
                        localStorage = Storage.getLocalStorageIfSupported();
                        if (localStorage != null) {
                            localStorage.setItem("urn:perun:gui:preferences:language", localeName);
                            Window.Location.reload();
                        } else {
                            UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", localeName);
                            Window.Location.replace(builder.buildString());
                        }
                    } catch (Exception ex) {
                        UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", localeName);
                        Window.Location.replace(builder.buildString());
                    }
                    // unclick button
                    languageButton.setDown(false);
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    // on CANCEL
                    languageButton.setDown(false);
                }
            }, true);
            conf.setNonScrollable(true);
            conf.show();
        }
    });
    return languageButton;
}
Also used : Storage(com.google.gwt.storage.client.Storage) UrlBuilder(com.google.gwt.http.client.UrlBuilder)

Example 2 with UrlBuilder

use of com.google.gwt.http.client.UrlBuilder in project gerrit by GerritCodeReview.

the class Gerrit method addProjectLink.

private static LinkMenuItem addProjectLink(LinkMenuBar m, TopMenuItem item) {
    LinkMenuItem i = new ProjectLinkMenuItem(item.getName(), item.getUrl()) {

        @Override
        protected void onScreenLoad(Project.NameKey project) {
            String p = panel.replace(PROJECT_NAME_MENU_VAR, URL.encodeQueryString(project.get()));
            if (!panel.startsWith("/x/") && !isAbsolute(panel)) {
                UrlBuilder builder = new UrlBuilder();
                builder.setProtocol(Location.getProtocol());
                builder.setHost(Location.getHost());
                String port = Location.getPort();
                if (port != null && !port.isEmpty()) {
                    builder.setPort(Integer.parseInt(port));
                }
                builder.setPath(Location.getPath());
                p = builder.buildString() + p;
            }
            getElement().setPropertyString("href", p);
        }

        @Override
        public void go() {
            String href = getElement().getPropertyString("href");
            if (href.startsWith("#")) {
                super.go();
            } else {
                Window.open(href, getElement().getPropertyString("target"), "");
            }
        }
    };
    if (item.getTarget() != null && !item.getTarget().isEmpty()) {
        i.getElement().setAttribute("target", item.getTarget());
    }
    if (item.getId() != null) {
        i.getElement().setAttribute("id", item.getId());
    }
    m.addItem(i);
    return i;
}
Also used : ProjectLinkMenuItem(com.google.gerrit.client.ui.ProjectLinkMenuItem) LinkMenuItem(com.google.gerrit.client.ui.LinkMenuItem) ProjectLinkMenuItem(com.google.gerrit.client.ui.ProjectLinkMenuItem) UrlBuilder(com.google.gwt.http.client.UrlBuilder)

Example 3 with UrlBuilder

use of com.google.gwt.http.client.UrlBuilder in project gerrit by GerritCodeReview.

the class Gerrit method selfRedirect.

public static String selfRedirect(String suffix) {
    // Clean up the path. Users seem to like putting extra slashes into the URL
    // which can break redirections by misinterpreting at either client or server.
    String path = Location.getPath();
    if (path == null || path.isEmpty()) {
        path = "/";
    } else {
        while (path.startsWith("//")) {
            path = path.substring(1);
        }
        while (path.endsWith("//")) {
            path = path.substring(0, path.length() - 1);
        }
        if (!path.endsWith("/")) {
            path = path + "/";
        }
    }
    if (suffix != null) {
        while (suffix.startsWith("/")) {
            suffix = suffix.substring(1);
        }
        path += suffix;
    }
    UrlBuilder builder = new UrlBuilder();
    builder.setProtocol(Location.getProtocol());
    builder.setHost(Location.getHost());
    String port = Location.getPort();
    if (port != null && !port.isEmpty()) {
        builder.setPort(Integer.parseInt(port));
    }
    builder.setPath(path);
    return builder.buildString();
}
Also used : UrlBuilder(com.google.gwt.http.client.UrlBuilder)

Example 4 with UrlBuilder

use of com.google.gwt.http.client.UrlBuilder in project rstudio by rstudio.

the class WebWindowOpener method openSatelliteWindow.

public void openSatelliteWindow(GlobalDisplay globalDisplay, String viewName, int width, int height, NewWindowOptions options) {
    // build url
    UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
    urlBuilder.setParameter("view", viewName);
    // setup options
    if (options == null)
        options = new NewWindowOptions();
    options.setName(SatelliteUtils.getSatelliteWindowName(viewName));
    options.setFocus(true);
    // open window (force web codepath b/c desktop needs this so
    // that window.opener is hooked up)
    webOpenMinimalWindow(globalDisplay, urlBuilder.buildString(), options, width, height, false);
}
Also used : NewWindowOptions(org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions) UrlBuilder(com.google.gwt.http.client.UrlBuilder)

Example 5 with UrlBuilder

use of com.google.gwt.http.client.UrlBuilder in project perun by CESNET.

the class ApplicationFormPage method prepareToggleLanguageButton.

/**
	 * Prepares the buttons for local languages
	 */
private void prepareToggleLanguageButton() {
    languageButton = new PushButton(new Image(SmallIcons.INSTANCE.locateIcon()));
    // translation not supported
    if (Utils.getNativeLanguage().isEmpty()) {
        languageButton.setEnabled(false);
        languageButton.setVisible(false);
        return;
    }
    if (!LocaleInfo.getCurrentLocale().getLocaleName().equals(Utils.getNativeLanguage().get(0))) {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToCzech(Utils.getNativeLanguage().get(2)));
    } else {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToEnglish());
    }
    languageButton.setStyleName("gwt-Button");
    languageButton.setPixelSize(17, 17);
    languageButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Confirm conf = new Confirm(languageButton.getTitle(), new HTML(ApplicationMessages.INSTANCE.changeLanguageText()), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    String localeName = LocaleInfo.getCurrentLocale().getLocaleName();
                    if (!localeName.equals(Utils.getNativeLanguage().get(0))) {
                        UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", Utils.getNativeLanguage().get(0));
                        Window.Location.replace(builder.buildString());
                    } else {
                        UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", "en");
                        Window.Location.replace(builder.buildString());
                    }
                // on OK
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                // on CANCEL
                }
            }, true);
            conf.setNonScrollable(true);
            conf.show();
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) JSONString(com.google.gwt.json.client.JSONString) UrlBuilder(com.google.gwt.http.client.UrlBuilder)

Aggregations

UrlBuilder (com.google.gwt.http.client.UrlBuilder)6 LinkMenuItem (com.google.gerrit.client.ui.LinkMenuItem)1 ProjectLinkMenuItem (com.google.gerrit.client.ui.ProjectLinkMenuItem)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 JSONString (com.google.gwt.json.client.JSONString)1 Storage (com.google.gwt.storage.client.Storage)1 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)1 NewWindowOptions (org.rstudio.studio.client.common.GlobalDisplay.NewWindowOptions)1