001: /*
002: * SwingML Copyright (C) 2002 SwingML Team
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> Farid Ibrahim
019: * <faridibrahim@lycos.com>
020: */
021:
022: package org.swingml.model;
023:
024: import java.util.*;
025:
026: import javax.swing.*;
027:
028: import org.swingml.*;
029: import org.swingml.component.*;
030: import org.swingml.system.*;
031:
032: public class TableDataModel extends SwingMLModel {
033:
034: private String alignment = Constants.LEFT;
035: private boolean autoSelect = true;
036: private TableColumnModel column = null;
037: private boolean editable = false;
038: private boolean startEdit;
039: private Object value = null;
040:
041: public TableDataModel() {
042: super ();
043: }
044:
045: public String getAlignment() {
046: return alignment;
047: }
048:
049: public TableColumnModel getColumn() {
050: return this .column;
051: }
052:
053: public List getIcons() {
054: return getChildren();
055: }
056:
057: public Object getValue() {
058: return this .value;
059: }
060:
061: public boolean hasIcons() {
062: return (this .getChildren() != null && !this .getChildren()
063: .isEmpty());
064: }
065:
066: public boolean isEditable() {
067: return this .editable;
068: }
069:
070: public boolean isStartEdit() {
071: return this .startEdit;
072: }
073:
074: public void setAlignment(String align) {
075: // ignore anything not Center, Left or Right
076: if (align.equalsIgnoreCase(Constants.CENTER)
077: || align.equalsIgnoreCase(Constants.LEFT)
078: || align.equalsIgnoreCase(Constants.RIGHT)) {
079: this .alignment = align;
080: } else {
081: this .alignment = Constants.LEFT;
082: }
083: }
084:
085: public void setAutoSelect(boolean shouldAutoSelect) {
086: this .autoSelect = shouldAutoSelect;
087: }
088:
089: public void setColumn(int aColumnIndex) {
090: JTableModel theTableModel = (JTableModel) super .getParent()
091: .getParent();
092: this .column = (TableColumnModel) theTableModel.getColumns()
093: .get(aColumnIndex);
094: }
095:
096: public void setEditable(boolean aEditable) {
097: this .editable = aEditable;
098: }
099:
100: public void setStartEdit(boolean shouldStartEdit) {
101: this .startEdit = shouldStartEdit;
102: }
103:
104: public void setValue(Object aValue) {
105: this .value = aValue;
106: }
107:
108: public boolean shoudlAutoSelectOnEdit() {
109: return autoSelect;
110: }
111:
112: public void validate() {
113: if (this .getColumn().getType().getClass().equals(
114: JComboBox.class)) {
115: Vector theItems = this .getColumn().getItems();
116: if (theItems != null) {
117: if (!theItems.contains(this .getValue().toString())) {
118: SwingMLLogger
119: .getInstance()
120: .log(
121: "Syntax error: The VALUE "
122: + this .getValue()
123: + " specified in the TD element of the TC with text "
124: + getColumn().getText()
125: + " does not match one of the values specified in the ITEMS parameter.");
126: }
127: }
128: }
129:
130: if (this .getColumn().getType().getClass().equals(
131: ColorComponent.class)) {
132: Vector theItems = this .getColumn().getItems();
133: if (theItems != null) {
134: if (this .getValue() == null) {
135: SwingMLLogger
136: .getInstance()
137: .log(
138: "Syntax error: The VALUE specified in the TD element of the TC with text "
139: + getColumn().getText()
140: + " does not match one of the values specified in the ITEMS parameter.");
141: }
142: }
143: }
144: }
145: }
|