1 package org
.argeo
.slc
.client
.ui
.dist
.controllers
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Arrays
;
8 import javax
.jcr
.NodeIterator
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.argeo
.eclipse
.ui
.jcr
.util
.JcrItemsComparator
;
12 import org
.argeo
.slc
.SlcException
;
13 import org
.argeo
.slc
.SlcTypes
;
14 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
15 import org
.eclipse
.jface
.viewers
.Viewer
;
17 /** Enable specific browsing of an artifact tree */
18 public class ArtifactsTreeContentProvider
implements ITreeContentProvider
,
20 private static final long serialVersionUID
= -8097817288192073987L;
23 private boolean sortChildren
= true;
24 private JcrItemsComparator itemComparator
= new JcrItemsComparator();
26 public Object
[] getElements(Object parent
) {
27 return getChildren(parent
);
30 public Object
getParent(Object child
) {
34 public Object
[] getChildren(Object parent
) {
35 Object
[] elements
= null;
37 if (parent
instanceof Node
) {
38 Node node
= (Node
) parent
;
39 NodeIterator ni
= node
.getNodes();
40 List
<Node
> nodesList
= new ArrayList
<Node
>();
41 while (ni
.hasNext()) {
42 nodesList
.add(ni
.nextNode());
45 Node
[] arr
= (Node
[]) nodesList
.toArray(new Node
[nodesList
47 Arrays
.sort(arr
, itemComparator
);
50 return nodesList
.toArray();
53 } catch (RepositoryException e
) {
54 throw new SlcException(
55 "Unexpected exception while listing node properties", e
);
60 public boolean hasChildren(Object parent
) {
62 if (parent
instanceof Node
) {
63 Node curNode
= (Node
) parent
;
64 // We manually stop digging at this level
65 if (curNode
.isNodeType(SLC_ARTIFACT_VERSION_BASE
))
67 else if (curNode
.hasNodes())
70 } catch (RepositoryException e
) {
71 throw new SlcException(
72 "Unexpected exception while checking if property is multiple",
78 public void setSortChildren(boolean sortChildren
) {
79 this.sortChildren
= sortChildren
;
82 public boolean getSortChildren() {
86 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
89 public void dispose() {