1 7 8 package org.jdesktop.jdnc.markup.attr; 9 10 import org.w3c.dom.Element ; 11 import org.w3c.dom.Node ; 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 26 public class TreeTableColumnAttributes { 27 public static final AttributeApplier bindingApplier = new AttributeApplier() { 28 public void apply(Realizable target, String namespaceURI, 29 String attributeName, String 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 47 private JNTreeTable getTreeTable(Realizable target) { 48 Node root = target.getOwnerDocument().getDocumentElement(); 49 Node parent = target.getParentNode(); 50 String nsURI = ElementTypes.TABLE.getNamespaceURI(); 51 String treeTableName = ElementTypes.TREE_TABLE.getLocalName(); 52 while (parent != root) { 53 String parentName = parent.getLocalName(); 54 if (parentName.equals(treeTableName) && 55 parent.getNamespaceURI().equals(nsURI)) { 56 Realizable tableElement = ElementProxy.getRealizable((Element ) 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 |