Project

General

Profile

« Previous | Next » 

Revision f6a8dc56

Added by Patrick Plitzner over 10 years ago

merged model adaptions to cdmlib 3.2.4 from campanula branch

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainer.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
35 35
 * @version 1.0
36 36
 */
37 37
public class FeatureNodeContainer{
38
	
39
	
40
	
38

  
39

  
40

  
41 41
	private FeatureNodeContainer parent;
42
	
42

  
43 43

  
44 44

  
45 45
	private FeatureNode featureNode;
......
48 48

  
49 49
	private FeatureNodeContainerTree containerTree;
50 50

  
51
	
51

  
52 52
	/**
53 53
	 * @param description
54 54
	 */
55 55
	protected FeatureNodeContainer(FeatureNodeContainerTree containerTree) {
56
		this.containerTree = containerTree; 
56
		this.containerTree = containerTree;
57 57
		this.containerTree.addContainer(this);
58 58
	}
59
	
60
	
59

  
60

  
61 61
	/**
62
	 * Recursively traverse a branch of a feature tree and check if there are 
63
	 * 
62
	 * Recursively traverse a branch of a feature tree and check if there are
63
	 *
64 64
	 * @param featureNode
65
	 * @param description 
65
	 * @param description
66 66
	 * @return
67 67
	 */
68 68
	protected void findLeaves(FeatureNode featureNode) {
69 69
		if(featureNode.isLeaf()){
70 70
			buildLeaf(featureNode);
71 71
		}else{
72
			for(FeatureNode childNode : featureNode.getChildren()){
72
			for(FeatureNode childNode : featureNode.getChildNodes()){
73 73
				findLeaves(childNode);
74 74
			}
75 75
		}
76 76
	}
77
	
77

  
78 78
	/**
79
	 * 
79
	 *
80 80
	 * @param featureNode
81 81
	 * @param description
82 82
	 * @return
......
85 85
		if(featureNode.getFeature() == null){
86 86
			throw new IllegalArgumentException("The given feature node does not have a feature.");
87 87
		}
88
		
88

  
89 89
		Feature feature = (Feature) HibernateProxyHelper.deproxy(featureNode.getFeature());
90
		
90

  
91 91
		// get feature node container for the given feature
92 92
		FeatureNodeContainer container = containerTree.getFeatureNodeContainer(feature);
93
		
93

  
94 94
		// get description elements for the given feature
95 95
		List<DescriptionElementBase> elements = containerTree.getDescriptionsElementsForFeature(feature);
96 96
		// no description elements, so we should also remove the feature node container
......
108 108
				container.buildBranch();
109 109
			}
110 110
			// add description elements to the feature node container
111
			container.setDescriptionElements(elements);		
111
			container.setDescriptionElements(elements);
112 112
		}
113 113
	}
114
	
114

  
115 115
	/**
116
	 * 
116
	 *
117 117
	 */
118 118
	private void remove() {
119 119
		if(getParent() != null){
......
134 134

  
135 135

  
136 136
	/**
137
	 * Recursively 
138
	 * 
137
	 * Recursively
138
	 *
139 139
	 * @param featureNodeMap
140 140
	 * @return
141 141
	 */
142
	private void buildBranch(){	
142
	private void buildBranch(){
143 143
		if(getParent() == null){
144 144
			FeatureNode parentFeatureNode = getFeatureNode().getParent();
145
			
145

  
146 146
			if(parentFeatureNode.isRoot()){
147 147
				containerTree.getRoot().addChild(this);
148 148
			}else{
......
151 151
					parentContainer = new FeatureNodeContainer(containerTree);
152 152
					parentContainer.setFeatureNode(parentFeatureNode);
153 153
				}
154
				
154

  
155 155
				parentContainer.addChild(this);
156
				
156

  
157 157
				parentContainer.buildBranch();
158
				
158

  
159 159
			}
160 160
		}
161 161
	}
162
	
162

  
163 163
	/**
164 164
	 * <p>Getter for the field <code>children</code>.</p>
165 165
	 *
......
182 182
			throw new IllegalStateException("Container may not have a description element set when setting children.");
183 183
		}
184 184
	}
185
	
185

  
186 186
	/**
187 187
	 * Adds a child container to the list of this containers children
188 188
	 *
......
201 201
	public void addDescriptionElement(DescriptionElementBase descriptionElement){
202 202
		descriptionElements.add(descriptionElement);
203 203
	}
204
	
204

  
205 205
	public void removeDescriptionElement(DescriptionElementBase descriptionElement){
206 206
		descriptionElements.remove(descriptionElement);
207 207
	}
208
	
208

  
209 209
	/**
210 210
	 * If {@link #isLeaf()} is true, i.e. this container should have elements, returns the list of description elements.
211 211
	 *
......
225 225
	public List<DescriptionElementBase> getDescriptionElementsForEntireBranch(){
226 226
		return getDescriptionElementsRecursively(new ArrayList<DescriptionElementBase>());
227 227
	}
228
	
228

  
229 229
	private List<DescriptionElementBase> getDescriptionElementsRecursively(List<DescriptionElementBase> descriptionElements){
230 230
		if(isLeaf()){
231 231
			descriptionElements.addAll(getDescriptionElements());
......
236 236
		}
237 237
		return descriptionElements;
238 238
	}
239
	
239

  
240 240
	protected List<FeatureNodeContainer> getLeafs(){
241 241
		List<FeatureNodeContainer> leafs = new ArrayList<FeatureNodeContainer>();
242
		
242

  
243 243
		if(isLeaf()){
244 244
			leafs.add(this);
245 245
		}else{
246 246
			for(FeatureNodeContainer container : getChildren()){
247 247
				leafs.addAll(container.getLeafs());
248
			}			
248
			}
249 249
		}
250 250
		return leafs;
251 251
	}
252
	
252

  
253 253
	/**
254 254
	 * Set the description element
255 255
	 *
......
263 263
			throw new IllegalStateException("Container may not contain child container when adding description elements.");
264 264
		}
265 265
	}
266
	
266

  
267 267
	/**
268 268
	 * If the container is a leaf, it will hold a description element and no child containers
269 269
	 *
......
272 272
	public boolean isLeaf(){
273 273
		return ! descriptionElements.isEmpty() && children.isEmpty();
274 274
	}
275
	
275

  
276 276
	/**
277 277
	 * <p>Setter for the field <code>featureNode</code>.</p>
278 278
	 *
......
290 290
	public FeatureNode getFeatureNode() {
291 291
		return featureNode;
292 292
	}
293
	
293

  
294 294
	/**
295 295
	 * <p>getFeature</p>
296 296
	 *
......
311 311
	public DescriptionBase getDescription(){
312 312
		return containerTree.getDescription();
313 313
	}
314
	
314

  
315 315
	public FeatureNodeContainerTree getContainerTree(){
316 316
		return containerTree;
317 317
	}
318 318

  
319 319

  
320 320
	/**
321
	 * 
321
	 *
322 322
	 */
323 323
	public void clear() {
324 324
		children.clear();

Also available in: Unified diff