KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: DataFieldAttributes.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.data.MetaData;
14 import org.jdesktop.swing.data.NumberMetaData;
15 import org.jdesktop.swing.data.StringMetaData;
16 import org.jdesktop.swing.table.TabularDataMetaData;
17
18 import java.text.SimpleDateFormat JavaDoc;
19
20 import java.util.Date JavaDoc;
21
22 import net.openmarkup.ApplierException;
23 import net.openmarkup.AttributeApplier;
24 import net.openmarkup.Realizable;
25
26 import org.w3c.dom.Element JavaDoc;
27
28 import org.jdesktop.jdnc.markup.elem.ElementProxy;
29
30 /**
31  * @author Amy Fowler
32  */

33 public class DataFieldAttributes {
34
35     public static final AttributeApplier typeApplier = new AttributeApplier() {
36         public void apply(Realizable target, String JavaDoc namespaceURI,
37                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
38             MetaData metaData = (MetaData) target.getObject();
39             Class JavaDoc klass = Decoder.decodeType(attributeValue);
40             if (klass != null) {
41                 metaData.setElementClass(klass);
42             }
43         }
44     };
45
46     public static final AttributeApplier decodeFormatApplier = new AttributeApplier() {
47         public void apply(Realizable target, String JavaDoc namespaceURI,
48                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
49             MetaData metaData = (MetaData) target.getObject();
50             if (metaData.getElementClass() == Date JavaDoc.class) {
51                 metaData.setDecodeFormat(new SimpleDateFormat JavaDoc(attributeValue));
52             }
53             /**@todo aim: should the "else" generate a warning? */
54         }
55     };
56
57     public static final AttributeApplier encodeFormatApplier = new AttributeApplier() {
58         public void apply(Realizable target, String JavaDoc namespaceURI,
59                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
60             MetaData metaData = (MetaData) target.getObject();
61             if (metaData.getElementClass() == Date JavaDoc.class) {
62                 metaData.setEncodeFormat(new SimpleDateFormat JavaDoc(attributeValue));
63             }
64             /**@todo aim: should the "else" generate a warning? */
65         }
66     };
67
68
69     public static final AttributeApplier titleApplier = new AttributeApplier() {
70         public void apply(Realizable target, String JavaDoc namespaceURI,
71                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
72             MetaData metaData = (MetaData) target.getObject();
73             metaData.setLabel(attributeValue);
74         }
75     };
76
77     public static final AttributeApplier displaySizeApplier = new AttributeApplier() {
78         public void apply(Realizable target, String JavaDoc namespaceURI,
79                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
80             StringMetaData metaData = (StringMetaData) target.getObject();
81             try {
82                 metaData.setDisplayWidth(Integer.parseInt(attributeValue));
83             } catch (Exception JavaDoc ex) {
84                 System.out.println("DataElementAttributes.displayWidthApplier: " + ex);
85             }
86         }
87     };
88
89     public static final AttributeApplier maximumApplier = new AttributeApplier() {
90         public void apply(Realizable target, String JavaDoc namespaceURI,
91                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
92             try {
93                 NumberMetaData metaData = (NumberMetaData) target.getObject();
94                 /**@todo aim: handle other number types */
95                 metaData.setMaximum(new Integer JavaDoc(Integer.parseInt(attributeValue)));
96             } catch (Exception JavaDoc ex) {
97                 System.out.println("DataElementAttributes.maximumApplier: " + ex);
98             }
99         }
100     };
101
102     public static final AttributeApplier maximumFieldSizeApplier = new AttributeApplier() {
103         public void apply(Realizable target, String JavaDoc namespaceURI,
104                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
105             try {
106                 StringMetaData metaData = (StringMetaData) target.getObject();
107                 /**@todo aim: handle other number types */
108                 metaData.setMaxLength(Integer.parseInt(attributeValue));
109             } catch (Exception JavaDoc ex) {
110                 System.out.println("DataElementAttributes.maximumLengthApplier: " + ex);
111             }
112         }
113     };
114
115     public static final AttributeApplier minimumApplier = new AttributeApplier() {
116         public void apply(Realizable target, String JavaDoc namespaceURI,
117                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
118             try {
119                 NumberMetaData metaData = (NumberMetaData) target.getObject();
120                 /**@todo aim: handle other number types */
121                 metaData.setMinimum(new Integer JavaDoc(Integer.parseInt(attributeValue)));
122             } catch (Exception JavaDoc ex) {
123                 System.out.println("DataElementAttributes.minimumApplier: " + ex);
124             }
125         }
126     };
127
128     public static final AttributeApplier minimumFieldSizeApplier = new AttributeApplier() {
129         public void apply(Realizable target, String JavaDoc namespaceURI,
130                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
131             try {
132                 StringMetaData metaData = (StringMetaData) target.getObject();
133                 /**@todo aim: handle other number types */
134                 metaData.setMinLength(Integer.parseInt(attributeValue));
135             } catch (Exception JavaDoc ex) {
136                 System.out.println("DataElementAttributes.minimumLengthApplier: " + ex);
137             }
138         }
139     };
140
141     public static final AttributeApplier multiLineApplier = new AttributeApplier() {
142         public void apply(Realizable target, String JavaDoc namespaceURI,
143                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
144             try {
145                 StringMetaData metaData = (StringMetaData) target.getObject();
146                 metaData.setMultiLine(Boolean.valueOf(attributeValue).booleanValue());
147             } catch (Exception JavaDoc ex) {
148                 System.out.println("DataElementAttributes.multiLineApplier: " + ex);
149             }
150         }
151     };
152
153     public static final AttributeApplier nameApplier = new AttributeApplier() {
154         public void apply(Realizable target, String JavaDoc namespaceURI,
155                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
156             MetaData metaData = (MetaData) target.getObject();
157             metaData.setName(attributeValue);
158         }
159     };
160
161     public static final AttributeApplier isReadOnlyApplier = new AttributeApplier() {
162         public void apply(Realizable target, String JavaDoc namespaceURI,
163                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
164             MetaData metaData = (MetaData) target.getObject();
165             metaData.setReadOnly(Boolean.valueOf(attributeValue).booleanValue());
166         }
167     };
168
169     public static final AttributeApplier isRequiredApplier = new AttributeApplier() {
170         public void apply(Realizable target, String JavaDoc namespaceURI,
171                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
172             MetaData metaData = (MetaData) target.getObject();
173             metaData.setRequired(Boolean.valueOf(attributeValue).booleanValue());
174         }
175     };
176
177
178 }
179
Popular Tags