Example usage for com.google.gwt.chrome.storage Storage getLocal

List of usage examples for com.google.gwt.chrome.storage Storage getLocal

Introduction

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

Prototype

public LocalStorageArea getLocal() 

Source Link

Usage

From source file:org.rest.client.jso.RequestObject.java

License:Apache License

/**
 * //from ww w.  j a  va2s .  c  o  m
 * @param clientFactory
 * @param callback
 */
public static void restoreLatest(final Callback<RequestObject, Throwable> callback) {
    Storage store = GWT.create(Storage.class);
    JSONObject jo = new JSONObject();
    jo.put(StoreKeys.LATEST_REQUEST_KEY, new JSONObject(null));
    store.getLocal().get(jo.getJavaScriptObject(), new StorageItemsCallback() {

        @Override
        public void onError(String message) {
            if (RestClient.isDebug()) {
                Log.error("RequestObject::restoreLatest - " + message);
            }
        }

        @Override
        public void onResult(JavaScriptObject data) {
            StorageResult<RequestObject> result = data.cast();
            if (result == null) {
                callback.onSuccess(null);
                return;
            }
            RequestObject ro = result.getObject(StoreKeys.LATEST_REQUEST_KEY).cast();
            if (ro != null) {
                callback.onSuccess(ro);
            } else {
                Log.error("Error perform RequestObject::restoreLatest. Result is null.");
                callback.onFailure(
                        new Throwable("Error perform RequestObject::restoreLatest. Result is null."));
            }
        }
    });
}

From source file:org.rest.client.jso.RequestObject.java

License:Apache License

/**
 * Store this request as a latest request
 *///  ww  w.  j a  v  a2  s .c om
public final void storeLastest(final Callback<Void, Throwable> callback) {
    Storage store = GWT.create(Storage.class);
    JSONObject requestData = toJSONObject();
    JSONObject save = new JSONObject();
    save.put(StoreKeys.LATEST_REQUEST_KEY, requestData);
    Log.debug("Storing lates object", save.getJavaScriptObject());
    store.getLocal().set(save.getJavaScriptObject(), new StorageSimpleCallback() {

        @Override
        public void onError(String message) {
            callback.onFailure(new Throwable(message));
        }

        @Override
        public void onDone() {
            Void v = GWT.create(Void.class);
            callback.onSuccess(v);
        }
    });
}