// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
* @version 1.0
*/
public class FeatureNodeContainer{
-
-
-
+
+
+
private FeatureNodeContainer parent;
-
+
private FeatureNode featureNode;
private FeatureNodeContainerTree containerTree;
-
+
/**
* @param description
*/
protected FeatureNodeContainer(FeatureNodeContainerTree containerTree) {
- this.containerTree = containerTree;
+ this.containerTree = containerTree;
this.containerTree.addContainer(this);
}
-
-
+
+
/**
- * Recursively traverse a branch of a feature tree and check if there are
- *
+ * Recursively traverse a branch of a feature tree and check if there are
+ *
* @param featureNode
- * @param description
+ * @param description
* @return
*/
protected void findLeaves(FeatureNode featureNode) {
if(featureNode.isLeaf()){
buildLeaf(featureNode);
}else{
- for(FeatureNode childNode : featureNode.getChildren()){
+ for(FeatureNode childNode : featureNode.getChildNodes()){
findLeaves(childNode);
}
}
}
-
+
/**
- *
+ *
* @param featureNode
* @param description
* @return
if(featureNode.getFeature() == null){
throw new IllegalArgumentException("The given feature node does not have a feature.");
}
-
+
Feature feature = (Feature) HibernateProxyHelper.deproxy(featureNode.getFeature());
-
+
// get feature node container for the given feature
FeatureNodeContainer container = containerTree.getFeatureNodeContainer(feature);
-
+
// get description elements for the given feature
List<DescriptionElementBase> elements = containerTree.getDescriptionsElementsForFeature(feature);
// no description elements, so we should also remove the feature node container
container.buildBranch();
}
// add description elements to the feature node container
- container.setDescriptionElements(elements);
+ container.setDescriptionElements(elements);
}
}
-
+
/**
- *
+ *
*/
private void remove() {
if(getParent() != null){
/**
- * Recursively
- *
+ * Recursively
+ *
* @param featureNodeMap
* @return
*/
- private void buildBranch(){
+ private void buildBranch(){
if(getParent() == null){
FeatureNode parentFeatureNode = getFeatureNode().getParent();
-
+
if(parentFeatureNode.isRoot()){
containerTree.getRoot().addChild(this);
}else{
parentContainer = new FeatureNodeContainer(containerTree);
parentContainer.setFeatureNode(parentFeatureNode);
}
-
+
parentContainer.addChild(this);
-
+
parentContainer.buildBranch();
-
+
}
}
}
-
+
/**
* <p>Getter for the field <code>children</code>.</p>
*
throw new IllegalStateException("Container may not have a description element set when setting children.");
}
}
-
+
/**
* Adds a child container to the list of this containers children
*
public void addDescriptionElement(DescriptionElementBase descriptionElement){
descriptionElements.add(descriptionElement);
}
-
+
public void removeDescriptionElement(DescriptionElementBase descriptionElement){
descriptionElements.remove(descriptionElement);
}
-
+
/**
* If {@link #isLeaf()} is true, i.e. this container should have elements, returns the list of description elements.
*
public List<DescriptionElementBase> getDescriptionElementsForEntireBranch(){
return getDescriptionElementsRecursively(new ArrayList<DescriptionElementBase>());
}
-
+
private List<DescriptionElementBase> getDescriptionElementsRecursively(List<DescriptionElementBase> descriptionElements){
if(isLeaf()){
descriptionElements.addAll(getDescriptionElements());
}
return descriptionElements;
}
-
+
protected List<FeatureNodeContainer> getLeafs(){
List<FeatureNodeContainer> leafs = new ArrayList<FeatureNodeContainer>();
-
+
if(isLeaf()){
leafs.add(this);
}else{
for(FeatureNodeContainer container : getChildren()){
leafs.addAll(container.getLeafs());
- }
+ }
}
return leafs;
}
-
+
/**
* Set the description element
*
throw new IllegalStateException("Container may not contain child container when adding description elements.");
}
}
-
+
/**
* If the container is a leaf, it will hold a description element and no child containers
*
public boolean isLeaf(){
return ! descriptionElements.isEmpty() && children.isEmpty();
}
-
+
/**
* <p>Setter for the field <code>featureNode</code>.</p>
*
public FeatureNode getFeatureNode() {
return featureNode;
}
-
+
/**
* <p>getFeature</p>
*
public DescriptionBase getDescription(){
return containerTree.getDescription();
}
-
+
public FeatureNodeContainerTree getContainerTree(){
return containerTree;
}
/**
- *
+ *
*/
public void clear() {
children.clear();