1 7 8 package org.jdesktop.jdnc.markup.attr; 9 10 import java.net.URL ; 11 import javax.xml.parsers.DocumentBuilderFactory ; 12 13 import javax.swing.ImageIcon ; 14 15 import org.w3c.dom.Document ; 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 26 public class TreeTableAttributes { 27 public static final AttributeApplier dataSourceApplier = new AttributeApplier() { 28 public void apply(Realizable target, String namespaceURI, 29 String attributeName, String attributeValue) throws ApplierException { 30 31 URL url = target.getResolvedURL(attributeValue); 33 RealizationUtils.validateURL(url); 34 35 try { 36 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 37 dbf.setNamespaceAware(true); 38 dbf.setIgnoringComments(true); 39 Document 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 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 namespaceURI, 54 String attributeName, String attributeValue) throws ApplierException { 55 URL url = target.getResolvedURL(attributeValue); 56 if (url != null) { 57 JNTreeTable table = (JNTreeTable) target.getObject(); 58 table.setCollapsedIcon(new ImageIcon (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 namespaceURI, 68 String attributeName, String attributeValue) throws ApplierException { 69 URL url = target.getResolvedURL(attributeValue); 70 if (url != null) { 71 JNTreeTable table = (JNTreeTable) target.getObject(); 72 table.setClosedIcon(new ImageIcon (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 namespaceURI, 82 String attributeName, String attributeValue) throws ApplierException { 83 URL url = target.getResolvedURL(attributeValue); 84 if (url != null) { 85 JNTreeTable table = (JNTreeTable) target.getObject(); 86 table.setOpenIcon(new ImageIcon (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 namespaceURI, 96 String attributeName, String 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 namespaceURI, 107 String attributeName, String attributeValue) throws ApplierException { 108 URL url = target.getResolvedURL(attributeValue); 109 if (url != null) { 110 JNTreeTable table = (JNTreeTable) target.getObject(); 111 table.setExpandedIcon(new ImageIcon (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 namespaceURI, 121 String attributeName, String attributeValue) throws ApplierException { 122 URL url = target.getResolvedURL(attributeValue); 123 if (url != null) { 124 JNTreeTable table = (JNTreeTable) target.getObject(); 125 table.setLeafIcon(new ImageIcon (url)); 126 } 127 else { 128 System.out.println("Couldn't resolve URL: " + attributeValue); 129 } 130 } 131 }; 132 } 133 | Popular Tags |