001: /*
002: * SwingML Copyright (C) 2002 Ezequiel Cuellar.
003: *
004: * This library is free software; you can redistribute it and/or modify it under
005: * the terms of the GNU Lesser General Public License as published by the Free
006: * Software Foundation; either version 2 of the License, or (at your option) any
007: * later version.
008: *
009: * This library is distributed in the hope that it will be useful, but WITHOUT
010: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012: * details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with this library; if not, write to the Free Software Foundation, Inc.,
016: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: * Authors: Ezequiel Cuellar <ecuellar@crosslogic.com>
019: *
020: */
021:
022: package org.swingml.tablebrowser.ext;
023:
024: import java.awt.*;
025:
026: import javax.swing.*;
027:
028: import org.swingml.*;
029: import org.swingml.component.*;
030: import org.swingml.model.*;
031: import org.swingml.util.*;
032: import org.swingml.xml.*;
033: import org.w3c.dom.*;
034:
035: public class TableBrowserDataMapper extends MapperUtil implements
036: Mapper {
037:
038: public Object getModelToMap(Node aNode, Object aParent,
039: Container aContainer) {
040: TableDataModel theModel = new TableDataModel();
041: SwingMLModel theContainer = (SwingMLModel) aParent;
042: int theColumnIndex = theContainer.getChildren().size();
043: theContainer.addChild(theModel);
044: theModel.setParent(theContainer);
045: theModel.setColumn(theColumnIndex);
046: return theModel;
047: }
048:
049: public void mapModel(Node aNode, Object aParent,
050: Container aContainer) {
051: TableDataModel theModel = (TableDataModel) this .getModelToMap(
052: aNode, aParent, aContainer);
053: this .mapModelAttributes(aNode, theModel, aParent);
054: iterate(aNode, theModel, aContainer);
055: }
056:
057: public void mapModelAttributes(Node aNode, Object aModel,
058: Object aParent) {
059: TableDataModel theModel = (TableDataModel) aModel;
060: super .mapCommonAttributes(theModel, aNode);
061: Node theResultNode = super .getAttribute(aNode,
062: Constants.EDITABLE);
063: if (theResultNode != null) {
064: if (theResultNode.getNodeValue().equalsIgnoreCase(
065: Constants.TRUE)) {
066: theModel.setEditable(true);
067: }
068: }
069: theResultNode = super .getAttribute(aNode, Constants.VALUE);
070: if (theResultNode != null) {
071: String theValue = theResultNode.getNodeValue();
072: Object theType = theModel.getColumn().getType();
073: if (theType instanceof Boolean) {
074: theModel.setValue(new Boolean(theValue));
075: } else if (theType instanceof JComboBox) {
076: theModel.setValue(theValue);
077: } else if (theType instanceof String) {
078: theModel.setValue(theValue);
079: } else if (theType instanceof Color) {
080: ColorComponent color = ColorComponent
081: .getColorByName(theValue);
082: theModel.setValue(color);
083: } else if (theType instanceof DateConverter) {
084: theModel.setValue(theValue);
085: } else if (theType instanceof NumberConverter) {
086: theModel.setValue(theValue);
087: } else if (theType instanceof JButton) {
088: theModel.setValue(theValue);
089: }
090: }
091:
092: theResultNode = super .getAttribute(aNode, Constants.TEXT);
093: if (theResultNode != null) {
094: theModel.setText(theResultNode.getNodeValue());
095: }
096:
097: theResultNode = super .getAttribute(aNode, Constants.ALIGN);
098: if (theResultNode != null) {
099: theModel.setAlignment(theResultNode.getNodeValue());
100: }
101:
102: theResultNode = super .getAttribute(aNode, Constants.START_EDIT);
103: if (theResultNode != null) {
104: if (theResultNode.getNodeValue().equalsIgnoreCase(
105: Constants.TRUE)) {
106: theModel.setStartEdit(true);
107: }
108: }
109:
110: theResultNode = getAttribute(aNode, Constants.AUTO_SELECT);
111: if (null != theResultNode) {
112: theModel.setAutoSelect((new Boolean(theResultNode
113: .getNodeValue())).booleanValue());
114: }
115: }
116: }
|