2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.dist
.controllers
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.List
;
22 import javax
.jcr
.Node
;
23 import javax
.jcr
.NodeIterator
;
24 import javax
.jcr
.RepositoryException
;
26 import org
.argeo
.ArgeoException
;
27 import org
.argeo
.eclipse
.ui
.jcr
.utils
.JcrItemsComparator
;
28 import org
.argeo
.slc
.jcr
.SlcTypes
;
29 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
30 import org
.eclipse
.jface
.viewers
.Viewer
;
32 public class ArtifactsTreeContentProvider
implements ITreeContentProvider
,
36 private boolean sortChildren
= true;
37 private JcrItemsComparator itemComparator
= new JcrItemsComparator();
39 public Object
[] getElements(Object parent
) {
40 return getChildren(parent
);
43 public Object
getParent(Object child
) {
47 public Object
[] getChildren(Object parent
) {
48 Object
[] elements
= null;
50 if (parent
instanceof Node
) {
51 Node node
= (Node
) parent
;
52 NodeIterator ni
= node
.getNodes();
53 List
<Node
> nodesList
= new ArrayList
<Node
>();
54 while (ni
.hasNext()) {
55 nodesList
.add(ni
.nextNode());
58 Node
[] arr
= (Node
[]) nodesList
.toArray(new Node
[nodesList
60 Arrays
.sort(arr
, itemComparator
);
63 return nodesList
.toArray();
66 } catch (RepositoryException e
) {
67 throw new ArgeoException(
68 "Unexpected exception while listing node properties", e
);
73 public boolean hasChildren(Object parent
) {
75 if (parent
instanceof Node
) {
76 Node curNode
= (Node
) parent
;
77 // We manually stop digging at this level
78 if (curNode
.isNodeType(SLC_ARTIFACT_VERSION_BASE
))
80 else if (curNode
.hasNodes())
83 } catch (RepositoryException e
) {
84 throw new ArgeoException(
85 "Unexpected exception while checking if property is multiple",
91 public void setSortChildren(boolean sortChildren
) {
92 this.sortChildren
= sortChildren
;
95 public boolean getSortChildren() {
99 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
102 public void dispose() {