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
.List
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.RepositoryException
;
23 import javax
.jcr
.nodetype
.NodeType
;
24 import javax
.jcr
.version
.Version
;
25 import javax
.jcr
.version
.VersionHistory
;
26 import javax
.jcr
.version
.VersionIterator
;
27 import javax
.jcr
.version
.VersionManager
;
29 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
30 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
31 import org
.eclipse
.jface
.viewers
.Viewer
;
34 * Display some version information of a JCR full versionable node in a tree
37 public class FullVersioningTreeContentProvider
implements ITreeContentProvider
{
38 private static final long serialVersionUID
= 8691772509491211112L;
41 * Sends back the first level of the Tree. input element must be a single
44 public Object
[] getElements(Object inputElement
) {
46 Node rootNode
= (Node
) inputElement
;
47 String curPath
= rootNode
.getPath();
48 VersionManager vm
= rootNode
.getSession().getWorkspace()
51 VersionHistory vh
= vm
.getVersionHistory(curPath
);
52 List
<Version
> result
= new ArrayList
<Version
>();
53 VersionIterator vi
= vh
.getAllLinearVersions();
55 while (vi
.hasNext()) {
56 result
.add(vi
.nextVersion());
58 return result
.toArray();
59 } catch (RepositoryException re
) {
60 throw new EclipseUiException(
61 "Unexpected error while getting version elements", re
);
65 public Object
[] getChildren(Object parentElement
) {
67 if (parentElement
instanceof Version
) {
68 List
<Node
> tmp
= new ArrayList
<Node
>();
69 tmp
.add(((Version
) parentElement
).getFrozenNode());
72 } catch (RepositoryException re
) {
73 throw new EclipseUiException("Unexpected error while getting child "
74 + "node for version element", re
);
79 public Object
getParent(Object element
) {
81 // this will not work in a simpleVersionning environment, parent is
83 if (element
instanceof Node
84 && ((Node
) element
).isNodeType(NodeType
.NT_FROZEN_NODE
)) {
85 Node node
= (Node
) element
;
86 return node
.getParent();
89 } catch (RepositoryException e
) {
94 public boolean hasChildren(Object element
) {
96 if (element
instanceof Version
)
98 else if (element
instanceof Node
)
99 return ((Node
) element
).hasNodes();
102 } catch (RepositoryException e
) {
103 throw new EclipseUiException("Cannot check children of " + element
, e
);
107 public void dispose() {
110 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {