001: package org.swingml.action;
002:
003: import org.swingml.*;
004: import org.w3c.dom.*;
005:
006: /**
007: * @author dpitt
008: */
009: public class TableBrowserCellUpdate extends RemoteAction {
010:
011: private String colId = null;
012: private String rowId = null;
013: private TableBrowserRemoteActionSubject subject = null;
014: private Object value = null;
015:
016: // apply results to table cell update
017: public void applyResult(RemoteActionResult result) {
018: TableBrowserCellUpdateResult concrete = (TableBrowserCellUpdateResult) result;
019: getSubject().update(concrete.getTargetRowId(),
020: concrete.getTargetColId(), concrete.getValue());
021: }
022:
023: public String createParamString() {
024: String results = null;
025: results = "?name=" + getName();
026: results += "&rowid=" + getRowId();
027: results += "&colid=" + getColId();
028: results += "&Value=" + getValue();
029: return results;
030: }
031:
032: public String getColId() {
033: return colId;
034: }
035:
036: public String getRowId() {
037: return rowId;
038: }
039:
040: public TableBrowserRemoteActionSubject getSubject() {
041: return subject;
042: }
043:
044: public Object getValue() {
045: return value;
046: }
047:
048: public void parseResponse(Node element) {
049: // Parse response XML for action
050: if (element == null) {
051: throw new RuntimeException(
052: "Result XML not returned from remote ACTION URL");
053: }
054: Node resultElement = null;
055: if (element.hasChildNodes()) {
056: // first child should be REMOTE_ACTION_RESULT
057: resultElement = element.getFirstChild();
058: }
059: if (resultElement == null) {
060: throw new RuntimeException(
061: "Result XML for Remote Action is Invalid");
062: }
063: NodeList theNodes = resultElement.getChildNodes();
064: RemoteActionMapper mapper = new RemoteActionMapper();
065: for (int i = 0; i < theNodes.getLength(); i++) {
066: Node node = theNodes.item(i);
067: // if error report
068: if (node.getNodeName().equalsIgnoreCase("ERROR")) {
069: String message = null;
070: NamedNodeMap theAttributes = node.getAttributes();
071: Node theAttribute = null;
072: Node aNode = null;
073: for (int a = 0; a < theAttributes.getLength(); a++) {
074: aNode = theAttributes.item(a);
075: if (aNode.getNodeName().equalsIgnoreCase("message")) {
076: theAttribute = aNode;
077: message = theAttribute.getNodeValue();
078: break;
079: }
080: }
081: showErrorDialog(message);
082: } else if (node.getNodeName().equals("UPDATE")) {
083: TableBrowserCellUpdateResult resultObject = new TableBrowserCellUpdateResult();
084: mapper.mapModelAttributes(node, resultObject);
085: // execute with result object
086: applyResult(resultObject);
087: } else if (node.getNodeName().equals("NO-OP")) {
088: // do nothing no operations
089: }
090: }
091: //execute with result objecterforme
092: }
093:
094: public void processErrorAction(String message) {
095: }
096:
097: public void setColId(String colId) {
098: this .colId = colId;
099: }
100:
101: public void setRowId(String rowId) {
102: this .rowId = rowId;
103: }
104:
105: public void setSubject(TableBrowserRemoteActionSubject model) {
106: this .subject = model;
107: }
108:
109: public void setValue(Object value) {
110: this .value = value;
111: }
112:
113: public void showErrorDialog(String message) {
114: StringBuffer buffer = new StringBuffer();
115: buffer.append("<OPTIONPANE ");
116: buffer.append("NAME=\"");
117: buffer.append("errorPanel");
118: buffer.append("\" ");
119: buffer.append("TEXT=\"");
120: buffer.append(message);
121: buffer.append("\" ");
122: buffer.append("TYPE=\"");
123: buffer.append("Message");
124: buffer.append("\" ");
125: buffer.append("/>");
126:
127: SwingMLRenderer.getRenderer().render(buffer.toString(),
128: SwingMLRenderer.getRenderer().getContentPane());
129: }
130: }
|