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, Date expires) 

Source Link

Document

Sets a cookie.

Usage

From source file:com.googlecode.gwtphonegap.client.device.DeviceBrowserImpl.java

License:Apache License

@Override
public String getUuid() {
    String value = Cookies.getCookie("gwt-phonegap-uuid");
    if (value == null) {
        long end = System.currentTimeMillis() + 60l * 60l * 24l * 356l * 1000l;
        value = getPseudoGUUID();//from w  ww .  ja  v  a  2  s. c  om
        Cookies.setCookie("gwt-phonegap-uuid", value, new Date(end));

    }
    return value;
}

From source file:com.griddynamics.jagger.facade.client.JaggerFacade.java

License:Open Source License

/**
 * This is the entry point method./*from  ww  w.  j a  v  a2s  .c  o m*/
 */
public void onModuleLoad() {
    userId = Cookies.getCookie("jagger_facade_user_id");
    if (userId == null) {
        JaggerFacadeService.App.getInstance().getUserId(new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable caught) {
            }

            @Override
            public void onSuccess(String result) {
                userId = result;
                Cookies.setCookie("jagger_facade_user_id", result,
                        new Date(System.currentTimeMillis() + 157680000000L));
                init();
            }
        });
    } else {
        init();
    }
}

From source file:com.gwtmodel.table.Utils.java

License:Apache License

public static void SetCookie(String key, String value) {
    // today/*from w  w  w .  java2s.com*/
    Date today = new Date();
    Date exp = DateUtil.addDaysD(today, 100);
    Cookies.setCookie(jPrefix() + key, value, exp);
}

From source file:com.moesol.gwt.maps.client.MapView.java

License:Open Source License

private void recordCenter() {
    String centerLng = Double.toString(getCenter().getLambda(AngleUnit.DEGREES));
    String centerLat = Double.toString(getCenter().getPhi(AngleUnit.DEGREES));
    Date expire = new Date(new Date().getTime() + ONE_YEAR);
    Cookies.setCookie("centerLng", centerLng, expire);
    Cookies.setCookie("centerLat", centerLat, expire);
}

From source file:com.nanosim.client.content.other.CwCookies.java

License:Apache License

/**
 * Initialize this example.//from  w  ww .  j a  va2 s  .  c  om
 */
@NanosimSource
@Override
public Widget onInitialize() {
    // Create the panel used to layout the content
    Grid mainLayout = new Grid(3, 3);

    // Display the existing cookies
    existingCookiesBox = new ListBox();
    Button deleteCookieButton = new Button(constants.cwCookiesDeleteCookie());
    deleteCookieButton.addStyleName("sc-FixedWidthButton");
    mainLayout.setHTML(0, 0, "<b>" + constants.cwCookiesExistingLabel() + "</b>");
    mainLayout.setWidget(0, 1, existingCookiesBox);
    mainLayout.setWidget(0, 2, deleteCookieButton);

    // Display the name of the cookie
    cookieNameBox = new TextBox();
    mainLayout.setHTML(1, 0, "<b>" + constants.cwCookiesNameLabel() + "</b>");
    mainLayout.setWidget(1, 1, cookieNameBox);

    // Display the name of the cookie
    cookieValueBox = new TextBox();
    Button setCookieButton = new Button(constants.cwCookiesSetCookie());
    setCookieButton.addStyleName("sc-FixedWidthButton");
    mainLayout.setHTML(2, 0, "<b>" + constants.cwCookiesValueLabel() + "</b>");
    mainLayout.setWidget(2, 1, cookieValueBox);
    mainLayout.setWidget(2, 2, setCookieButton);

    // Add a handler to set the cookie value
    setCookieButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String name = cookieNameBox.getText();
            String value = cookieValueBox.getText();
            Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT);

            // Verify the name is valid
            if (name.length() < 1) {
                Window.alert(constants.cwCookiesInvalidCookie());
                return;
            }

            // Set the cookie value
            Cookies.setCookie(name, value, expires);
            refreshExistingCookies(name);
        }
    });

    // Add a handler to select an existing cookie
    existingCookiesBox.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            updateExstingCookie();
        }
    });

    // Add a handler to delete an existing cookie
    deleteCookieButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            int selectedIndex = existingCookiesBox.getSelectedIndex();
            if (selectedIndex > -1 && selectedIndex < existingCookiesBox.getItemCount()) {
                String cookieName = existingCookiesBox.getValue(selectedIndex);
                Cookies.removeCookie(cookieName);
                existingCookiesBox.removeItem(selectedIndex);
                updateExstingCookie();
            }
        }
    });

    // Return the main layout
    refreshExistingCookies(null);
    return mainLayout;
}

From source file:com.sun.labs.aura.dbbrowser.client.viz.Util.java

License:Open Source License

public static void setStatDisplayCodes(List<String> codes) {
    StringBuffer sb = new StringBuffer();
    for (Iterator<String> it = codes.iterator(); it.hasNext();) {
        sb.append(it.next());/*from  w  ww.j  a v a 2s  . c  o m*/
        if (it.hasNext()) {
            sb.append(":");
        }
    }
    Date exp = new Date();
    long aLongTime = (1000 * 60 * 60 * 24 * 365 * 10); // roughly 10 years
    Cookies.setCookie("STAT_CODES", sb.toString(), new Date(exp.getTime() + aLongTime));
}

From source file:com.tasktop.c2c.server.profile.web.ui.client.view.components.account.presenter.AccountActivity.java

License:Open Source License

@Override
public void saveProfile() {
    ProfileEntryPoint.getInstance().getProfileService().updateProfile(profile,
            new AsyncCallbackSupport<Credentials>() {
                @Override/*  www.j  a  va 2s  . c o m*/
                public void success(Credentials result) {
                    ProfileEntryPoint.getInstance().getAppState().setCredentials(result);

                    profile = result.getProfile();
                    updateView();
                    ProfileGinjector.get.instance().getNotifier()
                            .displayMessage(Message.createSuccessMessage(profileMessages.profileUpdated()));
                    if (!originalEmail.equals(profile.getEmail())) {
                        ProfileGinjector.get.instance().getNotifier().displayMessage(
                                Message.createSuccessMessage(profileMessages.verificationEmailSent()));
                        originalEmail = profile.getEmail();
                    }
                    if (result.getProfile().getLanguage() != null && !result.getProfile().getLanguage()
                            .equals(LocaleInfo.getCurrentLocale().getLocaleName())) {
                        // We'd prefer to have the GwtLocaleCookieFilter be the only place where this cookie is set,
                        // but in this instance we find that when we refresh the page, the security context has not
                        // yet been updated by the AuthenticationRefreshFilter, so GwtLocaleCookieFilter uses the
                        // previous language value in the cookie. Since we cannot refresh twice, we instead set the
                        // cookie here.
                        Cookies.setCookie(LocaleInfo.getLocaleCookieName(), result.getProfile().getLanguage(),
                                new Date(System.currentTimeMillis() + (1209600 * 1000)));
                        // reload with the new language
                        Window.Location.reload();
                    }
                }
            });
}

From source file:com.tensegrity.wpalo.client.ui.dialog.LoginDialog.java

License:Open Source License

private final void addInputFields() {
    KeyListener keyListener = new KeyListener() {
        public void componentKeyUp(ComponentEvent event) {
            if ((event.isControlKey() && event.isShiftKey()) || (event.isControlKey() && event.isAltKey())) {
                int keyCode = event.getKeyCode();
                switch (keyCode) {
                case 65:
                    login.setValue("admin");
                    password.setValue("admin");
                    onSubmit();//from   w ww.ja va2  s .com
                    return;
                case 68:
                    login.setValue("direct-link");
                    password.setValue("direct-link");
                    onSubmit();
                    return;
                case 69:
                    login.setValue("editor");
                    password.setValue("editor");
                    onSubmit();
                    return;
                case 80:
                    login.setValue("poweruser");
                    password.setValue("poweruser");
                    onSubmit();
                    return;
                case 86:
                    login.setValue("viewer");
                    password.setValue("viewer");
                    onSubmit();
                    return;
                }
            }
            if (event.getKeyCode() == 13) {// enter pressed
                if (event.component.equals(login))
                    password.focus();
                else if (event.component.equals(password))
                    onSubmit();
            }
            validate();
        }
    };

    login = new TextField<String>();
    login.setFieldLabel(constants.loginName());
    login.setEmptyText(constants.loginName());
    login.addKeyListener(keyListener);
    login.setAllowBlank(false);
    // login.setMinLength(2);
    add(login);

    password = new TextField<String>();
    password.setPassword(true);
    password.setFieldLabel(constants.password());
    password.setEmptyText(constants.password());
    password.addKeyListener(keyListener);
    password.setAllowBlank(false);
    // password.setMinLength(2);
    add(password);

    languageList = new LanguageBox();
    currentLanguage = languageList.getCurrentLanguage();
    languageList.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<LanguageData>>() {
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<LanguageData>> se) {
            if (currentLanguage != null && currentLanguage.getValue() != null
                    && currentLanguage.getValue().equals(se.getSelectedItem().getValue())) {
                return;
            }
            currentLanguage = se.getSelectedItem();
            String locale = se.getSelectedItem().getValue().id;
            Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l);
            Cookies.setCookie("locale", locale, date);
            // TODO storeLoginPasswordTheme()
            String url = Window.Location.getHref();
            int index;
            if ((index = url.indexOf("locale=")) != -1) {
                int i2 = url.indexOf("&", index);
                if (i2 == -1) {
                    url = url.substring(0, index) + "locale=" + locale;
                } else {
                    url = url.substring(0, index) + "locale=" + locale + url.substring(i2);
                }
            } else {
                if (url.indexOf("?") != -1) {
                    url += "&locale=" + locale;
                } else {
                    url += "?locale=" + locale;
                }
            }
            Window.Location.assign(url);
            // Window.Location.reload();
        }
    });
    add(languageList);

    themeList = new ThemeBox();
    currentTheme = themeList.getCurrentTheme();
    themeList.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<ThemeData>>() {
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<ThemeData>> se) {
            if (currentTheme != null && currentTheme.getValue() != null
                    && currentTheme.getValue().equals(se.getSelectedItem().getValue())) {
                return;
            }
            currentTheme = se.getSelectedItem();
            String themeId = se.getSelectedItem().getValue().id;
            Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l);
            Cookies.setCookie("theme", themeId, date);
            // TODO storeLoginPasswordTheme()
            String url = Window.Location.getHref();
            int index;
            if ((index = url.indexOf("theme=")) != -1) {
                int i2 = url.indexOf("&", index);
                if (i2 == -1) {
                    url = url.substring(0, index) + "theme=" + themeId;
                } else {
                    url = url.substring(0, index) + "theme=" + themeId + url.substring(i2);
                }
            } else {
                if (url.indexOf("?") != -1) {
                    url += "&theme=" + themeId;
                } else {
                    url += "?theme=" + themeId;
                }
            }
            Window.Location.assign(url);
        }
    });
    add(themeList);

    // CheckBox remMe = new CheckBox();
    // remMe.setBoxLabel("Remember me");
    // remMe.setValue(false);
    // remMe.setLabelSeparator("");
    // add(remMe);
}

From source file:com.tensegrity.wpalo.client.ui.mvc.account.AdminHelpDialog.java

License:Open Source License

private final boolean checkShowTipCookie(String title, String user) {
    String cookieData = Cookies.getCookie(SHOW_ADMIN_TIPS_COOKIE + cookieTitle + user);
    Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l);
    if (cookieData == null) {
        cookieData = "true";
    }//from w w w  .j av a  2 s  .  c  om
    // Update cookie data expiration date:
    Cookies.setCookie(SHOW_ADMIN_TIPS_COOKIE + cookieTitle + user, cookieData, date);

    String value = cookieData;
    if (value == null) {
        value = "true";
    }
    boolean doShow = true;
    try {
        doShow = Boolean.parseBoolean(value);
    } catch (Throwable t) {
        doShow = true;
    }

    if (doShow) {
        return true;
    } else {
        cookieData = "" + doShow;
        Cookies.setCookie(SHOW_ADMIN_TIPS_COOKIE + cookieTitle + user, cookieData, date);
    }
    return false;
}

From source file:com.tensegrity.wpalo.client.ui.mvc.account.AdminHelpDialog.java

License:Open Source License

private final void doShowDialog(final String title, String msg, final String user) {
    setData("messageBox", true);
    setHeading(title);//from  w w  w  . j  a  v a 2s.  co m
    setResizable(false);
    setConstrain(true);
    setMinimizable(false);
    setMaximizable(false);
    setMinWidth(100);
    setClosable(false);
    setModal(false);
    setButtonAlign(HorizontalAlignment.CENTER);
    setMinHeight(80);
    setPlain(true);
    setFooter(true);
    setButtons(MessageBox.OK);
    setHideOnButtonClick(false);
    setCloseAction(CloseAction.CLOSE);
    addListener(Events.Close, new Listener<BaseEvent>() {
        public void handleEvent(BaseEvent be) {
            boolean showTips = true;
            if (doNotShowAgain != null) {
                showTips = !doNotShowAgain.getValue();
            }
            String cookieData = "" + showTips;
            Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l);
            Cookies.setCookie(SHOW_ADMIN_TIPS_COOKIE + cookieTitle + user, cookieData, date);
        }
    });

    doNotShowAgain = new CheckBox();
    doNotShowAgain.setBoxLabel(constants.doNotShowThisMessageAgain());

    String message = msg;

    messageLabel = new LabelField(message);
    messageLabel.setStyleName("margin10");
    add(messageLabel);

    doNotShowAgain.setStyleName("margin10");
    add(doNotShowAgain);
    show();
}