01: /*
02: * SwingML Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or modify it under
05: * the terms of the GNU Lesser General Public License as published by the Free
06: * Software Foundation; either version 2 of the License, or (at your option) any
07: * later version.
08: *
09: * This library is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12: * details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with this library; if not, write to the Free Software Foundation, Inc.,
16: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: * Authors: Ezequiel Cuellar <ecuellar@crosslogic.com> Marcelo W. Lopez Cremona
19: * <marcelo_java@argentina.com>
20: *
21: */
22:
23: package org.swingml.xml.mapper;
24:
25: import java.awt.*;
26:
27: import javax.swing.*;
28:
29: import org.swingml.*;
30: import org.swingml.component.*;
31: import org.swingml.model.*;
32: import org.swingml.xml.*;
33: import org.w3c.dom.*;
34:
35: public class TableDataMapper extends MapperUtil implements Mapper {
36:
37: public Object getModelToMap(Node aNode, Object aParent,
38: Container aContainer) {
39: TableDataModel theModel = new TableDataModel();
40: SwingMLModel theContainer = (SwingMLModel) aParent;
41: int theColumnIndex = theContainer.getChildren().size();
42: theContainer.addChild(theModel);
43: theModel.setParent(theContainer);
44: theModel.setColumn(theColumnIndex);
45: return theModel;
46: }
47:
48: public void mapModel(Node aNode, Object aParent,
49: Container aContainer) {
50: TableDataModel theModel = (TableDataModel) this .getModelToMap(
51: aNode, aParent, aContainer);
52: this .mapModelAttributes(aNode, theModel, aParent);
53: iterate(aNode, theModel, aContainer);
54: }
55:
56: public void mapModelAttributes(Node aNode, Object aModel,
57: Object aParent) {
58: TableDataModel theModel = (TableDataModel) aModel;
59: super .mapCommonAttributes(theModel, aNode);
60: Node theResultNode = super .getAttribute(aNode,
61: Constants.EDITABLE);
62: if (theResultNode != null) {
63: if (theResultNode.getNodeValue().equalsIgnoreCase(
64: Constants.TRUE)) {
65: theModel.setEditable(true);
66: }
67: }
68: theResultNode = super .getAttribute(aNode, Constants.VALUE);
69: if (theResultNode != null) {
70: String theValue = theResultNode.getNodeValue();
71: Object theType = theModel.getColumn().getType();
72: if (theType instanceof Boolean) {
73: theModel.setValue(new Boolean(theValue));
74: } else if (theType instanceof JComboBox) {
75: theModel.setValue(theValue);
76: } else if (theType instanceof String) {
77: theModel.setValue(theValue);
78: } else if (theType instanceof Color) {
79: ColorComponent color = ColorComponent
80: .getColorByName(theValue);
81: theModel.setValue(color);
82: }
83: } else {
84: theResultNode = super.getAttribute(aNode, Constants.TEXT);
85: if (theResultNode != null) {
86: theModel.setValue(theResultNode.getNodeValue());
87: }
88: }
89:
90: theResultNode = super.getAttribute(aNode, Constants.ALIGN);
91: if (theResultNode != null) {
92: theModel.setAlignment(theResultNode.getNodeValue());
93: }
94: }
95: }
|