001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package jsx3.gui.matrix;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * The interface defining the methods that affect the behavior of an object used as an edit mask in a matrix column.
024:
025: If an object is placed in the DOM as a child of a matrix column, it will be used as an edit mask. Any methods
026: in this interface that the object does not implement will be inserted into the object. This interface is a "loose"
027: interface because the class of an edit mask does not need to implement it in its class declaration. The class
028: simply needs to define any methods whose default behavior it wishes to override.
029:
030: Any edit mask that implements the jsx3.gui.Form interface will have the methods in this interface
031: inserted into it. If the edit mask does not implement jsx3.gui.Form but extends
032: jsx3.gui.Block, the methods in the jsx3.gui.Matrix.BlockMask interface are inserted
033: instead.
034: * @author Joe Walker [joe at getahead dot org]
035: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
036: */
037: public class EditMask extends jsx3.lang.Object {
038: /**
039: * All reverse ajax proxies need context to work from
040: * @param scriptProxy The place we are writing scripts to
041: * @param context The script that got us to where we are now
042: */
043: public EditMask(Context context, String extension,
044: ScriptProxy scriptProxy) {
045: super (context, extension, scriptProxy);
046: }
047:
048: /**
049: * This method is called once when the edit mask is discovered by the matrix column to give it an opportunity
050: to initialize itself.
051: * @param objColumn the matrix column parent.
052: */
053: public void emInit(jsx3.gui.matrix.Column objColumn) {
054: ScriptBuffer script = new ScriptBuffer();
055: script.appendCall(getContextPath() + "emInit", objColumn);
056: getScriptProxy().addScript(script);
057: }
058:
059: /**
060: * Called whenever an edit session begins.
061: * @param strValue
062: * @param objTdDim
063: * @param objPaneDim
064: * @param objMatrix
065: * @param objColumn
066: * @param strRecordId
067: * @param objTD
068: * @param callback <code>false</code> to cancel the edit session.
069: */
070: @SuppressWarnings("unchecked")
071: public void emBeginEdit(String strValue, jsx3.lang.Object objTdDim,
072: jsx3.lang.Object objPaneDim, jsx3.gui.Matrix objMatrix,
073: jsx3.gui.matrix.Column objColumn, String strRecordId,
074: String objTD,
075: org.directwebremoting.proxy.Callback<Boolean> callback) {
076: ScriptBuffer script = new ScriptBuffer();
077: String callbackPrefix = "";
078:
079: if (callback != null) {
080: callbackPrefix = "var reply = ";
081: }
082:
083: script.appendCall(callbackPrefix + getContextPath()
084: + "emBeginEdit", strValue, objTdDim, objPaneDim,
085: objMatrix, objColumn, strRecordId, objTD);
086:
087: if (callback != null) {
088: String key = org.directwebremoting.extend.CallbackHelper
089: .saveCallback(callback, Boolean.class);
090: script
091: .appendCall("__System.activateCallback", key,
092: "reply");
093: }
094:
095: getScriptProxy().addScript(script);
096: }
097:
098: /**
099: * Called when the current edit session ends. This method should return the edited value.
100: * @param callback the edited value.
101: */
102: @SuppressWarnings("unchecked")
103: public void emEndEdit(
104: org.directwebremoting.proxy.Callback<String> callback) {
105: ScriptBuffer script = new ScriptBuffer();
106: String callbackPrefix = "";
107:
108: if (callback != null) {
109: callbackPrefix = "var reply = ";
110: }
111:
112: script.appendCall(callbackPrefix + getContextPath()
113: + "emEndEdit");
114:
115: if (callback != null) {
116: String key = org.directwebremoting.extend.CallbackHelper
117: .saveCallback(callback, String.class);
118: script
119: .appendCall("__System.activateCallback", key,
120: "reply");
121: }
122:
123: getScriptProxy().addScript(script);
124: }
125:
126: /**
127: * Returns the current value stored in the edit mask.
128: * @param callback the current value of the edit mask.
129: */
130: @SuppressWarnings("unchecked")
131: public void emGetValue(
132: org.directwebremoting.proxy.Callback<String> callback) {
133: ScriptBuffer script = new ScriptBuffer();
134: String callbackPrefix = "";
135:
136: if (callback != null) {
137: callbackPrefix = "var reply = ";
138: }
139:
140: script.appendCall(callbackPrefix + getContextPath()
141: + "emGetValue");
142:
143: if (callback != null) {
144: String key = org.directwebremoting.extend.CallbackHelper
145: .saveCallback(callback, String.class);
146: script
147: .appendCall("__System.activateCallback", key,
148: "reply");
149: }
150:
151: getScriptProxy().addScript(script);
152: }
153:
154: /**
155: * Suspends an edit session so that if this mask loses focus, the edit session does not close.
156: */
157: public void suspendEditSession() {
158: ScriptBuffer script = new ScriptBuffer();
159: script.appendCall(getContextPath() + "suspendEditSession");
160: getScriptProxy().addScript(script);
161: }
162:
163: /**
164: * Resumes an edit session so that the edit session will close the next time this mask loses focus.
165: */
166: public void resumeEditSession() {
167: ScriptBuffer script = new ScriptBuffer();
168: script.appendCall(getContextPath() + "resumeEditSession");
169: getScriptProxy().addScript(script);
170: }
171:
172: /**
173: * Returns the state of the current edit session if this object is involved in a jsx3.gui.Matrix
174: edit mask session. The state has the following keys:
175:
176: matrix {jsx3.gui.Matrix}
177: column {jsx3.gui.Matrix.Column}
178: recordId {String}
179: td {HTMLElement}
180: value {String} may be null
181: * @return the edit session.
182: */
183: @SuppressWarnings("unchecked")
184: public jsx3.lang.Object emGetSession() {
185: String extension = "emGetSession().";
186: try {
187: java.lang.reflect.Constructor<jsx3.lang.Object> ctor = jsx3.lang.Object.class
188: .getConstructor(Context.class, String.class,
189: ScriptProxy.class);
190: return ctor.newInstance(this , extension, getScriptProxy());
191: } catch (Exception ex) {
192: throw new IllegalArgumentException("Unsupported type: "
193: + jsx3.lang.Object.class.getName());
194: }
195: }
196:
197: /**
198: * Returns the state of the current edit session if this object is involved in a jsx3.gui.Matrix
199: edit mask session. The state has the following keys:
200:
201: matrix {jsx3.gui.Matrix}
202: column {jsx3.gui.Matrix.Column}
203: recordId {String}
204: td {HTMLElement}
205: value {String} may be null
206: * @param returnType The expected return type
207: * @return the edit session.
208: */
209: @SuppressWarnings("unchecked")
210: public <T> T emGetSession(Class<T> returnType) {
211: String extension = "emGetSession().";
212: try {
213: java.lang.reflect.Constructor<T> ctor = returnType
214: .getConstructor(Context.class, String.class,
215: ScriptProxy.class);
216: return ctor.newInstance(this , extension, getScriptProxy());
217: } catch (Exception ex) {
218: throw new IllegalArgumentException(
219: "Unsupported return type: " + returnType.getName());
220: }
221: }
222:
223: /**
224: * Commits the current edit session of this edit mask.
225: * @param objEvent the wrapped browser event that logically caused this commit to occur. If this
226: parameter is provided then all the model events related to committing an edit session are triggered.
227: * @param bKeepOpen if <code>true</code> then the current value of this edit mask is committed without
228: closing the current edit session.
229: */
230: public void commitEditMask(jsx3.gui.Event objEvent,
231: boolean bKeepOpen) {
232: ScriptBuffer script = new ScriptBuffer();
233: script.appendCall(getContextPath() + "commitEditMask",
234: objEvent, bKeepOpen);
235: getScriptProxy().addScript(script);
236: }
237:
238: }
|