KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > elem > TreeTableElement


1 /*
2  * $Id: TreeTableElement.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.elem;
9
10 import java.util.Hashtable JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import org.w3c.dom.Element JavaDoc;
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 /**
28  *
29  * @author Ramesh Gupta
30  */

31 public class TreeTableElement extends TableElement {
32     private static final Map JavaDoc attrMap = new Hashtable JavaDoc();
33     private static final Map JavaDoc elementMap = new Hashtable JavaDoc();
34
35     public TreeTableElement(Element JavaDoc element, ElementType elementType) {
36         super(element, elementType);
37     }
38
39     protected Map JavaDoc getAttributeHandlerMap() {
40         return attrMap;
41     }
42
43     protected Map JavaDoc getElementHandlerMap() {
44         return elementMap;
45     }
46
47     public Object JavaDoc 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 JavaDoc registerAttributeHandlers() {
65         Map JavaDoc 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 JavaDoc registerElementHandlers() {
86         Map JavaDoc 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