]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/eclipse/ui/jcr/NodesWrapper.java
SDK system based on Makefiles
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / eclipse / ui / jcr / NodesWrapper.java
1 package org.argeo.eclipse.ui.jcr;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.jcr.Node;
7 import javax.jcr.NodeIterator;
8 import javax.jcr.RepositoryException;
9
10 import org.argeo.eclipse.ui.EclipseUiException;
11
12 /**
13 * Element of tree which is based on a node, but whose children are not
14 * necessarily this node children.
15 */
16 public class NodesWrapper {
17 private final Node node;
18
19 public NodesWrapper(Node node) {
20 super();
21 this.node = node;
22 }
23
24 protected NodeIterator getNodeIterator() throws RepositoryException {
25 return node.getNodes();
26 }
27
28 protected List<WrappedNode> getWrappedNodes() throws RepositoryException {
29 List<WrappedNode> nodes = new ArrayList<WrappedNode>();
30 for (NodeIterator nit = getNodeIterator(); nit.hasNext();)
31 nodes.add(new WrappedNode(this, nit.nextNode()));
32 return nodes;
33 }
34
35 public Object[] getChildren() {
36 try {
37 return getWrappedNodes().toArray();
38 } catch (RepositoryException e) {
39 throw new EclipseUiException("Cannot get wrapped children", e);
40 }
41 }
42
43 /**
44 * @return true by default because we don't want to compute the wrapped
45 * nodes twice
46 */
47 public Boolean hasChildren() {
48 return true;
49 }
50
51 public Node getNode() {
52 return node;
53 }
54
55 @Override
56 public int hashCode() {
57 return node.hashCode();
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (obj instanceof NodesWrapper)
63 return node.equals(((NodesWrapper) obj).getNode());
64 else
65 return false;
66 }
67
68 public String toString() {
69 return "nodes wrapper based on " + node;
70 }
71 }