1 /* 2 * Copyright (C) 2007-2012 Argeo GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.argeo.slc.client.ui.model; 17 18 import javax.jcr.Node; 19 import javax.jcr.NodeIterator; 20 import javax.jcr.RepositoryException; 21 import javax.jcr.nodetype.NodeType; 22 23 import org.argeo.slc.SlcException; 24 import org.argeo.slc.SlcNames; 25 import org.argeo.slc.SlcTypes; 26 27 /** 28 * UI Tree component that wrap a node of type NT_UNSTRUCTURED or base node for 29 * UI specific, user defined tree structure of type SLC_MY_RESULTS_ROOT_FOLDER. 30 * 31 * It is used for 32 * <ul> 33 * <li>automatically generated tree structure to store results (typically 34 * Year/Month/Day...)</li> 35 * <li>parent node for user defined tree structure (typically My Results node)</li> 36 * </ul> 37 * It thus lists either result folders, other folders and/or a list of results 38 * and keeps a reference to its parent. 39 */ 40 public class ParentNodeFolder extends ResultParent { 41 // private final static Log log = LogFactory.getLog(ParentNodeFolder.class); 42 43 private Node node = null; 44 45 /** 46 * 47 * @param parent 48 * @param node 49 * throws an exception if null 50 * @param name 51 */ 52 public ParentNodeFolder(ParentNodeFolder parent, Node node, String name) { 53 super(name); 54 if (node == null) 55 throw new SlcException("Node Object cannot be null"); 56 setParent(parent); 57 this.node = node; 58 } 59 60 @Override 61 protected void initialize() { 62 try { 63 NodeIterator ni = node.getNodes(); 64 while (ni.hasNext()) { 65 Node currNode = ni.nextNode(); 66 if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) { 67 SingleResultNode srn = new SingleResultNode(this, currNode, 68 currNode.getProperty(SlcNames.SLC_TEST_CASE) 69 .getString()); 70 addChild(srn); 71 } else if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) { 72 // FIXME change label 73 ResultFolder rf = new ResultFolder(this, currNode, 74 currNode.getName()); 75 addChild(rf); 76 } else if (currNode.isNodeType(SlcTypes.SLC_CHECK)) { 77 // FIXME : manually skip node types that are not to be 78 // displayed 79 // Do nothing 80 } else if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED)) 81 addChild(new ParentNodeFolder(this, currNode, 82 currNode.getName())); 83 } 84 } catch (RepositoryException re) { 85 throw new SlcException( 86 "Unexpected error while initializing ParentNodeFolder : " 87 + getName(), re); 88 } 89 } 90 91 public Node getNode() { 92 return node; 93 } 94 95 // /** 96 // * Overriden in the specific case of "My result" root object to return an 97 // * ordered list of children 98 // */ 99 // public synchronized Object[] getChildren() { 100 // Object[] children = super.getChildren(); 101 // try { 102 // if (node.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER)) 103 // return ResultParentUtils.orderChildren(children); 104 // else 105 // return children; 106 // } catch (RepositoryException re) { 107 // throw new SlcException( 108 // "Unexpected error while initializing simple node folder : " 109 // + getName(), re); 110 // } 111 // } 112 }