KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TreeTableAttributes.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 import java.net.URL JavaDoc;
11 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
12
13 import javax.swing.ImageIcon JavaDoc;
14
15 import org.w3c.dom.Document JavaDoc;
16 import org.jdesktop.swing.data.DOMAdapter;
17 import org.jdesktop.jdnc.JNTreeTable;
18 import org.jdesktop.jdnc.markup.RealizationUtils;
19 import net.openmarkup.ApplierException;
20 import net.openmarkup.AttributeApplier;
21 import net.openmarkup.Realizable;
22
23 /**
24  * @author Ramesh Gupta
25  */

26 public class TreeTableAttributes {
27     public static final AttributeApplier dataSourceApplier = new AttributeApplier() {
28         public void apply(Realizable target, String JavaDoc namespaceURI,
29                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
30
31             // Validate the URL before we do anything else.
32
URL JavaDoc url = target.getResolvedURL(attributeValue);
33             RealizationUtils.validateURL(url);
34
35             try {
36                 DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
37                 dbf.setNamespaceAware(true);
38                 dbf.setIgnoringComments(true);
39                 Document JavaDoc dom = dbf.newDocumentBuilder().parse(
40                     url.toExternalForm());
41                 JNTreeTable table = (JNTreeTable) target.getObject();
42                 table.setTreeTableModel(new DOMAdapter(dom));
43                 table.expandRow(0);
44             }
45             catch (Exception JavaDoc ex) {
46                 throw new ApplierException("Couldn't set data source " +
47                     attributeName + "=" + attributeValue, ex);
48             }
49         }
50     };
51
52     public static final AttributeApplier collapsedIconApplier = new AttributeApplier() {
53         public void apply(Realizable target, String JavaDoc namespaceURI,
54                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
55             URL JavaDoc url = target.getResolvedURL(attributeValue);
56             if (url != null) {
57                 JNTreeTable table = (JNTreeTable) target.getObject();
58                 table.setCollapsedIcon(new ImageIcon JavaDoc(url));
59             }
60             else {
61                 System.out.println("Couldn't resolve URL: " + attributeValue);
62             }
63         }
64     };
65
66     public static final AttributeApplier closedIconApplier = new AttributeApplier() {
67         public void apply(Realizable target, String JavaDoc namespaceURI,
68                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
69             URL JavaDoc url = target.getResolvedURL(attributeValue);
70             if (url != null) {
71                 JNTreeTable table = (JNTreeTable) target.getObject();
72                 table.setClosedIcon(new ImageIcon JavaDoc(url));
73             }
74             else {
75                 System.out.println("Couldn't resolve URL: " + attributeValue);
76             }
77         }
78     };
79
80     public static final AttributeApplier openIconApplier = new AttributeApplier() {
81         public void apply(Realizable target, String JavaDoc namespaceURI,
82                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
83             URL JavaDoc url = target.getResolvedURL(attributeValue);
84             if (url != null) {
85                 JNTreeTable table = (JNTreeTable) target.getObject();
86                 table.setOpenIcon(new ImageIcon JavaDoc(url));
87             }
88             else {
89                 System.out.println("Couldn't resolve URL: " + attributeValue);
90             }
91         }
92     };
93
94     public static final AttributeApplier expandsAllApplier = new AttributeApplier() {
95         public void apply(Realizable target, String JavaDoc namespaceURI,
96                           String JavaDoc attributeName, String JavaDoc attributeValue) {
97             JNTreeTable table = (JNTreeTable) target.getObject();
98             boolean expandsAll = Boolean.valueOf(attributeValue).booleanValue();
99             if (expandsAll) {
100                 table.expandAll();
101             }
102         }
103     };
104
105     public static final AttributeApplier expandedIconApplier = new AttributeApplier() {
106         public void apply(Realizable target, String JavaDoc namespaceURI,
107                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
108             URL JavaDoc url = target.getResolvedURL(attributeValue);
109             if (url != null) {
110                 JNTreeTable table = (JNTreeTable) target.getObject();
111                 table.setExpandedIcon(new ImageIcon JavaDoc(url));
112             }
113             else {
114                 System.out.println("Couldn't resolve URL: " + attributeValue);
115             }
116         }
117     };
118
119     public static final AttributeApplier leafIconApplier = new AttributeApplier() {
120         public void apply(Realizable target, String JavaDoc namespaceURI,
121                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
122             URL JavaDoc url = target.getResolvedURL(attributeValue);
123             if (url != null) {
124                 JNTreeTable table = (JNTreeTable) target.getObject();
125                 table.setLeafIcon(new ImageIcon JavaDoc(url));
126             }
127             else {
128                 System.out.println("Couldn't resolve URL: " + attributeValue);
129             }
130         }
131     };
132 }
133
Popular Tags