Example usage for com.google.gwt.user.client Cookies setCookie

List of usage examples for com.google.gwt.user.client Cookies setCookie

Introduction

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

Prototype

public static void setCookie(String name, String value) 

Source Link

Document

Sets a cookie.

Usage

From source file:com.google.gwt.sample.dynatablerf.client.FavoritesManager.java

License:Apache License

public FavoritesManager(final RequestFactory requestFactory) {
    String cookie = Cookies.getCookie(COOKIE_NAME);
    if (cookie != null) {
        try {//from   w  w  w .  j  a va 2  s.c  o  m
            for (String fragment : cookie.split(",")) {
                if (fragment.length() == 0) {
                    continue;
                }
                EntityProxyId<PersonProxy> id = requestFactory.getProxyId(fragment);
                if (id != null) {
                    favoriteIds.add(id);
                }
            }
        } catch (NumberFormatException e) {
            // Not a big deal, start up without favorites
            favoriteIds.clear();
        }
    }

    Window.addWindowClosingHandler(new ClosingHandler() {
        public void onWindowClosing(ClosingEvent event) {
            StringBuilder sb = new StringBuilder();
            for (EntityProxyId<PersonProxy> id : favoriteIds) {
                sb.append(requestFactory.getHistoryToken(id)).append(",");
            }
            Cookies.setCookie(COOKIE_NAME, sb.toString());
        }
    });
}

From source file:com.hazelcast.monitor.client.AddClusterClickHandler.java

License:Open Source License

private void connectToCluster() {
    try {/*from w  w w .  jav  a 2 s  .  c  om*/
        final String groupName = groupNameBox.getText().trim();
        final String password = passBox.getText().trim();
        final String members = addressesBox.getText().trim();

        hazelcastService.connectCluster(groupName, password, members, new AsyncCallback<ClusterView>() {
            public void onSuccess(ClusterView clusterView) {
                Cookies.setCookie(HazelcastMonitor.GROUP_NAME_COOKIE_NAME, groupName);
                Cookies.setCookie(HazelcastMonitor.GROUP_PASSWORD_COOKIE_NAME, password);
                Cookies.setCookie(HazelcastMonitor.GROUP_MEMBERS_COOKIE_NAME, members);

                hazelcastMonitor.createAndAddClusterWidgets(clusterView);
            }

            public void onFailure(Throwable caught) {
                handleException(caught, lbError);
            }
        });
    } catch (ConnectionExceptoin e) {
        handleException(e, lbError);
    }
}

From source file:com.logicaldoc.gui.frontend.client.security.LoginPanel.java

public void onLoggedIn(GUISession session) {
    try {/*from w  ww  . j av a 2 s  .c  om*/
        licensingCanvas.destroy();
        messagesWindow.destroy();
        Session.get().init(session);
        Frontend.get().showMain();
    } catch (Throwable e) {
        SC.warn(e.getMessage());
    }

    // If the case, save the credentials into client cookies
    if ("true".equals(Session.get().getConfig("gui.savelogin"))) {
        Offline.put(Constants.COOKIE_SAVELOGIN, (String) rememberMe.getValueAsBoolean().toString());
        Offline.put(Constants.COOKIE_USER, rememberMe.getValueAsBoolean() ? (String) username.getValue() : "");
        Offline.put(Constants.COOKIE_PASSWORD,
                rememberMe.getValueAsBoolean() ? (String) password.getValue() : "");
    } else {
        Offline.put(Constants.COOKIE_SAVELOGIN, "false");
        Offline.put(Constants.COOKIE_USER, "");
        Offline.put(Constants.COOKIE_PASSWORD, "");
    }

    // In any case save the SID in the browser
    Offline.put(Constants.COOKIE_SID, session.getSid());
    Cookies.setCookie(Constants.COOKIE_SID, session.getSid());

    GUIUser user = session.getUser();
    if (user.getQuotaCount() >= user.getQuota() && user.getQuota() >= 0)
        Log.warn(I18N.message("quotadocsexceeded"), null);
}

From source file:com.qualogy.qafe.gwt.client.ui.renderer.events.EventFactory.java

License:Apache License

public static void createWindowSizeEvent(final String uuid, final String window, final WindowPanel sender) {
    sender.addResizeHandler(new ResizeHandler() {
        public void onResize(ResizeEvent event) {
            int height = event.getHeight();
            int width = event.getWidth();
            if (!("" + height).equals(Cookies.getCookie(uuid + "-height-" + window))
                    || !("" + width).equals(Cookies.getCookie(uuid + "-width-" + window))) {

                int absoluteLeft = sender.getAbsoluteLeft();
                int absoluteTop = sender.getAbsoluteTop();

                Cookies.setCookie(uuid + "-left" + "-" + window, String.valueOf(absoluteLeft));
                Cookies.setCookie(uuid + "-top" + "-" + window, String.valueOf(absoluteTop));
                sender.getWidget().setHeight(height + "");
                sender.getWidget().setWidth(width + "");

                if (sender.getWidget() != null && (sender.getWidget()) instanceof QRootPanel) {
                    QRootPanel qRootPanel = (QRootPanel) (sender.getWidget());
                    if (qRootPanel.getRootPanel() != null) {
                        qRootPanel.getRootPanel().setHeight(height + "");
                        qRootPanel.getRootPanel().setWidth(width + "");
                    }//from ww w  .j a v a 2s .c o m
                    ScrollPanel sp = (ScrollPanel) qRootPanel.getRootPanel();
                    int menuHeight = 0;
                    int toolbarHeight = 0;
                    int extra = 1;
                    if (qRootPanel.getMenuBar() != null && qRootPanel.getToolbar() == null) {
                        menuHeight = qRootPanel.getMenuBar().getOffsetHeight();
                        extra = 10;
                    }
                    if (qRootPanel.getToolbar() != null && qRootPanel.getMenuBar() == null) {
                        toolbarHeight = qRootPanel.getToolbar().getOffsetHeight();
                        extra = -1;
                    }
                    if (qRootPanel.getToolbar() != null && qRootPanel.getMenuBar() != null) {
                        extra = 58;
                    }
                    int headerHeight = sender.getHeader().getOffsetHeight();
                    sp.setHeight((height - menuHeight - toolbarHeight - headerHeight - extra) + "");
                    sp.setWidth(width + "");
                }
                // It is not necessary to pack the window after changing
                // the
                // width and/or the height
                // sender.pack();
                //               }
            }
        }
    });
}

From source file:com.seanchenxi.resteasy.autobean.client.RESTRequest.java

License:Apache License

/**
 * Sets the given cookie in the current document when executing the request. Beware that this will be persistent in your browser.
 *//*  ww  w. j a  v  a2  s  .c  o m*/
public RESTRequest<T> addCookie(String name, String value) {
    Cookies.setCookie(name, value);
    return this;
}

From source file:com.smvp4g.mvp.client.core.utils.LoginUtils.java

License:Open Source License

/**
 * Save user login information to cookies.
 *
 * @param userName must be not null//from  w  ww.  j  a  v a  2  s .  c  o  m
 * @param userRole must be not null
 */
public static void login(String userName, String userRole) {
    assert userName != null;
    assert userRole != null;
    Date expires = new Date(System.currentTimeMillis() + DURATION);
    Cookies.setCookie(SESSION_ID, userName);
    Cookies.setCookie(USER_NAME, userName);
    Cookies.setCookie(ROLE, userRole);
}

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

License:Apache License

@Override
public void init() {
    panel = new FlowPanel();
    if (!quietMode) {
        DOM.appendChild(getContainerElement(), caption);
        setWidget(panel);//from w w  w . j a  v  a  2  s .com
        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);
        actions.add(connectorStats);
        connectorStats.setTitle("Show connector statistics for client");
        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);
        addDevMode();
        addSuperDevMode();

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

        panel.add(actions);

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

        clear.addClickHandler(new ClickHandler() {
            @Override
            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() {
            @Override
            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() {
            @Override
            public void onClick(ClickEvent event) {
                for (ApplicationConnection applicationConnection : ApplicationConfiguration
                        .getRunningApplications()) {
                    applicationConnection.forceLayout();
                }
            }
        });

        analyzeLayout.addClickHandler(new ClickHandler() {
            @Override
            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() {
            @Override
            public void onClick(ClickEvent event) {
                String pos = getAbsoluteLeft() + "," + getAbsoluteTop() + "," + getOffsetWidth() + ","
                        + getOffsetHeight() + "," + autoScroll.getValue();
                Cookies.setCookie(POS_COOKIE_NAME, pos);
            }
        });

        highlight.addClickHandler(new ClickHandler() {

            @Override
            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));

            }
        });

    }
    connectorStats.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            for (ApplicationConnection a : ApplicationConfiguration.getRunningApplications()) {
                dumpConnectorInfo(a);
            }
        }
    });
    log("Starting Vaadin client side engine. Widgetset: " + GWT.getModuleName());

    log("Widget set is built on version: " + Version.getFullVersion());

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

}

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);// www.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:com.webwoz.client.client.WebWOZClient.java

License:Apache License

private void logout() {
    Cookies.setCookie("loggedin", "0");
    this.login = "0";
    setLoginScreen(0);/*from ww w .  j  a  v a2s  . co  m*/
    stopEntry();
    stopSession();
}

From source file:com.webwoz.client.client.WebWOZClient.java

License:Apache License

private void login() {

    String sql = "Select * from user inner join experimentuser where user.id = experimentuser.userid and user.name = '"
            + userTextBox.getText() + "' and user.pw = '" + pwTextBox.getText() + "' and user.role = 2";

    // Initialize the service remote procedure call
    if (databaseAccessSvc == null) {
        databaseAccessSvc = GWT.create(DatabaseAccess.class);
    }//from   w ww. jav a 2 s .  c  om

    AsyncCallback<String[][]> callback = new AsyncCallback<String[][]>() {
        public void onFailure(Throwable caught) {

        }

        public void onSuccess(String[][] result) {

            if (result != null) {

                user = (Integer.parseInt(result[0][0]));
                experiment = (Integer.parseInt(result[0][4]));
                // loginPanel.setVisible(false);
                setLoginScreen(1);

                loginMessage.setText("");
                loadScreen();

                // set cookies
                Cookies.setCookie("user", "" + user + "");
                Cookies.setCookie("experiment", "" + experiment + "");
                getExperimentSettings();

            } else {
                // clear login if no user is found
                setLoginScreen(0);
                loginMessage.setText("Sorry! Wrong user name or password ");
                Cookies.setCookie("loggedin", "0");
            }
        }
    };

    databaseAccessSvc.retrieveData(sql, callback);
}