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: * A class that defines the methods required for an object to be used by Matrix.Column instances to
024: format cells of data.
025: * @author Joe Walker [joe at getahead dot org]
026: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
027: */
028: public class ColumnFormat extends jsx3.lang.Object {
029: /**
030: * All reverse ajax proxies need context to work from
031: * @param scriptProxy The place we are writing scripts to
032: * @param context The script that got us to where we are now
033: */
034: public ColumnFormat(Context context, String extension,
035: ScriptProxy scriptProxy) {
036: super (context, extension, scriptProxy);
037: }
038:
039: /**
040: * Returns a column formatter for a string key. The key may be one of the following:
041:
042:
043: @unescape Ð
044:
045: @unescape_all Ð
046:
047: @lookup Ð
048:
049: @datetime[,(short|medium|long|full,format)] Ð
050:
051: @date[,(short|medium|long|full,format)] Ð
052:
053: @time[,(short|medium|long|full,format)] Ð
054:
055: @number[,(integer|percent|currency,format)] Ð
056:
057: @message,format
058: Ð
059: * @param strKey
060: * @param objColumn
061: */
062: @SuppressWarnings("unchecked")
063: public jsx3.gui.matrix.ColumnFormat getInstance(String strKey,
064: jsx3.gui.matrix.Column objColumn) {
065: String extension = "getInstance(\"" + strKey + "\", \""
066: + objColumn + "\").";
067: try {
068: java.lang.reflect.Constructor<jsx3.gui.matrix.ColumnFormat> ctor = jsx3.gui.matrix.ColumnFormat.class
069: .getConstructor(Context.class, String.class,
070: ScriptProxy.class);
071: return ctor.newInstance(this , extension, getScriptProxy());
072: } catch (Exception ex) {
073: throw new IllegalArgumentException("Unsupported type: "
074: + jsx3.gui.matrix.ColumnFormat.class.getName());
075: }
076: }
077:
078: /**
079: * Classes that implement this interface must provide this method to allow for browser-specific or similar type 'switch'. If
080: false is returned, the formatter will not even attempt to iterate
081: * @param callback true if the formatter should be called to iterate and format
082: */
083: @SuppressWarnings("unchecked")
084: public void validate(
085: org.directwebremoting.proxy.Callback<Boolean> callback) {
086: ScriptBuffer script = new ScriptBuffer();
087: String callbackPrefix = "";
088:
089: if (callback != null) {
090: callbackPrefix = "var reply = ";
091: }
092:
093: script.appendCall(callbackPrefix + getContextPath()
094: + "validate");
095:
096: if (callback != null) {
097: String key = org.directwebremoting.extend.CallbackHelper
098: .saveCallback(callback, Boolean.class);
099: script
100: .appendCall("__System.activateCallback", key,
101: "reply");
102: }
103:
104: getScriptProxy().addScript(script);
105: }
106:
107: /**
108: * Formats the Matrix cell, a native DIV element.
109: * @param objDiv on-screen DIV element to be formatted. Note that this DIV is contained within a TD
110: * @param strCDFKey CDF record id for the record in the data model bound to the affected on-screen row
111: * @param objMatrix matrix instance
112: * @param objMatrixColumn matrix column instance
113: * @param intRowNumber row number for row containing this cell (1-based)
114: * @param objServer server instance. Useful for querying locale (for localized output)
115: */
116: public void format(String objDiv, String strCDFKey,
117: jsx3.gui.Matrix objMatrix,
118: jsx3.gui.matrix.Column objMatrixColumn, int intRowNumber,
119: jsx3.app.Server objServer) {
120: ScriptBuffer script = new ScriptBuffer();
121: script.appendCall(getContextPath() + "format", objDiv,
122: strCDFKey, objMatrix, objMatrixColumn, intRowNumber,
123: objServer);
124: getScriptProxy().addScript(script);
125: }
126:
127: }
|