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;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * Mixin interface allows implementors to show alerts, confirms, and prompts.
024: * @author Joe Walker [joe at getahead dot org]
025: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
026: */
027: public class Alerts extends jsx3.lang.Object {
028: /**
029: * All reverse ajax proxies need context to work from
030: * @param scriptProxy The place we are writing scripts to
031: * @param context The script that got us to where we are now
032: */
033: public Alerts(Context context, String extension,
034: ScriptProxy scriptProxy) {
035: super (context, extension, scriptProxy);
036: }
037:
038: /**
039: * implementors of this mixin interface must implement this method
040: * @return the parent of the alert dialogs
041: */
042: @SuppressWarnings("unchecked")
043: public jsx3.app.Model getAlertsParent() {
044: String extension = "getAlertsParent().";
045: try {
046: java.lang.reflect.Constructor<jsx3.app.Model> ctor = jsx3.app.Model.class
047: .getConstructor(Context.class, String.class,
048: ScriptProxy.class);
049: return ctor.newInstance(this , extension, getScriptProxy());
050: } catch (Exception ex) {
051: throw new IllegalArgumentException("Unsupported type: "
052: + jsx3.app.Model.class.getName());
053: }
054: }
055:
056: /**
057: * implementors of this mixin interface must implement this method
058: * @param returnType The expected return type
059: * @return the parent of the alert dialogs
060: */
061: @SuppressWarnings("unchecked")
062: public <T> T getAlertsParent(Class<T> returnType) {
063: String extension = "getAlertsParent().";
064: try {
065: java.lang.reflect.Constructor<T> ctor = returnType
066: .getConstructor(Context.class, String.class,
067: ScriptProxy.class);
068: return ctor.newInstance(this , extension, getScriptProxy());
069: } catch (Exception ex) {
070: throw new IllegalArgumentException(
071: "Unsupported return type: " + returnType.getName());
072: }
073: }
074:
075: /**
076: * show an alert dialog
077: * @param strTitle the title of the dialog
078: * @param strMessage the message to display
079: * @param fctOnOk callback function on pressing ok button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
080: * @param strOk the text of the ok button, can be false to remove button from display
081: * @param objParams argument to configureAlert()
082: */
083: public void alert(String strTitle, String strMessage,
084: org.directwebremoting.proxy.CodeBlock fctOnOk,
085: String strOk, String objParams) {
086: ScriptBuffer script = new ScriptBuffer();
087: script.appendCall(getContextPath() + "alert", strTitle,
088: strMessage, fctOnOk, strOk, objParams);
089: getScriptProxy().addScript(script);
090: }
091:
092: /**
093: * show a text box input prompt
094: * @param strTitle the title of the dialog
095: * @param strMessage the message to display
096: * @param fctOnOk callback function on pressing ok button, receives the dialog as an argument, and the value of the text input as a second argument; if null the dialog will close itself; if defined must explicitly close the dialog
097: * @param fctOnCancel callback function on pressing cancel button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
098: * @param strOk the text of the ok button
099: * @param strCancel the text of the cancel button
100: * @param objParams argument to configureAlert()
101: */
102: public void prompt(String strTitle, String strMessage,
103: org.directwebremoting.proxy.CodeBlock fctOnOk,
104: org.directwebremoting.proxy.CodeBlock fctOnCancel,
105: String strOk, String strCancel, String objParams) {
106: ScriptBuffer script = new ScriptBuffer();
107: script.appendCall(getContextPath() + "prompt", strTitle,
108: strMessage, fctOnOk, fctOnCancel, strOk, strCancel,
109: objParams);
110: getScriptProxy().addScript(script);
111: }
112:
113: /**
114: * show a confirm alert
115: * @param strTitle the title of the dialog
116: * @param strMessage the message to display
117: * @param fctOnOk callback function on pressing ok button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
118: * @param fctOnCancel callback function on pressing cancel button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
119: * @param strOk the text of the ok button
120: * @param strCancel the text of the cancel button
121: * @param intBtnDefault the bold button that receives return key, 1:ok, 2:cancel, 3:no
122: * @param fctOnNo callback function on pressing no button, receives the dialog as an argument; if null the dialog will close itself; if defined must explicitly close the dialog
123: * @param strNo the text of the no button
124: * @param objParams argument to configureAlert()
125: */
126: public void confirm(String strTitle, String strMessage,
127: org.directwebremoting.proxy.CodeBlock fctOnOk,
128: org.directwebremoting.proxy.CodeBlock fctOnCancel,
129: String strOk, String strCancel, int intBtnDefault,
130: org.directwebremoting.proxy.CodeBlock fctOnNo,
131: String strNo, String objParams) {
132: ScriptBuffer script = new ScriptBuffer();
133: script.appendCall(getContextPath() + "confirm", strTitle,
134: strMessage, fctOnOk, fctOnCancel, strOk, strCancel,
135: intBtnDefault, fctOnNo, strNo, objParams);
136: getScriptProxy().addScript(script);
137: }
138:
139: /**
140: * configure the dialog
141: * @param objDialog the dialog
142: * @param objParams may include fields 'width', 'height', 'noTitle', and 'nonModal'.
143: */
144: public void configureAlert(java.lang.Object objDialog,
145: jsx3.lang.Object objParams) {
146: ScriptBuffer script = new ScriptBuffer();
147: script.appendCall(getContextPath() + "configureAlert",
148: objDialog, objParams);
149: getScriptProxy().addScript(script);
150: }
151:
152: }
|