1 package org
.argeo
.eclipse
.ui
.jcr
;
3 import java
.util
.ArrayList
;
7 import javax
.jcr
.NodeIterator
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.jcr
.Session
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.eclipse
.ui
.AbstractTreeContentProvider
;
14 /** Canonic implementation of tree content provider manipulating JCR nodes. */
15 public abstract class AbstractNodeContentProvider
extends
16 AbstractTreeContentProvider
{
17 private Session session
;
19 public AbstractNodeContentProvider(Session session
) {
20 this.session
= session
;
24 * Whether this path is a base path (and thus has no parent). By default it
25 * returns true if path is '/' (root node)
27 protected Boolean
isBasePath(String path
) {
29 return path
.equals("/");
33 public Object
[] getChildren(Object element
) {
34 if (element
instanceof Node
) {
36 List
<Node
> nodes
= new ArrayList
<Node
>();
37 for (NodeIterator nit
= ((Node
) element
).getNodes(); nit
39 nodes
.add(nit
.nextNode());
40 return nodes
.toArray();
41 } catch (RepositoryException e
) {
42 throw new ArgeoException("Cannot get children of " + element
, e
);
45 return super.getChildren(element
);
50 public Object
getParent(Object element
) {
51 if (element
instanceof Node
) {
52 Node node
= (Node
) element
;
54 String path
= node
.getPath();
58 return node
.getParent();
59 } catch (RepositoryException e
) {
60 throw new ArgeoException("Cannot get parent of " + element
, e
);
63 return super.getParent(element
);
67 public boolean hasChildren(Object element
) {
68 if (element
instanceof Node
) {
69 Node node
= (Node
) element
;
71 return node
.hasNodes();
72 } catch (RepositoryException e
) {
73 throw new ArgeoException("Cannot check whether " + element
74 + " has children", e
);
77 return super.hasChildren(element
);
80 public Session
getSession() {