1 package org
.argeo
.slc
.client
.ui
.dist
.providers
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Arrays
;
8 import javax
.jcr
.NodeIterator
;
9 import javax
.jcr
.RepositoryException
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.eclipse
.ui
.jcr
.utils
.JcrItemsComparator
;
13 import org
.argeo
.slc
.jcr
.SlcTypes
;
14 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
15 import org
.eclipse
.jface
.viewers
.Viewer
;
17 public class ArtifactsTreeContentProvider
implements ITreeContentProvider
,
21 private boolean sortChildren
= true;
22 private JcrItemsComparator itemComparator
= new JcrItemsComparator();
24 public Object
[] getElements(Object parent
) {
25 return getChildren(parent
);
28 public Object
getParent(Object child
) {
32 public Object
[] getChildren(Object parent
) {
33 Object
[] elements
= null;
35 if (parent
instanceof Node
) {
36 Node node
= (Node
) parent
;
37 NodeIterator ni
= node
.getNodes();
38 List
<Node
> nodesList
= new ArrayList
<Node
>();
39 while (ni
.hasNext()) {
40 nodesList
.add(ni
.nextNode());
43 Node
[] arr
= (Node
[]) nodesList
.toArray(new Node
[nodesList
45 Arrays
.sort(arr
, itemComparator
);
48 return nodesList
.toArray();
51 } catch (RepositoryException e
) {
52 throw new ArgeoException(
53 "Unexpected exception while listing node properties", e
);
58 public boolean hasChildren(Object parent
) {
60 if (parent
instanceof Node
) {
61 Node curNode
= (Node
) parent
;
62 // We manually stop digging at this level
63 if (curNode
.isNodeType(SLC_ARTIFACT_VERSION_BASE
))
65 else if (curNode
.hasNodes())
68 } catch (RepositoryException e
) {
69 throw new ArgeoException(
70 "Unexpected exception while checking if property is multiple",
76 public void setSortChildren(boolean sortChildren
) {
77 this.sortChildren
= sortChildren
;
80 public boolean getSortChildren() {
84 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
87 public void dispose() {