1 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 ; 20 21 import org.w3c.dom.Element ; 22 23 import org.jdesktop.jdnc.markup.elem.ElementProxy; 24 25 28 public class DataColumnAttributes { 29 public static final AttributeApplier dataTypeApplier = new AttributeApplier() { 30 public void apply(Realizable target, String namespaceURI, 31 String attributeName, String attributeValue) throws ApplierException { 32 Integer column = (Integer ) target.getObject(); 33 if (column != null) { 36 int columnIndex = column.intValue(); 37 if (columnIndex > 0) { 38 TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable( 39 (Element ) target.getParentNode()).getObject(); 40 Class klass = Decoder.decodeType(attributeValue); 41 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 namespaceURI, 52 String attributeName, String attributeValue) throws ApplierException { 53 Integer column = (Integer ) target.getObject(); 54 if (column != null) { 55 int columnIndex = column.intValue(); 56 if (columnIndex > 0) { 57 TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable( 58 (Element ) target.getParentNode()).getObject(); 59 60 Converter converter = new Converters.DateConverter( 61 new SimpleDateFormat (attributeValue), 62 new SimpleDateFormat ("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 namespaceURI, 71 String attributeName, String attributeValue) throws ApplierException { 72 Integer column = (Integer ) target.getObject(); 73 if (column != null) { 74 int columnIndex = column.intValue(); 75 if (columnIndex > 0) { 76 TabularDataMetaData metaData = (TabularDataMetaData) 77 ElementProxy.getRealizable( 78 (Element ) 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 namespaceURI, 88 String attributeName, String attributeValue) throws ApplierException { 89 Integer column = (Integer ) target.getObject(); 90 if (column != null) { 91 int columnIndex = column.intValue(); 92 if (columnIndex > 0) { 93 TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable( 94 (Element ) 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 namespaceURI, 103 String attributeName, String attributeValue) throws ApplierException { 104 Integer column = (Integer ) target.getObject(); 105 if (column != null) { 106 int columnIndex = column.intValue(); 107 if (columnIndex > 0) { 108 TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable( 109 (Element ) target.getParentNode()).getObject(); 110 Class klass = metaData.getColumnClass(columnIndex); 111 Converter converter = Converters.get(klass); 112 try { 113 metaData.setColumnMaximum(columnIndex, 114 converter.decode(attributeValue, null)); 115 } catch (Exception e) { 116 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 namespaceURI, 127 String attributeName, String attributeValue) throws ApplierException { 128 Integer column = (Integer ) target.getObject(); 129 if (column != null) { 130 int columnIndex = column.intValue(); 131 if (columnIndex > 0) { 132 TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable( 133 (Element ) target.getParentNode()).getObject(); 134 Class klass = metaData.getColumnClass(columnIndex); 135 Converter converter = Converters.get(klass); 136 try { 137 metaData.setColumnMinimum(columnIndex, 138 converter.decode(attributeValue, null)); 139 } catch (Exception e) { 140 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 namespaceURI, 150 String attributeName, String attributeValue) throws ApplierException { 151 Integer column = (Integer ) target.getObject(); 152 if (column != null) { 153 int columnIndex = column.intValue(); 154 if (columnIndex > 0) { 155 TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable( 156 (Element ) 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 namespaceURI, 165 String attributeName, String attributeValue) throws ApplierException { 166 Integer column = (Integer ) target.getObject(); 167 if (column != null) { 168 int columnIndex = column.intValue(); 169 if (columnIndex > 0) { 170 TabularDataMetaData metaData = (TabularDataMetaData) ElementProxy.getRealizable( 171 (Element ) target.getParentNode()).getObject(); 172 metaData.setColumnWritable(columnIndex, 173 !Boolean.valueOf(attributeValue).booleanValue()); 174 } 175 } 176 } 177 }; 178 179 } 180 | Popular Tags |