Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java @ 7465:4b29bb2c785f
Datacage: Remove tree branches vom datacage tree on client side which do not contain loadable data.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 30 Oct 2013 11:58:57 +0100 |
parents | ea9eef426962 |
children | b188255f08b3 |
comparison
equal
deleted
inserted
replaced
7464:f16dce7a2407 | 7465:4b29bb2c785f |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.shared.model; | 9 package org.dive4elements.river.client.shared.model; |
10 | 10 |
11 import java.io.Serializable; | 11 import java.io.Serializable; |
12 import java.util.List; | |
12 | 13 |
13 public class DataCageTree implements Serializable | 14 public class DataCageTree implements Serializable |
14 { | 15 { |
16 | |
17 public interface Visitor { | |
18 boolean accept(DataCageNode node); | |
19 } // interface | |
20 | |
15 protected DataCageNode root; | 21 protected DataCageNode root; |
16 | 22 |
17 public DataCageTree() { | 23 public DataCageTree() { |
18 } | 24 } |
19 | 25 |
26 } | 32 } |
27 | 33 |
28 public DataCageNode getRoot() { | 34 public DataCageNode getRoot() { |
29 return root; | 35 return root; |
30 } | 36 } |
37 | |
38 | |
39 protected boolean recursivePrune(DataCageNode node, Visitor visitor) { | |
40 if (!node.hasChildren()) { | |
41 return visitor.accept(node); | |
42 } | |
43 | |
44 List<DataCageNode> children = node.getChildren(); | |
45 | |
46 for (int i = children.size()-1; i >= 0; --i) { | |
47 if (!recursivePrune(children.get(i), visitor)) { | |
48 children.remove(i); | |
49 } | |
50 } | |
51 | |
52 return !children.isEmpty(); | |
53 } | |
54 | |
55 public boolean prune(Visitor visitor) { | |
56 return root == null || !root.hasChildren() | |
57 ? true | |
58 : recursivePrune(root, visitor); | |
59 } | |
31 } | 60 } |
32 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |