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 /** Enable specific browsing of an artifact tree */
33 public class ArtifactsTreeContentProvider
implements ITreeContentProvider
,
35 private static final long serialVersionUID
= -8097817288192073987L;
38 private boolean sortChildren
= true;
39 private JcrItemsComparator itemComparator
= new JcrItemsComparator();
41 public Object
[] getElements(Object parent
) {
42 return getChildren(parent
);
45 public Object
getParent(Object child
) {
49 public Object
[] getChildren(Object parent
) {
50 Object
[] elements
= null;
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());
60 Node
[] arr
= (Node
[]) nodesList
.toArray(new Node
[nodesList
62 Arrays
.sort(arr
, itemComparator
);
65 return nodesList
.toArray();
68 } catch (RepositoryException e
) {
69 throw new ArgeoException(
70 "Unexpected exception while listing node properties", e
);
75 public boolean hasChildren(Object parent
) {
77 if (parent
instanceof Node
) {
78 Node curNode
= (Node
) parent
;
79 // We manually stop digging at this level
80 if (curNode
.isNodeType(SLC_ARTIFACT_VERSION_BASE
))
82 else if (curNode
.hasNodes())
85 } catch (RepositoryException e
) {
86 throw new ArgeoException(
87 "Unexpected exception while checking if property is multiple",
93 public void setSortChildren(boolean sortChildren
) {
94 this.sortChildren
= sortChildren
;
97 public boolean getSortChildren() {
101 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
104 public void dispose() {