com.vaadin.polymer.iron.widget.IronLocalstorage Maven / Gradle / Ivy
/*
* This code was generated with Vaadin Web Component GWT API Generator,
* from iron-localstorage project by unknown author
* that is licensed with http://polymer.github.io/LICENSE.txt license.
*/
package com.vaadin.polymer.iron.widget;
import com.vaadin.polymer.iron.element.*;
import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEvent;
import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEventHandler;
import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEmptyEvent;
import com.vaadin.polymer.iron.widget.event.IronLocalstorageLoadEmptyEventHandler;
import com.vaadin.polymer.PolymerWidget;
import com.vaadin.polymer.elemental.*;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.core.client.JavaScriptObject;
/**
* Element access to Web Storage API (window.localStorage).
* Keeps value
property in sync with localStorage.
* Value is saved as json by default.
* Usage:
* ls-sample
will automatically save changes to its value.
* <dom-module id="ls-sample">
* <iron-localstorage name="my-app-storage"
* value="{{cartoon}}"
* on-iron-localstorage-load-empty="initializeDefaultCartoon"
* ></iron-localstorage>
* </dom-module>
*
* <script>
* Polymer({
* is: 'ls-sample',
* properties: {
* cartoon: {
* type: Object
* }
* },
* // initializes default if nothing has been stored
* initializeDefaultCartoon: function() {
* this.cartoon = {
* name: "Mickey",
* hasEars: true
* }
* },
* // use path set api to propagate changes to localstorage
* makeModifications: function() {
* this.set('cartoon.name', "Minions");
* this.set('cartoon.hasEars', false);
* }
* });
* </script>
*
*
*
Tech notes:
*
* value.*
is observed, and saved on modifications. You must use
property notification methods to modify value for changes to be observed.
*
* Set auto-save-disabled
to prevent automatic saving.
*
* Value is saved as JSON by default.
*
* To delete a key, set value to null
*
*
* Element listens to StorageAPI storage
event, and will reload upon receiving it.
* Warning: do not bind value to sub-properties until Polymer
bug 1550
is resolved. Local storage will be blown away.
<iron-localstorage value="{{foo.bar}}"
will cause data loss.
*/
public class IronLocalstorage extends PolymerWidget {
/**
* Default Constructor.
*/
public IronLocalstorage() {
this("");
}
/**
* Constructor used by UIBinder to create widgets with content.
*/
public IronLocalstorage(String html) {
super(IronLocalstorageElement.TAG, IronLocalstorageElement.SRC, html);
getPolymerElement().addEventListener(
com.vaadin.polymer.iron.element.event.IronLocalstorageLoadEvent.NAME,
new com.vaadin.polymer.iron.element.event.IronLocalstorageLoadEvent.Listener() {
@Override
protected void handleEvent(com.vaadin.polymer.iron.element.event.IronLocalstorageLoadEvent event) {
fireEvent(new IronLocalstorageLoadEvent(event));
}
});
getPolymerElement().addEventListener(
com.vaadin.polymer.iron.element.event.IronLocalstorageLoadEmptyEvent.NAME,
new com.vaadin.polymer.iron.element.event.IronLocalstorageLoadEmptyEvent.Listener() {
@Override
protected void handleEvent(com.vaadin.polymer.iron.element.event.IronLocalstorageLoadEmptyEvent event) {
fireEvent(new IronLocalstorageLoadEmptyEvent(event));
}
});
}
/**
* Gets a handle to the Polymer object's underlying DOM element.
*/
public IronLocalstorageElement getPolymerElement() {
return (IronLocalstorageElement) getElement();
}
/**
* Value will not be saved automatically if true. You’ll have to do it manually with save()
*
* JavaScript Info:
* @property autoSaveDisabled
* @type Boolean
*
*/
public boolean getAutoSaveDisabled(){
return getPolymerElement().getAutoSaveDisabled();
}
/**
* Value will not be saved automatically if true. You’ll have to do it manually with save()
*
* JavaScript Info:
* @property autoSaveDisabled
* @type Boolean
*
*/
public void setAutoSaveDisabled(boolean value) {
getPolymerElement().setAutoSaveDisabled(value);
}
/**
* Last error encountered while saving/loading items
*
* JavaScript Info:
* @property errorMessage
* @type String
*
*/
public String getErrorMessage(){
return getPolymerElement().getErrorMessage();
}
/**
* Last error encountered while saving/loading items
*
* JavaScript Info:
* @property errorMessage
* @type String
*
*/
public void setErrorMessage(String value) {
getPolymerElement().setErrorMessage(value);
}
/**
* localStorage item key
*
* JavaScript Info:
* @property name
* @type String
*
*/
public String getName(){
return getPolymerElement().getName();
}
/**
* localStorage item key
*
* JavaScript Info:
* @property name
* @type String
*
*/
public void setName(String value) {
getPolymerElement().setName(value);
}
/**
* Loads the value again. Use if you modify
localStorage using DOM calls, and want to
keep this element in sync.
*
* JavaScript Info:
* @method reload
*
*/
public void reload() {
getPolymerElement().reload();
}
/**
* Saves the value to localStorage. Call to save if autoSaveDisabled is set.
If value
is null, deletes localStorage.
*
* JavaScript Info:
* @method save
*
*/
public void save() {
getPolymerElement().save();
}
/**
* If true: do not convert value to JSON on save/load
*
* JavaScript Info:
* @property useRaw
* @type Boolean
*
*/
public boolean getUseRaw(){
return getPolymerElement().getUseRaw();
}
/**
* If true: do not convert value to JSON on save/load
*
* JavaScript Info:
* @property useRaw
* @type Boolean
*
*/
public void setUseRaw(boolean value) {
getPolymerElement().setUseRaw(value);
}
/**
* The data associated with this storage.
If set to null item will be deleted.
*
* JavaScript Info:
* @property value
* @type *
*
*/
public JavaScriptObject getValue(){
return getPolymerElement().getValue();
}
/**
* The data associated with this storage.
If set to null item will be deleted.
*
* JavaScript Info:
* @property value
* @type *
*
*/
public void setValue(JavaScriptObject value) {
getPolymerElement().setValue(value);
}
/**
* The data associated with this storage.
If set to null item will be deleted.
*
* JavaScript Info:
* @attribute value
*
*/
public void setValue(String value) {
getPolymerElement().setAttribute("value", value);
}
/**
*
*
* JavaScript Info:
* @method attached
*
*/
public void attached() {
getPolymerElement().attached();
}
/**
*
*
* JavaScript Info:
* @method detached
*
*/
public void detached() {
getPolymerElement().detached();
}
/**
*
*
* JavaScript Info:
* @property observers
* @type Array
*
*/
public JsArray getObservers(){
return getPolymerElement().getObservers();
}
/**
*
*
* JavaScript Info:
* @property observers
* @type Array
*
*/
public void setObservers(JsArray value) {
getPolymerElement().setObservers(value);
}
/**
* Fired when value loads from localStorage.
*
* JavaScript Info:
* @event iron-localstorage-load
*/
public HandlerRegistration addIronLocalstorageLoadHandler(IronLocalstorageLoadEventHandler handler) {
return addHandler(handler, IronLocalstorageLoadEvent.TYPE);
}
/**
* Fired when loaded value does not exist.
Event handler can be used to initialize default value.
*
* JavaScript Info:
* @event iron-localstorage-load-empty
*/
public HandlerRegistration addIronLocalstorageLoadEmptyHandler(IronLocalstorageLoadEmptyEventHandler handler) {
return addHandler(handler, IronLocalstorageLoadEmptyEvent.TYPE);
}
}