View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/ConceptsTreeModel.java,v 1.13 2003/08/27 03:13:30 farrukh_najmi Exp $ 9 * 10 * ==================================================================== 11 */ 12 package com.sun.xml.registry.client.browser; 13 14 import javax.xml.registry.infomodel.ClassificationScheme; 15 import javax.xml.registry.infomodel.Concept; 16 import javax.xml.registry.infomodel.RegistryObject; 17 18 /*** 19 * A JTable that lists 20 * 21 * @author Jim Glennon 22 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 23 */ 24 public class ConceptsTreeModel extends javax.swing.tree.DefaultTreeModel { 25 RegistryBrowser registryBrowser; 26 ConceptsTreeNode rootNode; 27 RegistryObject rootTaxonomyElem = null; 28 java.util.HashSet hiddenSchemes = null; 29 30 private org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(this.getClass()); 31 32 public ConceptsTreeModel(boolean updateOnCreate) { 33 this(updateOnCreate, null); 34 } 35 36 public ConceptsTreeModel(boolean updateOnCreate, RegistryObject rootTaxonomyElem) { 37 super(new javax.swing.tree.DefaultMutableTreeNode()); 38 registryBrowser = RegistryBrowser.getInstance(); 39 40 if (!((rootTaxonomyElem == null) || (rootTaxonomyElem instanceof ClassificationScheme) || 41 (rootTaxonomyElem instanceof Concept))) { 42 log.error("Only ClassificationScheme, Concept or null expected, got a " + rootTaxonomyElem); 43 } 44 this.rootTaxonomyElem = rootTaxonomyElem; 45 46 // only update if parent component needs to 47 if (updateOnCreate == true) { 48 update(); 49 } 50 } 51 52 public void insertClassificationScheme(ClassificationScheme scheme) { 53 NodeInfo nodeInfo = new NodeInfo(); 54 nodeInfo.obj = scheme; 55 nodeInfo.loaded = true; 56 ConceptsTreeNode newNode = new ConceptsTreeNode(nodeInfo); 57 58 // insertNodeInto(newNode, rootNode, rootNode.getChildCount()); 59 rootNode.add(new ConceptsTreeNode(nodeInfo)); 60 reload(rootNode); 61 } 62 63 public void insertConcept(Concept concept, javax.swing.tree.DefaultMutableTreeNode parentNode) { 64 NodeInfo nodeInfo = new NodeInfo(); 65 nodeInfo.obj = concept; 66 nodeInfo.loaded = false; 67 ConceptsTreeNode newNode = new ConceptsTreeNode(nodeInfo); 68 69 // insertNodeInto(newNode, rootNode, rootNode.getChildCount()); 70 parentNode.add(new ConceptsTreeNode(nodeInfo)); 71 reload(parentNode); 72 } 73 74 /*** 75 * If no root node specified then load all ClassificationSchemes under a 76 * dummy root node. If a root node is specified then load it as teh root 77 * node. If the children of a node have been loaded then call exapnd on it. 78 */ 79 public void update() { 80 JAXRClient client = registryBrowser.client; 81 if (rootTaxonomyElem != null) { 82 //Root scheme specified just load it as root node 83 NodeInfo nodeInfo = new NodeInfo(); 84 nodeInfo.obj = rootTaxonomyElem; 85 nodeInfo.loaded = false; 86 rootNode = new ConceptsTreeNode(nodeInfo); 87 setRoot(rootNode); 88 89 String depthStr = com.sun.xml.registry.ebxml.util.ProviderProperties.getInstance(). 90 getProperty("jaxr-ebxml.registryBrowser.objectTypeCombo.initialFetchDepth", "4"); 91 int depth = Integer.parseInt(depthStr); 92 expandTree(rootNode, depth); 93 } 94 else { 95 //NO single root scheme specified so load all schemes 96 //under a dummy root node named Concepts 97 rootNode = new ConceptsTreeNode("Concepts"); 98 setRoot(rootNode); 99 100 java.util.Collection schemes = client.getClassificationSchemes(); 101 // add classification nodes to the tree 102 java.util.Iterator iter = schemes.iterator(); 103 while (iter.hasNext()) { // update 104 ClassificationScheme scheme = (ClassificationScheme) iter.next(); 105 106 if (!hideScheme(scheme)) { 107 NodeInfo nodeInfo = new NodeInfo(); 108 nodeInfo.obj = scheme; 109 nodeInfo.loaded = false; 110 ConceptsTreeNode newNode = new ConceptsTreeNode(nodeInfo); 111 112 // insertNodeInto(newNode, rootNode, rootNode.getChildCount()); 113 rootNode.add(new ConceptsTreeNode(nodeInfo)); 114 } 115 } 116 } 117 118 reload(rootNode); 119 } 120 121 /*** 122 * Determines whether to hide this scheme based upon user configuration. 123 */ 124 private boolean hideScheme(ClassificationScheme scheme) { 125 boolean hide=false; 126 127 try { 128 String id = scheme.getKey().getId(); 129 if (getHiddenSchemes().contains(id)) { 130 hide = true; 131 } 132 } 133 catch (javax.xml.registry.JAXRException e) { 134 RegistryBrowser.displayError(e); 135 } 136 return hide; 137 } 138 139 /* 140 * Loads the list of schemes to hide from the property file. 141 */ 142 private java.util.HashSet getHiddenSchemes() { 143 144 if (hiddenSchemes == null) { 145 hiddenSchemes = new java.util.HashSet(); 146 String hiddenSchemesStr = com.sun.xml.registry.ebxml.util.ProviderProperties.getInstance().getProperty("jaxr-ebxml.registryBrowser.ConceptsTreeModel.hiddenSchemesList"); 147 148 if (hiddenSchemesStr != null) { 149 java.util.StringTokenizer tokenizer = 150 new java.util.StringTokenizer(hiddenSchemesStr, "|" ); 151 152 while ( tokenizer.hasMoreTokens() ) { 153 try { 154 String schemeId = tokenizer.nextToken(); 155 hiddenSchemes.add(schemeId); 156 } catch ( Exception e ) { 157 e.printStackTrace(); 158 } 159 } 160 } 161 } 162 163 return hiddenSchemes; 164 } 165 166 167 /*** 168 * Fetches children of specified node upto specified depth. 169 * @param depth a value of 1 means fetch immediate children. 170 * A value of N means fetch N levels deep. 171 * A value of 0 means do nothing. 172 * A value of less than 0 means fetch entire tree. 173 */ 174 public void expandTree(javax.swing.tree.DefaultMutableTreeNode node, int depth) { 175 176 Object userObj = node.getUserObject(); 177 if (!(userObj instanceof NodeInfo)) { 178 return; 179 } 180 181 NodeInfo nodeInfo = (NodeInfo) userObj; 182 183 if (nodeInfo.loaded) { 184 return; 185 } 186 nodeInfo.loaded = true; 187 188 java.util.Collection childConcepts = null; 189 try { 190 childConcepts = getChildConcepts( nodeInfo.obj); 191 } 192 catch (javax.xml.registry.JAXRException e) { 193 log.error(e); 194 } 195 196 --depth; 197 if (childConcepts != null) { 198 java.util.Iterator iter = childConcepts.iterator(); 199 200 while (iter.hasNext()) { // expandTree() 201 nodeInfo = new NodeInfo(); 202 Concept childConcept = (Concept) iter.next(); 203 nodeInfo.obj = childConcept; 204 nodeInfo.loaded = false; 205 ConceptsTreeNode newNode = new ConceptsTreeNode(nodeInfo); 206 207 // insertNodeInto(newNode, node, node.getChildCount()); 208 node.add(newNode); 209 210 if (depth != 0) { 211 expandTree(newNode, depth); 212 } 213 } 214 nodeStructureChanged(node); 215 } 216 } 217 218 private class ConceptsTreeNode extends javax.swing.tree.DefaultMutableTreeNode { 219 220 ConceptsTreeNode(Object userObject) { 221 super(userObject); 222 } 223 224 public String toString() { 225 String str = super.toString(); 226 227 Object userObj = getUserObject(); 228 if (userObj instanceof NodeInfo) { 229 NodeInfo nodeInfo = (NodeInfo) userObj; 230 231 if (nodeInfo.obj instanceof RegistryObject) { 232 str = getName(nodeInfo.obj); 233 } 234 } 235 236 237 if (str == null) { 238 str = "[no name info given]"; 239 } 240 return str; 241 } 242 243 } 244 245 private String getName(RegistryObject ro) { 246 String name = null; 247 248 try { 249 name = RegistryBrowser.getName(ro); 250 251 if ((name == null) || (name.length() == 0)) { 252 if (ro instanceof Concept) { 253 name = ((Concept)ro).getValue(); 254 } 255 } 256 } 257 catch (javax.xml.registry.JAXRException e) { 258 RegistryBrowser.displayError(e); 259 } 260 if (name == null) { 261 name = ""; 262 } 263 return name; 264 } 265 266 private java.util.Collection getChildConcepts(RegistryObject ro) throws javax.xml.registry.JAXRException { 267 java.util.Collection childConcepts = null; 268 if (ro instanceof ClassificationScheme) { 269 ClassificationScheme scheme = (ClassificationScheme)ro; 270 childConcepts = scheme.getChildrenConcepts(); 271 } 272 else if (ro instanceof Concept) { 273 Concept concept = (Concept)ro; 274 childConcepts = concept.getChildrenConcepts(); 275 } 276 return childConcepts; 277 } 278 279 }

This page was automatically generated by Maven