Example usage for com.google.gwt.storage.client Storage isLocalStorageSupported

List of usage examples for com.google.gwt.storage.client Storage isLocalStorageSupported

Introduction

In this page you can find the example usage for com.google.gwt.storage.client Storage isLocalStorageSupported.

Prototype

public static boolean isLocalStorageSupported() 

Source Link

Document

Returns true if the localStorage part of the Storage API is supported on the running platform.

Usage

From source file:com.data2semantics.yasgui.client.configmenu.Compatabilities.java

License:Open Source License

private void checkCompatabilities() {
    html5StorageSupported = Storage.isLocalStorageSupported();
    downloadFileSupported = JsMethods.stringToDownloadSupported();
    downloadAttributeSupported = JsMethods.downloadAttributeSupported();
    historySupported = JsMethods.historyApiSupported();
    allSupported = (html5StorageSupported && downloadFileSupported && downloadAttributeSupported
            && historySupported);
}

From source file:com.data2semantics.yasgui.client.configmenu.Compatibilities.java

License:Open Source License

private void checkCompatibilities() {
    html5StorageSupported = Storage.isLocalStorageSupported();
    downloadFileSupported = JsMethods.stringToDownloadSupported();
    downloadAttributeSupported = JsMethods.downloadAttributeSupported();
    historySupported = JsMethods.historyApiSupported();
    offlineSupported = JsMethods.offlineSupported();
    allSupported = (html5StorageSupported && downloadFileSupported && downloadAttributeSupported
            && historySupported);
}

From source file:com.data2semantics.yasgui.client.helpers.LocalStorageHelper.java

License:Open Source License

public static void setInLocalStorage(String key, String value) {
    if (Storage.isLocalStorageSupported()) {
        Storage html5Storage = Storage.getLocalStorageIfSupported();
        html5Storage.setItem(Helper.getCurrentHost() + "_" + key, value);
    }//from  www . j a v  a2  s.  c o m
}

From source file:com.data2semantics.yasgui.client.helpers.LocalStorageHelper.java

License:Open Source License

/**
 * Store settings as json string in cookie. If html5 local storage is possible, use that. 
 * html5 storage does not send cookie info on every request, which reduces network load
 * //w w  w .  j a v  a2s .c  o  m
 * @param settings
 */
public static void storeSettingsInCookie(Settings settings) {
    if (Storage.isLocalStorageSupported()) {
        setInLocalStorage(COOKIE_SETTINGS, settings.toString(), true);
    } else {
        //We are using a browser which does not support html5
        setAsCookie(COOKIE_SETTINGS, settings.toString(), SETTINGS_EXPIRE_DAYS);
    }
}

From source file:com.dawg6.web.dhcalc.client.BasePanel.java

License:Open Source License

protected String getFieldValue(String field, String defaultValue) {
    if (Storage.isLocalStorageSupported()) {
        Storage storage = Storage.getLocalStorageIfSupported();
        String value = storage.getItem(field);

        return (value != null) ? value : defaultValue;
    } else {//from   w w  w .  j av  a 2  s .c  om
        return getCookie(field, defaultValue);
    }
}

From source file:com.dawg6.web.dhcalc.client.BasePanel.java

License:Open Source License

protected boolean loadStorage() {

    boolean result = false;

    if (Storage.isLocalStorageSupported()) {
        Storage storage = Storage.getLocalStorageIfSupported();

        Collection<String> cookies = null;

        if (Cookies.isCookieEnabled()) {
            cookies = Cookies.getCookieNames();
        }// ww w.  ja v a2s  .co m

        for (Field f : getFields()) {
            String value = storage.getItem(f.name);

            if (value != null) {
                // do nothing
            } else if ((cookies != null) && (cookies.contains(f.name))) {
                value = getCookie(f.name, f.defaultValue);
                storage.setItem(f.name, value);
                Cookies.removeCookie(f.name);
            } else {
                value = f.defaultValue;
                storage.setItem(f.name, value);
            }

            setFieldValue(f, value);
        }

        result = true;
    }

    return result;
}

From source file:com.dawg6.web.dhcalc.client.BasePanel.java

License:Open Source License

protected void saveFields(Field... fields) {
    if (Storage.isLocalStorageSupported()) {
        Storage storage = Storage.getLocalStorageIfSupported();

        for (Field f : fields) {
            saveField(storage, f);/*from  w  w w.  j  av  a2 s  .  c o m*/
        }

    } else {
        for (Field f : fields) {
            saveCookie(f);
        }
    }
}

From source file:com.dawg6.web.dhcalc.client.BasePanel.java

License:Open Source License

protected void saveField(String field, String value) {
    if (Storage.isLocalStorageSupported()) {
        Storage storage = Storage.getLocalStorageIfSupported();
        storage.setItem(field, value);//from w  ww .  ja v a  2s. c om
    } else {
        saveCookie(value, field);
    }
}

From source file:com.dawg6.web.dhcalc.client.SavePanel.java

License:Open Source License

public SavePanel() {

    CaptionPanel captionPanel = new CaptionPanel("Save/Load");
    initWidget(captionPanel);// w w  w  .j a v  a 2  s.c  om

    FlexTable flexTable_3 = new FlexTable();
    flexTable_3.setCellPadding(2);
    captionPanel.setContentWidget(flexTable_3);

    tabPanel = new TabPanel();
    flexTable_3.setWidget(0, 0, tabPanel);

    browserPanel = new FlexTable();
    browserPanel.setCellPadding(2);

    if (Storage.isLocalStorageSupported()) {
        tabPanel.add(browserPanel, "Browser Storage", false);
    }

    storageList = new ListBox();
    browserPanel.setWidget(0, 0, storageList);
    storageList.setWidth("100%");
    storageList.setVisibleItemCount(5);

    nameField = new TextBox();
    nameField.setVisibleLength(30);
    nameField.setText("Enter a Name");
    browserPanel.setWidget(1, 0, nameField);

    Button btnNewButton = new Button("New button");
    browserPanel.setWidget(1, 1, btnNewButton);
    btnNewButton.setText("Add");

    btnNewButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            addLocalStorage();
        }
    });

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    horizontalPanel.setSpacing(5);
    horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    browserPanel.setWidget(2, 0, horizontalPanel);

    Button button_6 = new Button("New button");
    button_6.setText("Save");
    horizontalPanel.add(button_6);

    button_6.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            saveLocalStorage();
        }
    });

    Button button_5 = new Button("New button");
    horizontalPanel.add(button_5);
    button_5.setText("Restore");

    button_5.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            restoreLocalStorage();
        }
    });

    Button button_2 = new Button("New button");
    horizontalPanel.add(button_2);
    button_2.setText("Delete");

    button_2.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            deleteLocalStorage();
        }
    });

    Button btnNewButton_1 = new Button("New button");
    horizontalPanel.add(btnNewButton_1);
    btnNewButton_1.setText("Rename");

    btnNewButton_1.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            renameLocalStorage();
        }
    });

    browserPanel.getFlexCellFormatter().setColSpan(0, 0, 1);
    browserPanel.getFlexCellFormatter().setColSpan(2, 0, 1);
    browserPanel.getFlexCellFormatter().setColSpan(0, 0, 2);
    browserPanel.getFlexCellFormatter().setColSpan(2, 0, 2);
    browserPanel.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER);

    filePanel = new FlexTable();
    filePanel.setCellPadding(2);
    tabPanel.add(filePanel, "Local File", false);

    HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
    filePanel.setWidget(0, 0, horizontalPanel_1);

    loadPanel = new FormPanel();
    loadPanel.setMethod(FormPanel.METHOD_POST);
    loadPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    loadPanel.setAction("loadData");
    horizontalPanel_1.add(loadPanel);

    HorizontalPanel horizontalPanel_2 = new HorizontalPanel();
    loadPanel.setWidget(horizontalPanel_2);
    horizontalPanel_2.setSize("100%", "100%");

    fileUpload = new FileUpload();
    fileUpload.setName("file");
    horizontalPanel_2.add(fileUpload);

    clientKey = new Hidden("client");
    horizontalPanel_2.add(clientKey);
    filePanel.getFlexCellFormatter().setColSpan(0, 0, 1);

    Button button = new Button("Save Data...");
    filePanel.setWidget(1, 0, button);
    button.setText("Save File");

    Button button_1 = new Button("Load Data...");
    filePanel.setWidget(1, 1, button_1);
    button_1.setText("Load File");
    filePanel.getFlexCellFormatter().setColSpan(0, 0, 2);
    filePanel.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
    filePanel.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);

    button_1.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            loadFile();

        }
    });

    button.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            saveFile();

        }
    });

    textPanel = new FlexTable();
    textPanel.setCellPadding(2);
    tabPanel.add(textPanel, "Copy/Paste", false);

    textArea = new TextArea();
    textArea.setText(
            "Paste previously saved form data here and click \"Restore.\" Or press \"Current\" to paste current Form data.");
    textArea.setVisibleLines(5);
    textPanel.setWidget(0, 0, textArea);
    textArea.setSize("100%", "");

    Button button_3 = new Button("Save Data...");
    button_3.setText("Current");
    textPanel.setWidget(1, 0, button_3);

    textArea.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            textArea.selectAll();
        }
    });

    nameField.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            nameField.selectAll();
        }
    });

    button_3.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {

            if (listener != null) {

                FormData data = listener.getFormData();

                JSONObject obj = JsonUtil.toJSONObject(data);
                textArea.setText(JsonUtil.formatJsonText(obj.toString()));
                textArea.selectAll();
            }

        }
    });

    Button button_4 = new Button("Load Data...");
    button_4.setText("Restore");

    button_4.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (listener != null) {
                String text = textArea.getText();

                FormData data = JsonUtil.parseFormData(text);

                listener.setFormData(data);
                textArea.setText("");
            }

        }
    });

    textPanel.setWidget(1, 1, button_4);
    textPanel.getFlexCellFormatter().setColSpan(0, 0, 2);
    textPanel.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
    textPanel.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);

    flexTable_3.getFlexCellFormatter().setColSpan(0, 0, 1);

    storageList.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            int i = storageList.getSelectedIndex();

            if (i >= 0) {
                String name = storageList.getItemText(i);

                if (name != null)
                    nameField.setText(name);
            }

        }
    });
}

From source file:com.google.api.gwt.oauth2.client.AuthImpl.java

License:Apache License

/**
 * Returns the correct {@link TokenStore} implementation to use based on
 * browser support for localStorage./*from w  w w .  j a va2  s  . com*/
 */
// TODO(jasonhall): This will not result in CookieStoreImpl being compiled out
// for browsers that support localStorage, and vice versa? If not, this should
// be a deferred binding rule.
private static TokenStoreImpl getTokenStore() {
    return Storage.isLocalStorageSupported() ? new TokenStoreImpl() : new CookieStoreImpl();
}