List of usage examples for com.google.gwt.storage.client Storage clear
public void clear()
From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.grid.LocalStorageGridExample.java
License:sencha.com license
@Override public Widget asWidget() { if (fp == null) { final Storage storage = Storage.getLocalStorageIfSupported(); if (storage == null) { new MessageBox("Not Supported", "Your browser doesn't appear to supprt HTML5 localStorage").show(); return new HTML("LocalStorage not supported in this browser"); }/*from w w w .j a va 2s . c o m*/ // Writer to translate load config into string UrlEncodingWriter<ForumLoadConfig> writer = new UrlEncodingWriter<ForumLoadConfig>( TestAutoBeanFactory.instance, ForumLoadConfig.class); // Reader to translate String results into objects JsonReader<ForumListLoadResult, ForumCollection> reader = new JsonReader<ForumListLoadResult, ForumCollection>( TestAutoBeanFactory.instance, ForumCollection.class) { @Override protected ForumListLoadResult createReturnData(Object loadConfig, ForumCollection records) { PagingLoadConfig cfg = (PagingLoadConfig) loadConfig; ForumListLoadResult res = TestAutoBeanFactory.instance.dataLoadResult().as(); res.setData(records.getTopics()); res.setOffset(cfg.getOffset()); res.setTotalLength(Integer.parseInt(records.getTotalCount())); return res; } }; // Proxy to load from server String url = "http://www.sencha.com/forum/topics-remote.php"; final ScriptTagProxy<ForumLoadConfig> remoteProxy = new ScriptTagProxy<ForumLoadConfig>(url); remoteProxy.setWriter(writer); // Proxy to load objects from local storage final StorageReadProxy<ForumLoadConfig> localReadProxy = new StorageReadProxy<ForumLoadConfig>(storage); localReadProxy.setWriter(writer); // Proxy to persist network-loaded objects into local storage final StorageWriteProxy<ForumLoadConfig, String> localWriteProxy = new StorageWriteProxy<ForumLoadConfig, String>( storage); localWriteProxy.setKeyWriter(writer); // Wrapper Proxy to dispatch to either storage or scripttag, and to save results DataProxy<ForumLoadConfig, String> proxy = new DataProxy<ForumLoadConfig, String>() { @Override public void load(final ForumLoadConfig loadConfig, final Callback<String, Throwable> callback) { // Storage read is known to be synchronous, so read it first - if null, continue localReadProxy.load(loadConfig, new Callback<String, Throwable>() { @Override public void onFailure(Throwable reason) { // ignore failure, go remote onSuccess(null); } @Override public void onSuccess(String result) { if (result != null) { callback.onSuccess(result); } else { //read from remote and save it remoteProxy.load(loadConfig, new Callback<JavaScriptObject, Throwable>() { @Override public void onSuccess(JavaScriptObject result) { //write results to local db String json = new JSONObject(result).toString(); Entry<ForumLoadConfig, String> data = new Entry<ForumLoadConfig, String>( loadConfig, json); localWriteProxy.load(data, new Callback<Void, Throwable>() { @Override public void onSuccess(Void result) { // ignore response } @Override public void onFailure(Throwable reason) { // ignore response } }); callback.onSuccess(json); } @Override public void onFailure(Throwable reason) { callback.onFailure(reason); } }); } } }); } }; PagingLoader<ForumLoadConfig, ForumListLoadResult> loader = new PagingLoader<ForumLoadConfig, ForumListLoadResult>( proxy, reader); loader.useLoadConfig(TestAutoBeanFactory.instance.loadConfig().as()); ForumProperties props = GWT.create(ForumProperties.class); ListStore<Forum> store = new ListStore<Forum>(props.key()); loader.addLoadHandler( new LoadResultListStoreBinding<ForumLoadConfig, Forum, ForumListLoadResult>(store)); ColumnConfig<Forum, String> cc1 = new ColumnConfig<Forum, String>(props.title(), 100, "Title"); cc1.setSortable(false); ColumnConfig<Forum, String> cc2 = new ColumnConfig<Forum, String>(props.excerpt(), 165, "Excerpt"); cc2.setSortable(false); ColumnConfig<Forum, Date> cc3 = new ColumnConfig<Forum, Date>(props.date(), 100, "Date"); cc3.setSortable(false); ColumnConfig<Forum, String> cc4 = new ColumnConfig<Forum, String>(props.author(), 50, "Author"); cc4.setSortable(false); List<ColumnConfig<Forum, ?>> l = new ArrayList<ColumnConfig<Forum, ?>>(); l.add(cc1); l.add(cc2); l.add(cc3); l.add(cc4); ColumnModel<Forum> cm = new ColumnModel<Forum>(l); Grid<Forum> grid = new Grid<Forum>(store, cm); grid.getView().setForceFit(true); grid.setLoader(loader); grid.setLoadMask(true); grid.setBorders(true); final PagingToolBar toolBar = new PagingToolBar(50); toolBar.getElement().getStyle().setProperty("borderBottom", "none"); toolBar.add(new TextButton("Clear Cache", new SelectHandler() { @Override public void onSelect(SelectEvent event) { storage.clear(); } })); toolBar.bind(loader); fp = new FramedPanel(); fp.setHeadingText("LocalStorage Grid Example"); fp.setCollapsible(true); fp.setAnimCollapse(true); fp.setPixelSize(575, 350); fp.addStyleName("margin-10"); fp.setButtonAlign(BoxLayoutPack.CENTER); VerticalLayoutContainer con = new VerticalLayoutContainer(); con.setBorders(true); con.add(grid, new VerticalLayoutData(1, 1)); con.add(toolBar, new VerticalLayoutData(1, -1)); fp.setWidget(con); loader.load(); } return fp; }
From source file:nl.mpi.tg.eg.experiment.client.presenter.LocalStoragePresenter.java
License:Open Source License
protected void eraseLocalStorageButton(final String styleName, final String buttonGroup) { optionButton(new PresenterEventListner() { @Override/*from ww w .j a v a 2 s .co m*/ public String getLabel() { return "Erase Stored Data"; } @Override public String getStyleName() { return styleName; } @Override public int getHotKey() { return -1; } @Override public void eventFired(ButtonBase button, SingleShotEventListner singleShotEventListner) { final Storage localStorage = Storage.getLocalStorageIfSupported(); localStorage.clear(); Window.Location.replace(Window.Location.getPath()); } }, buttonGroup); }
From source file:org.silverpeas.mobile.client.common.storage.LocalStorageHelper.java
License:Open Source License
public static void clear() { Storage storage = Storage.getLocalStorageIfSupported(); if (storage != null) storage.clear(); }