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

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

Introduction

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

Prototype

public void setItem(String key, String data) 

Source Link

Document

Sets the value in the Storage associated with the specified key to the specified data.

Usage

From source file:ch.unifr.pai.twice.utils.device.client.UUID.java

License:Apache License

/**
 * If no identifier is defined, this method tries to recover it from the HTML5 session storage if available or generates a new UUID and stores it if
 * possible./*from w ww  .j  av a2 s  . c om*/
 * 
 * 
 * @return the currently valid identifier of this device (the return value is never null!)
 */
public static String get() {
    if (uuid == null) {
        Storage s = Storage.getSessionStorageIfSupported();
        if (s != null) {
            uuid = s.getItem("ch.unifr.pai.mice.uuid");
        }
        if (uuid == null) {
            uuid = UUIDGenerator.uuid();
            if (s != null)
                s.setItem("ch.unifr.pai.mice.uuid", uuid);
        }
    }
    return uuid;
}

From source file:ch.unifr.pai.twice.widgets.mpbrowser.client.MPBrowser.java

License:Apache License

@Override
public void onModuleLoad() {
    multiCursor.start();/*from  w  w w . j a  v  a  2 s.  c o m*/
    scrollBar.getElement().getStyle().setBackgroundColor("lightgrey");
    scrollBar.addNorth(scrollUp, 30);
    scrollBar.addSouth(scrollDown, 30);
    scrollBar.add(new HTML());
    textBox.setWidth("100%");
    navig.add(backward);
    navig.add(forward);
    navig.setCellWidth(backward, "50px");
    navig.setCellWidth(forward, "50px");
    navig.add(textBox);
    navig.setWidth("100%");
    Storage s = Storage.getSessionStorageIfSupported();
    if (s != null) {
        String type = s.getItem("ch.unifr.pai.mice.deviceType");
        if (type == null || !type.equals("multicursor")) {
            s.setItem("ch.unifr.pai.mice.deviceType", "multicursor");
        }
    }
    frame.setUrl(GWT.getHostPageBaseURL() + "http://www.google.ch");
    frame.setHeight("100%");
    frame.setWidth("100%");
    frame.getElement().setAttribute("scrolling", "no");
    frame.addLoadHandler(new LoadHandler() {

        @Override
        public void onLoad(LoadEvent event) {
            if (frame.getUrl() != null && !frame.getUrl().startsWith(GWT.getHostPageBaseURL())) {
                frame.setUrl(GWT.getHostPageBaseURL() + frame.getUrl());
                updateScrollBar();
            }
            Document d = IFrameElement.as(frame.getElement()).getContentDocument();
            textBox.setValue(d.getURL());
        }
    });
    scrollBar2.getElement().getStyle().setBackgroundColor("lightgrey");
    scrollBar2.addNorth(scrollUp2, 30);
    scrollBar2.addSouth(scrollDown2, 30);
    scrollBar2.add(new HTML());
    textBox2.setWidth("100%");
    navig2.add(backward2);
    navig2.add(forward2);
    navig2.setCellWidth(backward2, "50px");
    navig2.setCellWidth(forward2, "50px");
    navig2.add(textBox2);
    navig2.setWidth("100%");

    frame2.setUrl(GWT.getHostPageBaseURL() + "http://www.google.ch");
    frame2.setHeight("100%");
    frame2.setWidth("100%");
    frame2.getElement().setAttribute("scrolling", "no");
    frame2.addLoadHandler(new LoadHandler() {

        @Override
        public void onLoad(LoadEvent event) {
            if (frame2.getUrl() != null && !frame2.getUrl().startsWith(GWT.getHostPageBaseURL())) {
                frame2.setUrl(GWT.getHostPageBaseURL() + frame2.getUrl());
                updateScrollBar2();
            }
            Document d = IFrameElement.as(frame2.getElement()).getContentDocument();
            textBox2.setValue(d.getURL());
        }
    });

    DockLayoutPanel p = new DockLayoutPanel(Unit.PX);
    p.addNorth(navig, 25);
    p.addEast(scrollBar, 30);
    p.add(frame);
    browserSplit.addNorth(p, 500);

    DockLayoutPanel p2 = new DockLayoutPanel(Unit.PX);
    p2.addNorth(navig2, 25);
    p2.addEast(scrollBar2, 30);
    p2.add(frame2);
    browserSplit.add(p2);

    RootLayoutPanel.get().add(browserSplit);
}

From source file:com.ait.tooling.nativetools.client.storage.AbstractStorage.java

License:Open Source License

protected AbstractStorage(final CacheType type, Storage storage) {
    m_type = type;/*from w  ww.jav  a  2  s  .  c  om*/

    if (null != storage) {
        try {
            final String test = "__" + type + "__";

            storage.setItem(test, test);

            storage.removeItem(test);
        } catch (Exception e) {
            storage = null;

            Client.get().error(type + " is not enabled, Browser may be in private mode: ", e);
        }
    }
    m_storage = storage;
}

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);
    }/*  ww  w . j  a  v  a2 s.c o m*/
}

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();
        }/*from   w  ww. j a  va  2  s.c o  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 saveField(String field, String value) {
    if (Storage.isLocalStorageSupported()) {
        Storage storage = Storage.getLocalStorageIfSupported();
        storage.setItem(field, value);
    } else {/*from ww  w . j  av  a2  s  . co m*/
        saveCookie(value, field);
    }
}

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

License:Open Source License

protected void saveField(Storage storage, Field f) {
    String value = getFieldValue(f);
    storage.setItem(f.name, value);
}

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

License:Open Source License

private void saveItems(JsoArray<Entry> list) {
    Storage storage = getStorage();

    if (storage != null) {
        storage.setItem(SAVED_ITEMS, list.stringify());
    }//from ww  w .j a v  a 2s. c  o  m
}

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

License:Open Source License

protected void renameLocalStorage() {
    String name = getName();//www.j  a  v  a 2 s.c o  m

    if (name != null) {
        final Storage s = getStorage();

        if (s != null) {
            final int i = storageList.getSelectedIndex();

            if (i < 0) {
                ApplicationPanel.showErrorDialog("Select a Storage entry");
            } else {
                String key = storageList.getValue(i);
                String value = s.getItem(key);
                storageList.removeItem(i);
                s.removeItem(key);
                key = STORAGE_KEY + name;
                s.setItem(key, value);
                storageList.insertItem(name, key, i);
            }
        }
    }
}

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

License:Open Source License

protected void saveLocalStorage() {
    final Storage s = getStorage();

    if (s != null) {
        final int i = storageList.getSelectedIndex();

        if (i < 0) {
            ApplicationPanel.showErrorDialog("Select a Storage entry");
        } else {/*from   w w  w. ja  va2  s.c  o  m*/
            if (listener != null) {
                final FormData data = listener.getFormData();

                JSONObject obj = JsonUtil.toJSONObject(data);
                String key = storageList.getValue(i);
                s.setItem(key, obj.toString());

                ApplicationPanel.showInfoDialog("Configuration Saved.");
            }
        }
    }
}