1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import org.jdesktop.swing.data.MetaData; 11 import org.jdesktop.swing.data.DefaultTableModelExt; 12 13 import org.jdesktop.swing.data.DOMAdapter; 14 15 import org.jdesktop.jdnc.markup.Attributes; 16 import org.jdesktop.jdnc.markup.ElementTypes; 17 import org.jdesktop.jdnc.markup.Namespace; 18 import org.jdesktop.jdnc.markup.attr.DataAttributes; 19 20 import java.io.IOException ; 21 22 import java.util.ArrayList ; 23 import java.util.Hashtable ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import net.openmarkup.AttributeHandler; 28 import net.openmarkup.ElementAssimilator; 29 import net.openmarkup.ElementHandler; 30 import net.openmarkup.ElementType; 31 import net.openmarkup.Realizable; 32 import net.openmarkup.Scribe; 33 34 import org.w3c.dom.Element ; 35 36 41 public class DataElement extends ElementProxy { 42 private static final Map attrMap = new Hashtable (); 43 private static final Map elementMap = new Hashtable (); 44 private static final Map mediaTypeRepresentation = new Hashtable (); 45 46 public DataElement(Element element, ElementType elementType) { 47 super(element, elementType); 48 } 49 50 protected void applyAttributesAfter() { 51 super.applyAttributesAfter(); 52 applyAttribute(Namespace.JDNC, Attributes.IS_FIRST_ROW_HEADER); 53 applyAttribute(Namespace.JDNC, Attributes.COLUMN_DELIMITER); 54 applyAttribute(Namespace.JDNC, Attributes.SOURCE); 55 applyAttribute(Namespace.JDNC, Attributes.ACTUATE); 58 String actuateValue = this.getAttributeNSOptional(Namespace.JDNC, Attributes.ACTUATE); 60 if (actuateValue.length() == 0) { 61 try { 62 DataAttributes.actuateData((DefaultTableModelExt)getObject(), actuateValue); 63 } catch (Exception ex) { 64 Scribe.getLogger().warning("DataElement Error actuating data: " + ex.getMessage()); 65 } 66 } 67 } 68 69 protected Map registerAttributeHandlers() { 70 Map handlerMap = super.registerAttributeHandlers(); 71 if (handlerMap != null) { 72 handlerMap.put(Namespace.JDNC + ":" + Attributes.ACTUATE, actuateHandler); 73 handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_FIRST_ROW_HEADER, firstRowHeaderHandler); 74 handlerMap.put(Namespace.JDNC + ":" + Attributes.COLUMN_DELIMITER, columnDelimiterHandler); 75 handlerMap.put(Namespace.JDNC + ":" + Attributes.SOURCE, sourceHandler); 76 } 77 return handlerMap; 78 } 79 80 protected Map registerElementHandlers() { 81 Map handlerMap = super.registerElementHandlers(); 82 if (handlerMap != null) { 83 handlerMap.put(Namespace.JDNC + ":" +ElementTypes.META_DATA.getLocalName(), 85 metaDataElementHandler); 86 } 87 return handlerMap; 88 } 89 90 protected Map getAttributeHandlerMap() { 91 return attrMap; 92 } 93 94 protected Map getElementHandlerMap() { 95 return elementMap; 96 } 97 98 public static final ElementAssimilator metaDataAssimilator = new ElementAssimilator() { 99 public void assimilate(Realizable parent, Realizable child) { 100 DefaultTableModelExt data = (DefaultTableModelExt)parent.getObject(); 101 List list = (List )child.getObject(); 102 int columnCount = list.size(); 103 data.setColumnCount(columnCount); 104 for(int i = 0; i < columnCount; i++) { 105 data.setColumnMetaData(i, (MetaData)list.get(i)); 106 } 107 } 108 }; 109 110 private static final AttributeHandler actuateHandler = 111 new AttributeHandler(Namespace.JDNC, Attributes.ACTUATE, DataAttributes.actuateApplier); 112 113 private static final AttributeHandler columnDelimiterHandler = 114 new AttributeHandler(Namespace.JDNC, Attributes.COLUMN_DELIMITER, DataAttributes.columnDelimiterApplier); 115 116 private static final AttributeHandler firstRowHeaderHandler = 117 new AttributeHandler(Namespace.JDNC, Attributes.IS_FIRST_ROW_HEADER, DataAttributes.firstRowHeaderApplier); 118 119 private static final AttributeHandler sourceHandler = 120 new AttributeHandler(Namespace.JDNC, Attributes.SOURCE, DataAttributes.sourceApplier); 121 122 private static final ElementHandler metaDataElementHandler = 123 new ElementHandler(ElementTypes.META_DATA, metaDataAssimilator); 124 125 126 } 127 | Popular Tags |