001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.client.widgets;
009:
010: import com.google.gwt.core.client.JavaScriptObject;
011: import com.google.gwt.user.client.Element;
012: import com.gwtext.client.core.JsObject;
013: import com.gwtext.client.util.JavaScriptObjectHelper;
014:
015: /**
016: * A simple utility class for generically masking elements while loading data. If the element being masked has an
017: * underlying {@link com.gwtext.client.data.Store}, the masking will be automatically synchronized with the store's
018: * loading process and the mask element will be cached for reuse. For all other elements, this mask will replace the
019: * element's UpdateManager load indicator and will be destroyed after the initial load.
020: */
021: public class LoadMask extends JsObject {
022:
023: private String message;
024: private String messageCls = "x-mask-loading";
025: private boolean removeMask;
026:
027: /**
028: * Create a new LoadMask.
029: *
030: * @param element the element to mask
031: * @param message the text to display in a centered loading message box
032: */
033: public LoadMask(Element element, String message) {
034: this .message = message;
035: JavaScriptObject config = JavaScriptObjectHelper.createObject();
036: JavaScriptObjectHelper.setAttribute(config, "msg", message);
037: jsObj = create(element, config);
038: }
039:
040: /**
041: * Create a new LoadMask.
042: *
043: * @param element the element to mask
044: * @param message the text to display in a centered loading message box
045: * @param messageCls the CSS class to apply to the loading message element (defaults to "x-mask-loading").
046: * @param removeMask true to create a single-use mask that is automatically destroyed after loading (useful for page loads),
047: * false to persist the mask element reference for multiple uses (e.g., for paged data widgets).
048: */
049: public LoadMask(Element element, String message, String messageCls,
050: boolean removeMask) {
051: this .message = message;
052: this .messageCls = messageCls;
053: this .removeMask = removeMask;
054: JavaScriptObject config = JavaScriptObjectHelper.createObject();
055: JavaScriptObjectHelper.setAttribute(config, "msg", message);
056: JavaScriptObjectHelper.setAttribute(config, "msgCls",
057: messageCls);
058: JavaScriptObjectHelper.setAttribute(config, "removeMask",
059: removeMask);
060: jsObj = create(element, config);
061: }
062:
063: /**
064: * Create a new LoadMask.
065: *
066: * @param id the element ID to mask
067: * @param message the text to display in a centered loading message box
068: */
069: public LoadMask(String id, String message) {
070: this .message = message;
071: JavaScriptObject config = JavaScriptObjectHelper.createObject();
072: JavaScriptObjectHelper.setAttribute(config, "msg", message);
073: jsObj = create(id, config);
074: }
075:
076: /**
077: * Create a new LoadMask.
078: *
079: * @param id the element ID to mask
080: * @param message the text to display in a centered loading message box
081: * @param messageCls the CSS class to apply to the loading message element (defaults to "x-mask-loading").
082: * @param removeMask true to create a single-use mask that is automatically destroyed after loading (useful for page loads),
083: * false to persist the mask element reference for multiple uses (e.g., for paged data widgets).
084: */
085: public LoadMask(String id, String message, String messageCls,
086: boolean removeMask) {
087: this .message = message;
088: this .messageCls = messageCls;
089: this .removeMask = removeMask;
090: JavaScriptObject config = JavaScriptObjectHelper.createObject();
091: JavaScriptObjectHelper.setAttribute(config, "msg", message);
092: JavaScriptObjectHelper.setAttribute(config, "msgCls",
093: messageCls);
094: JavaScriptObjectHelper.setAttribute(config, "removeMask",
095: removeMask);
096: jsObj = create(id, config);
097: }
098:
099: private native JavaScriptObject create(Element element,
100: JavaScriptObject config) /*-{
101: return new $wnd.Ext.LoadMask(element, config);
102: }-*/;
103:
104: private native JavaScriptObject create(String id,
105: JavaScriptObject config) /*-{
106: return new $wnd.Ext.LoadMask(id, config);
107: }-*/;
108:
109: /**
110: * Disables the mask to prevent it from being displayed.
111: */
112: public native void disable() /*-{
113: var lm = this.@com.gwtext.client.core.JsObject::getJsObj()();
114: lm.disable();
115: }-*/;
116:
117: /**
118: * Enables the mask so that it can be displayed.
119: */
120: public native void enable() /*-{
121: var lm = this.@com.gwtext.client.core.JsObject::getJsObj()();
122: lm.enable();
123: }-*/;
124:
125: /**
126: * True if the mask is currently disabled so that it will not be displayed (defaults to false)
127: *
128: * @return true if mask disabled
129: */
130: public native boolean isDisabled() /*-{
131: var lm = this.@com.gwtext.client.core.JsObject::getJsObj()();
132: return lm.disabled;
133: }-*/;
134:
135: /**
136: * The text to display in a centered loading message box (defaults to 'Loading...').
137: *
138: * @return the messsage text
139: */
140: public String getMessage() {
141: return message;
142: }
143:
144: /**
145: * The CSS class to apply to the loading message element (defaults to "x-mask-loading").
146: *
147: * @return the message CSS class
148: */
149: public String getMessageCls() {
150: return messageCls;
151: }
152:
153: /**
154: * True to create a single-use mask that is automatically destroyed after loading (useful for page loads), False to persist the mask element reference for multiple uses (e.g., for paged data widgets).
155: * Defaults to false.
156: *
157: * @return true to create a single-use mask
158: */
159: public boolean isRemoveMask() {
160: return removeMask;
161: }
162: }
|