]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/model/SingleJcrNodeElem.java
Make login shell styling more robust.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / jcr / model / SingleJcrNodeElem.java
1 package org.argeo.cms.ui.jcr.model;
2
3 import javax.jcr.Node;
4 import javax.jcr.NodeIterator;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.Workspace;
7
8 import org.argeo.eclipse.ui.EclipseUiException;
9 import org.argeo.eclipse.ui.TreeParent;
10
11 /**
12 * UI Tree component. Wraps a node of a JCR {@link Workspace}. It also keeps a
13 * reference to its parent node that can either be a {@link WorkspaceElem}, a
14 * {@link SingleJcrNodeElem} or null if the node is "mounted" as the root of the
15 * UI tree.
16 */
17 public class SingleJcrNodeElem extends TreeParent {
18
19 private final Node node;
20 private String alias = null;
21
22 /** Creates a new UiNode in the UI Tree */
23 public SingleJcrNodeElem(TreeParent parent, Node node, String name) {
24 super(name);
25 setParent(parent);
26 this.node = node;
27 }
28
29 /**
30 * Creates a new UiNode in the UI Tree, keeping a reference to the alias of
31 * the corresponding repository in the current UI environment. It is useful
32 * to be able to mount nodes as roots of the UI tree.
33 */
34 public SingleJcrNodeElem(TreeParent parent, Node node, String name, String alias) {
35 super(name);
36 setParent(parent);
37 this.node = node;
38 this.alias = alias;
39 }
40
41 /** Returns the node wrapped by the current UI object */
42 public Node getNode() {
43 return node;
44 }
45
46 protected String getRepositoryAlias() {
47 return alias;
48 }
49
50 /**
51 * Overrides normal behaviour to initialise children only when first
52 * requested
53 */
54 @Override
55 public synchronized Object[] getChildren() {
56 if (isLoaded()) {
57 return super.getChildren();
58 } else {
59 // initialize current object
60 try {
61 NodeIterator ni = node.getNodes();
62 while (ni.hasNext()) {
63 Node curNode = ni.nextNode();
64 addChild(new SingleJcrNodeElem(this, curNode, curNode.getName()));
65 }
66 return super.getChildren();
67 } catch (RepositoryException re) {
68 throw new EclipseUiException("Cannot initialize SingleJcrNode children", re);
69 }
70 }
71 }
72
73 @Override
74 public boolean hasChildren() {
75 try {
76 if (node.getSession().isLive())
77 return node.hasNodes();
78 else
79 return false;
80 } catch (RepositoryException re) {
81 throw new EclipseUiException("Cannot check children node existence", re);
82 }
83 }
84 }