1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.util.Hashtable ; 11 import java.util.Map ; 12 13 import org.w3c.dom.Element ; 14 import org.jdesktop.swing.treetable.TreeTableModel; 15 import org.jdesktop.jdnc.JNTreeTable; 16 import net.openmarkup.AttributeHandler; 17 import net.openmarkup.ElementAssimilator; 18 import net.openmarkup.ElementHandler; 19 import net.openmarkup.ElementType; 20 import net.openmarkup.Realizable; 21 import org.jdesktop.jdnc.markup.Attributes; 22 import org.jdesktop.jdnc.markup.ElementTypes; 23 import org.jdesktop.jdnc.markup.Namespace; 24 import org.jdesktop.jdnc.markup.attr.TreeTableAttributes; 25 26 27 31 public class TreeTableElement extends TableElement { 32 private static final Map attrMap = new Hashtable (); 33 private static final Map elementMap = new Hashtable (); 34 35 public TreeTableElement(Element element, ElementType elementType) { 36 super(element, elementType); 37 } 38 39 protected Map getAttributeHandlerMap() { 40 return attrMap; 41 } 42 43 protected Map getElementHandlerMap() { 44 return elementMap; 45 } 46 47 public Object instantiate() { 48 object = super.instantiate(); 49 applyAttribute(Namespace.JDNC, Attributes.DATA_SOURCE); 50 applyAttribute(Namespace.JDNC, Attributes.COLLAPSED_ICON); 51 applyAttribute(Namespace.JDNC, Attributes.CONTAINER_ICON); 52 applyAttribute(Namespace.JDNC, Attributes.CLOSED_ICON); 53 applyAttribute(Namespace.JDNC, Attributes.OPEN_ICON); 54 applyAttribute(Namespace.JDNC, Attributes.EXPANDED_ICON); 55 applyAttribute(Namespace.JDNC, Attributes.LEAF_ICON); 56 return object; 57 } 58 59 protected void applyAttributesAfter() { 60 super.applyAttributesAfter(); 61 applyAttribute(Namespace.JDNC, Attributes.EXPANDS_ALL); 62 } 63 64 protected Map registerAttributeHandlers() { 65 Map handlerMap = super.registerAttributeHandlers(); 66 if (handlerMap != null) { 67 handlerMap.put(Namespace.JDNC + ":" + Attributes.DATA_SOURCE, 68 dataSourceHandler); 69 handlerMap.put(Namespace.JDNC + ":" + Attributes.COLLAPSED_ICON, 70 collapsedIconHandler); 71 handlerMap.put(Namespace.JDNC + ":" + Attributes.CLOSED_ICON, 72 containerClosedIconHandler); 73 handlerMap.put(Namespace.JDNC + ":" + Attributes.OPEN_ICON, 74 containerOpenIconHandler); 75 handlerMap.put(Namespace.JDNC + ":" + Attributes.EXPANDS_ALL, 76 expandsAllHandler); 77 handlerMap.put(Namespace.JDNC + ":" + Attributes.EXPANDED_ICON, 78 expandedIconHandler); 79 handlerMap.put(Namespace.JDNC + ":" + Attributes.LEAF_ICON, 80 leafIconHandler); 81 } 82 return handlerMap; 83 } 84 85 protected Map registerElementHandlers() { 86 Map handlerMap = super.registerElementHandlers(); 87 if (handlerMap != null) { 88 handlerMap.put(Namespace.JDNC + ":" + 89 ElementTypes.HIERARCHICAL_DATA.getLocalName(), 90 hierarchicalDataElementHandler); 91 handlerMap.put(Namespace.JDNC + ":" + 92 ElementTypes.TREE_TABLE_COLUMNS.getLocalName(), 93 tableColumnsElementHandler); 94 } 95 return handlerMap; 96 } 97 98 public static final ElementAssimilator dataAssimilator = new ElementAssimilator() { 99 public void assimilate(Realizable parent, Realizable child) { 100 JNTreeTable table = (JNTreeTable)parent.getObject(); 101 TreeTableModel model = (TreeTableModel)child.getObject(); 102 table.setTreeTableModel(model); 103 table.expandRow(0); 104 } 105 }; 106 107 protected static final AttributeHandler dataSourceHandler = 108 new AttributeHandler(Namespace.JDNC, Attributes.DATA_SOURCE, TreeTableAttributes.dataSourceApplier); 109 110 protected static final AttributeHandler collapsedIconHandler = 111 new AttributeHandler(Namespace.JDNC, Attributes.COLLAPSED_ICON, TreeTableAttributes.collapsedIconApplier); 112 113 protected static final AttributeHandler containerClosedIconHandler = 114 new AttributeHandler(Namespace.JDNC, Attributes.CLOSED_ICON, TreeTableAttributes.closedIconApplier); 115 116 protected static final AttributeHandler containerOpenIconHandler = 117 new AttributeHandler(Namespace.JDNC, Attributes.OPEN_ICON, TreeTableAttributes.openIconApplier); 118 119 protected static final AttributeHandler expandsAllHandler = 120 new AttributeHandler(Namespace.JDNC, Attributes.EXPANDS_ALL, TreeTableAttributes.expandsAllApplier); 121 122 protected static final AttributeHandler expandedIconHandler = 123 new AttributeHandler(Namespace.JDNC, Attributes.EXPANDED_ICON, TreeTableAttributes.expandedIconApplier); 124 125 protected static final AttributeHandler leafIconHandler = 126 new AttributeHandler(Namespace.JDNC, Attributes.LEAF_ICON, TreeTableAttributes.leafIconApplier); 127 128 protected static final ElementHandler hierarchicalDataElementHandler = 129 new ElementHandler(ElementTypes.HIERARCHICAL_DATA, dataAssimilator); 130 131 private static final ElementHandler tableColumnsElementHandler = 132 new ElementHandler(ElementTypes.TREE_TABLE_COLUMNS, tableColumnsAssimilator); 133 134 } 135 | Popular Tags |