KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TreeTableColumnAttributes.java,v 1.2 2005/01/27 13:32:01 kleopatra 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 org.w3c.dom.Element JavaDoc;
11 import org.w3c.dom.Node JavaDoc;
12 import org.jdesktop.swing.data.DefaultTableModelExt;
13 import org.jdesktop.swing.table.TabularDataMetaData;
14 import org.jdesktop.swing.table.TableColumnExt;
15 import org.jdesktop.jdnc.JNTreeTable;
16 import net.openmarkup.ApplierException;
17 import net.openmarkup.AttributeApplier;
18 import net.openmarkup.Realizable;
19 import org.jdesktop.jdnc.markup.ElementTypes;
20 import org.jdesktop.jdnc.markup.elem.ElementProxy;
21 import org.jdesktop.swing.data.DOMAdapter;
22 import org.jdesktop.swing.treetable.TreeTableModel;
23 /**
24  * @author Ramesh Gupta
25  */

26 public class TreeTableColumnAttributes {
27     public static final AttributeApplier bindingApplier = new AttributeApplier() {
28         public void apply(Realizable target, String JavaDoc namespaceURI,
29                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
30             JNTreeTable table = getTreeTable(target);
31             if (table != null) {
32                 DOMAdapter data = (DOMAdapter) table.getTreeTableModel();
33                 if (data != null) {
34                     int count = data.getColumnCount();
35                     for (int i = 0; i < count; i++) {
36                         if (data.getColumnName(i).equals(attributeValue)) {
37                             TableColumnExt column = (TableColumnExt) target.getObject();
38                             column.setModelIndex(i);
39                             break;
40                         }
41                     }
42                 }
43             }
44         }
45
46         /** @todo Refactor the following and TableColumnAttributes.getTable() */
47         private JNTreeTable getTreeTable(Realizable target) {
48             Node JavaDoc root = target.getOwnerDocument().getDocumentElement();
49             Node JavaDoc parent = target.getParentNode();
50             String JavaDoc nsURI = ElementTypes.TABLE.getNamespaceURI();
51             String JavaDoc treeTableName = ElementTypes.TREE_TABLE.getLocalName();
52             while (parent != root) {
53                 String JavaDoc parentName = parent.getLocalName();
54                 if (parentName.equals(treeTableName) &&
55                     parent.getNamespaceURI().equals(nsURI)) {
56                     Realizable tableElement = ElementProxy.getRealizable((Element JavaDoc) parent);
57                     if (tableElement != null) {
58                         return (JNTreeTable) tableElement.getObject();
59                     }
60                     return null;
61                 }
62                 parent = parent.getParentNode();
63             }
64             return null;
65         }
66     };
67 }
68
Popular Tags