1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.slc.client.ui.dist.controllers;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import javax.jcr.Node;
23 import javax.jcr.NodeIterator;
24 import javax.jcr.RepositoryException;
25
26 import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator;
27 import org.argeo.slc.SlcException;
28 import org.argeo.slc.SlcTypes;
29 import org.eclipse.jface.viewers.ITreeContentProvider;
30 import org.eclipse.jface.viewers.Viewer;
31
32
33 public class ArtifactsTreeContentProvider implements ITreeContentProvider,
34 SlcTypes {
35 private static final long serialVersionUID = -8097817288192073987L;
36
37
38 private boolean sortChildren = true;
39 private JcrItemsComparator itemComparator = new JcrItemsComparator();
40
41 public Object[] getElements(Object parent) {
42 return getChildren(parent);
43 }
44
45 public Object getParent(Object child) {
46 return null;
47 }
48
49 public Object[] getChildren(Object parent) {
50 Object[] elements = null;
51 try {
52 if (parent instanceof Node) {
53 Node node = (Node) parent;
54 NodeIterator ni = node.getNodes();
55 List<Node> nodesList = new ArrayList<Node>();
56 while (ni.hasNext()) {
57 nodesList.add(ni.nextNode());
58 }
59 if (sortChildren) {
60 Node[] arr = (Node[]) nodesList.toArray(new Node[nodesList
61 .size()]);
62 Arrays.sort(arr, itemComparator);
63 return arr;
64 } else
65 return nodesList.toArray();
66
67 }
68 } catch (RepositoryException e) {
69 throw new SlcException(
70 "Unexpected exception while listing node properties", e);
71 }
72 return elements;
73 }
74
75 public boolean hasChildren(Object parent) {
76 try {
77 if (parent instanceof Node) {
78 Node curNode = (Node) parent;
79
80 if (curNode.isNodeType(SLC_ARTIFACT_VERSION_BASE))
81 return false;
82 else if (curNode.hasNodes())
83 return true;
84 }
85 } catch (RepositoryException e) {
86 throw new SlcException(
87 "Unexpected exception while checking if property is multiple",
88 e);
89 }
90 return false;
91 }
92
93 public void setSortChildren(boolean sortChildren) {
94 this.sortChildren = sortChildren;
95 }
96
97 public boolean getSortChildren() {
98 return sortChildren;
99 }
100
101 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
102 }
103
104 public void dispose() {
105 }
106 }