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

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

Introduction

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

Prototype

public static String getCookie(String name) 

Source Link

Document

Gets the cookie associated with the given name.

Usage

From source file:com.qualogy.qafe.gwt.client.factory.WindowFactory.java

License:Apache License

public static void createWindow(UIGVO ui, String windowId) {
    Widget w = GWTUIGenerator.createView(ui, windowId);

    if (ClientApplicationContext.getInstance().isMDI()) {
        WindowGVO windowGVO = getWindow(ui, windowId);
        String windowTitle = getWindowTitle(ui, windowId);

        if (windowGVO != null) {
            windowTitle = windowGVO.getTitle();
        }/*from ww w.  j a v  a  2s.c om*/

        if (w != null) {

            WindowPanel window = new QWindowPanel(windowTitle);
            window.getHeader().setText(windowTitle);

            if (w instanceof QRootPanel) {
                ((QWindowPanel) window).setQRootPanel((QRootPanel) w);
            }

            window.setAnimationEnabled(true);
            ((QWindowPanel) window).setManaged(true);

            // Do not pack the windows if the "width" or "height" attributes
            // are on
            boolean bPack = true;

            // window.updateSize();
            if (windowGVO.getHeight() != null && windowGVO.getHeight().length() > 0) {
                try {
                    int height = Integer.parseInt(windowGVO.getHeight());
                    // Test if the height is not negative
                    if (height < 0)
                        throw new NumberFormatException();
                    bPack = false;
                    window.setHeight(height + "px");
                } catch (NumberFormatException e) {
                    ClientApplicationContext.getInstance()
                            .log("could not set height on Window (it's not a valid integer):"
                                    + windowGVO.getHeight());
                }
            }
            if (windowGVO.getWidth() != null && windowGVO.getWidth().length() > 0) {
                try {
                    int width = Integer.parseInt(windowGVO.getWidth());
                    // Test if the width is not negative
                    if (width < 0)
                        throw new NumberFormatException();
                    bPack = false;
                    window.setWidth(width + "px");
                } catch (NumberFormatException e) {
                    ClientApplicationContext.getInstance().log(
                            "could not set width on Window (it's not a valid integer):" + windowGVO.getWidth());
                }
            }

            if (currentWindowTitle == null)
                currentWindowTitle = windowGVO.getTitle();
            if (!windowTitle.equalsIgnoreCase(currentWindowTitle)) {
                ClientApplicationContext.getInstance().updatePosition();
            }
            currentWindowTitle = windowTitle;
            int left = ClientApplicationContext.getInstance().getStartXPosition();
            int top = ClientApplicationContext.getInstance().getStartYPosition();
            if (windowGVO.getLeft() != null) {
                left = windowGVO.getLeft();
            }
            if (windowGVO.getTop() != null) {
                top = windowGVO.getTop();
            }
            window.setPopupPosition(left, top);

            ClientApplicationContext.getInstance().addWindows(ui, window, windowId);
            if (Cookies.getCookie(ui.getUuid() + "-top-" + windowId) != null
                    && Cookies.getCookie(ui.getUuid() + "-left-" + windowId) != null) {
                // There is a known bug that causes the parsing of the position stored as string in the cookie to be
                // returned as a double. 
                double leftPos = Double.parseDouble(Cookies.getCookie(ui.getUuid() + "-left-" + windowId));
                double rightPos = Double.parseDouble(Cookies.getCookie(ui.getUuid() + "-top-" + windowId));
                int roundedLeftPos = (int) Math.round(leftPos);
                int roundedRightPos = (int) Math.round(rightPos);
                window.setPopupPosition(roundedLeftPos, roundedRightPos);

            }
            window.setWidget(w);
            // If the width or the height attributes were set then we don't
            // pack the window
            // Use the default width and height that you got in the ClientApplicationContext.
            if (ClientApplicationContext.getInstance().getGlobalConfigurations()
                    .get("window.default.height") != null && windowGVO.getHeight() == null) {
                window.setHeight(ClientApplicationContext.getInstance().getGlobalConfigurations()
                        .get("window.default.height"));
                bPack = false;
            }
            if (ClientApplicationContext.getInstance().getGlobalConfigurations()
                    .get("window.default.width") != null && windowGVO.getWidth() == null) {
                window.setWidth(ClientApplicationContext.getInstance().getGlobalConfigurations()
                        .get("window.default.width"));
                bPack = false;
            }

            if (bPack) {
                window.pack();
                if (window.getContentHeight() > (int) (Window.getClientHeight() * 0.8)) {
                    Dimension d = window.getContentSize();
                    Dimension newD = new Dimension(d.getWidth(), Window.getClientHeight() / 2);
                    window.setContentSize(newD);
                }
                if (window.getContentWidth() > (int) (Window.getClientWidth() * 0.8)) {
                    Dimension d = window.getContentSize();
                    Dimension newD = new Dimension(Window.getClientWidth() / 2, d.getHeight());
                    window.setContentSize(newD);
                }
            }

            window.show();
            modifyWindowSize(w, window);

            EventFactory.createWindowSizeEvent(ui.getUuid(), windowId, window);
            if (windowGVO != null) {
                RendererHelper.addStyle(windowGVO.getRootPanel(), ((QWindowPanel) window).getQRootPanel());
                if (windowGVO.getClosable() != null) {
                    ((QWindowPanel) window).setClosable(windowGVO.getClosable().booleanValue());
                }
                if (windowGVO.getMaximizable() != null && windowGVO.getMaximizable().booleanValue()) {
                    ((QWindowPanel) window).addMaximizeButton();// setMaximizable(windowGVO.getMaximizable().booleanValue());
                }
                if (windowGVO.getMinimizable() != null && windowGVO.getMinimizable().booleanValue()) {
                    ((QWindowPanel) window).addMinimizeButton();
                }
                if (windowGVO.getResizable() != null) {
                    window.setResizable(windowGVO.getResizable().booleanValue());
                }

                // The id of the ui-window is winId|winId|appId (<id>|<parent>|<context>),
                // while the id of ui-components within a window is componentId|winId|appId
                RendererHelper.addId(windowGVO, window, ui.getUuid(), windowGVO.getId(), windowGVO.getContext(),
                        true);
                RendererHelper.addUUID(windowGVO, window, ui.getUuid());
                // /// TODO Check the unload and window actions...
                EventFactory.createDefaultCloseEvent(windowGVO, window,
                        ClientApplicationContext.getInstance().getWindowSession(), ui.getUuid());
                EventFactory.createWindowStateChangeListener(window, windowTitle, ui.getUuid(), windowId);
            }
        } else {
            ClientApplicationContext.getInstance().log("Opening Window failed", "Window with id '" + windowId
                    + "' could not be opened.\n This Window might not exist in this application context", true);
        }
    } else {
        WindowGVO windowGVO = getWindow(ui, windowId);

        setWidgetToMainPanel(w, windowGVO);
    }
}

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 om*/
                    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.sencha.gxt.state.client.CookieProvider.java

License:sencha.com license

@Override
public void getValue(String name, Callback<String, Throwable> callback) {
    callback.onSuccess(Cookies.getCookie(name));
}

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

License:Open Source License

/**
 * Gets the login.//from   w  w w  . ja  v  a2 s . co  m
 *
 * @return the login
 */
public static boolean getLogin() {
    try {
        String sessionId = Cookies.getCookie("sessionId");
        if (sessionId == null || sessionId.equals("") || sessionId.equals("undefined")) {
            return false;
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}

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

License:Open Source License

/**
 * Gets the user name./*from   w  w  w  .  j a v a  2  s  . c om*/
 *
 * @return the user name
 */
public static String getUserName() {
    if (!getLogin()) {
        return "";
    }
    String userName = Cookies.getCookie(USER_NAME);
    if (userName == null) {
        userName = "";
    }
    return userName;
}

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

License:Open Source License

/**
 * Gets the role.//www  .  j a  v a 2  s.  co m
 *
 * @return null if user not login.
 */
public static String getRole() {
    if (getLogin()) {
        return Cookies.getCookie(ROLE);
    }
    return null;
}

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

License:Open Source License

public static String[] getStatDisplayCodes() {
    String val = Cookies.getCookie("STAT_CODES");
    if (val == null) {
        ArrayList<String> defaults = new ArrayList<String>();
        defaults.add("ATTEND");
        defaults.add("NEW_ITEM");
        defaults.add("UPDATE_ITEM");
        defaults.add("GET_ITEM");
        defaults.add("FIND_SIM");
        setStatDisplayCodes(defaults);/*w  w w .j a v a2 s  .c o  m*/
        return getStatDisplayCodes();
    }

    return val.split(":");
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.widget.PageHeaderWidget.java

License:Open Source License

private void populateLoginBox() {

    if (playButton != null) {
        playButton.onDelete();/*from  ww w. j  a va 2 s.c o m*/
    }

    txtbox = new TextBox();
    txtbox.setText(Cookies.getCookie("app-openid-uniqueid"));
    txtbox.setStyleName("openidField");
    txtbox.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == 13) {
                fetchUserInfo();
            }
        }
    });

    Button b = new Button();
    b.setText("Login with your openID");
    b.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent ce) {
            fetchUserInfo();
        }
    });

    HorizontalPanel h = new HorizontalPanel();
    h.add(txtbox);
    h.add(b);
    mainPanel.setWidget(0, 0, h);

}

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 ww  .  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.viewbrowser.ViewBrowser.java

License:Open Source License

private final void checkShowTipCookie(XUser user) {
    String cookieData = Cookies.getCookie(SHOW_TIPS_COOKIE + user.getLogin());
    Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l);
    if (cookieData == null) {
        cookieData = "true,1";
    }/*from  w ww  .  j  a  v a2  s .  co  m*/
    // Update cookie data expiration date:
    Cookies.setCookie(SHOW_TIPS_COOKIE + user.getLogin(), cookieData, date);

    String[] values = cookieData.split(",");
    if (values == null || values.length != 2) {
        values = new String[2];
        values[0] = "true";
        values[1] = "1";
    }
    boolean doShow = true;
    int tipNumber = 1;
    try {
        doShow = Boolean.parseBoolean(values[0]);
        tipNumber = Integer.parseInt(values[1]);
    } catch (Throwable t) {
        doShow = true;
        tipNumber = 1;
    }

    if (doShow) {
        new ShowTipsAtStartupDialog(tipNumber, date, user.getLogin());
    } else {
        cookieData = doShow + "," + tipNumber;
        Cookies.setCookie(SHOW_TIPS_COOKIE + user.getLogin(), cookieData, date);
    }
}