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
.cms
.ui
.jcr
;
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
.eclipse
.ui
.EclipseUiException
;
27 import org
.argeo
.eclipse
.ui
.jcr
.utils
.JcrItemsComparator
;
28 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
29 import org
.eclipse
.jface
.viewers
.Viewer
;
32 * Implementation of the {@code ITreeContentProvider} in order to display a
33 * single JCR node and its children in a tree like structure
35 public class JcrTreeContentProvider
implements ITreeContentProvider
{
36 private static final long serialVersionUID
= -2128326504754297297L;
37 // private Node rootNode;
38 private JcrItemsComparator itemComparator
= new JcrItemsComparator();
41 * Sends back the first level of the Tree. input element must be a single node
44 public Object
[] getElements(Object inputElement
) {
45 Node rootNode
= (Node
) inputElement
;
46 return childrenNodes(rootNode
);
49 public Object
[] getChildren(Object parentElement
) {
50 return childrenNodes((Node
) parentElement
);
53 public Object
getParent(Object element
) {
55 Node node
= (Node
) element
;
56 if (!node
.getPath().equals("/"))
57 return node
.getParent();
60 } catch (RepositoryException e
) {
65 public boolean hasChildren(Object element
) {
67 return ((Node
) element
).hasNodes();
68 } catch (RepositoryException e
) {
69 throw new EclipseUiException("Cannot check children existence on " + element
, e
);
73 protected Object
[] childrenNodes(Node parentNode
) {
75 List
<Node
> children
= new ArrayList
<Node
>();
76 NodeIterator nit
= parentNode
.getNodes();
77 while (nit
.hasNext()) {
78 Node node
= nit
.nextNode();
79 // if (node.getName().startsWith("rep:") || node.getName().startsWith("jcr:")
80 // || node.getName().startsWith("nt:"))
84 Node
[] arr
= children
.toArray(new Node
[0]);
85 Arrays
.sort(arr
, itemComparator
);
87 } catch (RepositoryException e
) {
88 throw new EclipseUiException("Cannot list children of " + parentNode
, e
);
92 public void dispose() {
95 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {