KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > attr > DataColumnAttributes


1 /*
2  * $Id: DataColumnAttributes.java,v 1.1.1.1 2004/06/16 01:43:40 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup.attr;
9
10
11 import org.jdesktop.swing.data.Converters;
12 import org.jdesktop.swing.data.Converter;
13 import org.jdesktop.swing.table.TabularDataMetaData;
14
15 import net.openmarkup.ApplierException;
16 import net.openmarkup.AttributeApplier;
17 import net.openmarkup.Realizable;
18
19 import java.text.SimpleDateFormat JavaDoc;
20
21 import org.w3c.dom.Element JavaDoc;
22
23 import org.jdesktop.jdnc.markup.elem.ElementProxy;
24
25 /**
26  * @author Ramesh Gupta
27  */

28 public class DataColumnAttributes {
29     public static final AttributeApplier dataTypeApplier = new AttributeApplier() {
30         public void apply(Realizable target, String JavaDoc namespaceURI,
31                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
32             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
33             //System.out.println("dataTypeApplier: column="+
34
// (column != null? column.toString():"null"));
35
if (column != null) {
36                 int columnIndex = column.intValue();
37                 if (columnIndex > 0) {
38                     TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable(
39                         (Element JavaDoc) target.getParentNode()).getObject();
40                     Class JavaDoc klass = Decoder.decodeType(attributeValue);
41                     //System.out.println("column class="+klass.getName());
42
if (klass != null) {
43                         metaData.setColumnClass(columnIndex, klass);
44                     }
45                 }
46             }
47         }
48     };
49
50     public static final AttributeApplier dateFormatApplier = new AttributeApplier() {
51         public void apply(Realizable target, String JavaDoc namespaceURI,
52                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
53             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
54             if (column != null) {
55                 int columnIndex = column.intValue();
56                 if (columnIndex > 0) {
57                     TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable(
58                         (Element JavaDoc) target.getParentNode()).getObject();
59                     /**@todo aim: this is lossy - need to work this out */
60                     Converter converter = new Converters.DateConverter(
61                         new SimpleDateFormat JavaDoc(attributeValue),
62                         new SimpleDateFormat JavaDoc("MMMMM d yyyy"));
63                     metaData.setColumnConverter(columnIndex, converter);
64                 }
65             }
66         }
67     };
68
69     public static final AttributeApplier displayLengthApplier = new AttributeApplier() {
70         public void apply(Realizable target, String JavaDoc namespaceURI,
71                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
72             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
73             if (column != null) {
74                 int columnIndex = column.intValue();
75                 if (columnIndex > 0) {
76                     TabularDataMetaData metaData = (TabularDataMetaData)
77                         ElementProxy.getRealizable(
78                         (Element JavaDoc) target.getParentNode()).getObject();
79                     metaData.setColumnDisplaySize(columnIndex, Integer.parseInt(
80                         attributeValue));
81                 }
82             }
83         }
84     };
85
86     public static final AttributeApplier labelApplier = new AttributeApplier() {
87         public void apply(Realizable target, String JavaDoc namespaceURI,
88                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
89             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
90             if (column != null) {
91                 int columnIndex = column.intValue();
92                 if (columnIndex > 0) {
93                     TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable(
94                         (Element JavaDoc) target.getParentNode()).getObject();
95                     metaData.setColumnLabel(columnIndex, attributeValue);
96                 }
97             }
98         }
99     };
100
101     public static final AttributeApplier maximumApplier = new AttributeApplier() {
102         public void apply(Realizable target, String JavaDoc namespaceURI,
103                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
104             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
105             if (column != null) {
106                 int columnIndex = column.intValue();
107                 if (columnIndex > 0) {
108                     TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable(
109                         (Element JavaDoc) target.getParentNode()).getObject();
110                     Class JavaDoc klass = metaData.getColumnClass(columnIndex);
111                     Converter converter = Converters.get(klass);
112                     try {
113                         metaData.setColumnMaximum(columnIndex,
114                                                   converter.decode(attributeValue, null));
115                     } catch (Exception JavaDoc e) {
116                         /**@todo aim: need exception handling */
117                         System.out.println("maximum applier, couldn't convert value "+attributeValue);
118                     }
119                 }
120             }
121         }
122     };
123
124
125     public static final AttributeApplier minimumApplier = new AttributeApplier() {
126         public void apply(Realizable target, String JavaDoc namespaceURI,
127                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
128             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
129             if (column != null) {
130                 int columnIndex = column.intValue();
131                 if (columnIndex > 0) {
132                     TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable(
133                         (Element JavaDoc) target.getParentNode()).getObject();
134                     Class JavaDoc klass = metaData.getColumnClass(columnIndex);
135                     Converter converter = Converters.get(klass);
136                     try {
137                         metaData.setColumnMinimum(columnIndex,
138                                                   converter.decode(attributeValue, null));
139                     } catch (Exception JavaDoc e) {
140                         /**@todo aim: need exception handling */
141                         System.out.println("minimum applier, couldn't convert value "+attributeValue);
142                     }
143                 }
144             }
145         }
146     };
147
148     public static final AttributeApplier nameApplier = new AttributeApplier() {
149         public void apply(Realizable target, String JavaDoc namespaceURI,
150                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
151             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
152             if (column != null) {
153                 int columnIndex = column.intValue();
154                 if (columnIndex > 0) {
155                     TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable(
156                         (Element JavaDoc) target.getParentNode()).getObject();
157                     metaData.setColumnName(columnIndex, attributeValue);
158                 }
159             }
160         }
161     };
162
163     public static final AttributeApplier isReadOnlyApplier = new AttributeApplier() {
164         public void apply(Realizable target, String JavaDoc namespaceURI,
165                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
166             Integer JavaDoc column = (Integer JavaDoc) target.getObject();
167             if (column != null) {
168                 int columnIndex = column.intValue();
169                 if (columnIndex > 0) {
170                     TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable(
171                         (Element JavaDoc) target.getParentNode()).getObject();
172                     metaData.setColumnWritable(columnIndex,
173                             !Boolean.valueOf(attributeValue).booleanValue());
174                 }
175             }
176         }
177     };
178
179 }
180
Popular Tags