Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java @ 9520:b188255f08b3
Allow to filter datacage entries by module-roles of current user.
Hide Sinfo, Uinfo and Minfo branches if user does not have those modules.
author | gernotbelger |
---|---|
date | Mon, 01 Oct 2018 16:21:20 +0200 |
parents | 4b29bb2c785f |
children |
comparison
equal
deleted
inserted
replaced
9519:ec2ebbc49fbc | 9520:b188255f08b3 |
---|---|
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; | |
13 | 12 |
14 public class DataCageTree implements Serializable | 13 public class DataCageTree implements Serializable { |
15 { | 14 |
15 private static final long serialVersionUID = 1L; | |
16 | 16 |
17 public interface Visitor { | 17 public interface Visitor { |
18 boolean accept(DataCageNode node); | 18 boolean accept(DataCageNode node); |
19 } // interface | 19 } |
20 | 20 |
21 protected DataCageNode root; | 21 private DataCageNode root; |
22 | 22 |
23 public DataCageTree() { | 23 public DataCageTree() { |
24 } | 24 } |
25 | 25 |
26 public DataCageTree(DataCageNode root) { | 26 public DataCageTree(final DataCageNode root) { |
27 this.root = root; | 27 this.root = root; |
28 } | 28 } |
29 | 29 |
30 public void setRoot(DataCageNode root) { | 30 public void setRoot(final DataCageNode root) { |
31 this.root = root; | 31 this.root = root; |
32 } | 32 } |
33 | 33 |
34 public DataCageNode getRoot() { | 34 public DataCageNode getRoot() { |
35 return root; | 35 return this.root; |
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 } | 36 } |
60 } | 37 } |
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |