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
.akb
.ui
.providers
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.NodeIterator
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.Session
;
26 import org
.argeo
.slc
.akb
.AkbException
;
27 import org
.argeo
.slc
.akb
.AkbNames
;
28 import org
.argeo
.slc
.akb
.AkbTypes
;
29 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
30 import org
.eclipse
.jface
.viewers
.Viewer
;
33 * Content provider for a tree of active AKB environments. Displays
34 * <CODE>ActiveTreeItem</CODE> to be able to display subtrees of item without
35 * duplicating the information from the corresponding template.
37 public class ActiveEnvsTreeContentProvider
implements ITreeContentProvider
{
38 // private final static Log log = LogFactory
39 // .getLog(ActiveEnvsTreeContentProvider.class);
43 * Pass base parent node as parameter
46 public Object
[] getElements(Object parent
) {
47 if (parent
instanceof Node
)
48 return initializeTree((Node
) parent
);
53 private ActiveTreeItem
[] initializeTree(Node activeEnvsParentNode
) {
55 NodeIterator ni
= activeEnvsParentNode
.getNodes();
56 List
<ActiveTreeItem
> envs
= new ArrayList
<ActiveTreeItem
>();
57 while (ni
.hasNext()) {
58 Node currNode
= ni
.nextNode();
59 if (currNode
.isNodeType(AkbTypes
.AKB_ENV
)) {
60 envs
.add(new ActiveTreeItem(null, currNode
, currNode
));
63 ActiveTreeItem
[] envArr
= envs
.toArray(new ActiveTreeItem
[envs
66 } catch (RepositoryException re
) {
67 throw new AkbException("Error while initializing the "
68 + "tree of active environments.", re
);
72 public Object
getParent(Object child
) {
73 return ((ActiveTreeItem
) child
).getParent();
76 public Object
[] getChildren(Object parent
) {
78 ActiveTreeItem currItem
= (ActiveTreeItem
) parent
;
79 Node parNode
= currItem
.getNode();
80 Node envNode
= currItem
.getEnvironment();
82 if (parNode
.isNodeType(AkbTypes
.AKB_ENV
)) {
83 Session session
= parNode
.getSession();
84 if (parNode
.hasProperty(AkbNames
.AKB_ENV_TEMPLATE_PATH
)
85 && session
.nodeExists(parNode
.getProperty(
86 AkbNames
.AKB_ENV_TEMPLATE_PATH
).getString()))
87 parNode
= session
.getNode(parNode
.getProperty(
88 AkbNames
.AKB_ENV_TEMPLATE_PATH
).getString());
93 NodeIterator ni
= parNode
.getNodes();
94 List
<ActiveTreeItem
> children
= new ArrayList
<ActiveTreeItem
>();
95 while (ni
.hasNext()) {
96 Node currNode
= ni
.nextNode();
97 if (!currNode
.isNodeType(AkbTypes
.AKB_CONNECTOR_FOLDER
)) {
98 ActiveTreeItem currChild
= new ActiveTreeItem(currItem
,
100 children
.add(currChild
);
103 return children
.toArray();
104 } catch (RepositoryException e
) {
105 throw new AkbException("Error while getting children nodes", e
);
109 public boolean hasChildren(Object parent
) {
111 ActiveTreeItem currItem
= (ActiveTreeItem
) parent
;
112 Node parNode
= currItem
.getNode();
114 if (parNode
.isNodeType(AkbTypes
.AKB_ENV
)) {
115 Session session
= parNode
.getSession();
116 if (parNode
.hasProperty(AkbNames
.AKB_ENV_TEMPLATE_PATH
)
117 && session
.nodeExists(parNode
.getProperty(
118 AkbNames
.AKB_ENV_TEMPLATE_PATH
).getString()))
119 parNode
= session
.getNode(parNode
.getProperty(
120 AkbNames
.AKB_ENV_TEMPLATE_PATH
).getString());
125 return parNode
.hasNodes();
126 } catch (RepositoryException e
) {
127 throw new AkbException("Error while checking children nodes", e
);
131 public void dispose() {
132 // FIXME implement if needed
135 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {