]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.akb.ui/src/main/java/org/argeo/slc/akb/ui/providers/TemplatesTreeContentProvider.java
fix a few post refactoring UI Bugs
[gpl/argeo-slc.git] / plugins / org.argeo.slc.akb.ui / src / main / java / org / argeo / slc / akb / ui / providers / TemplatesTreeContentProvider.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.akb.ui.providers;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.jcr.Node;
22 import javax.jcr.NodeIterator;
23 import javax.jcr.RepositoryException;
24
25 import org.argeo.slc.akb.AkbException;
26 import org.argeo.slc.akb.AkbTypes;
27 import org.eclipse.jface.viewers.ITreeContentProvider;
28 import org.eclipse.jface.viewers.Viewer;
29
30 /** Basic content provider for a tree of AKB environment templates */
31 public class TemplatesTreeContentProvider implements ITreeContentProvider {
32
33 /**
34 * @param parent
35 * Pass current user home as parameter
36 *
37 */
38 public Object[] getElements(Object parent) {
39 if (parent instanceof Object[])
40 return (Object[]) parent;
41 else
42 return null;
43 }
44
45 public Object getParent(Object child) {
46 try {
47 Node node = (Node) child;
48 if (node.getDepth() == 0)
49 return null;
50 else
51 return node.getParent();
52 } catch (RepositoryException e) {
53 throw new AkbException("Error while getting parent node", e);
54 }
55 }
56
57 public Object[] getChildren(Object parent) {
58 try {
59 NodeIterator ni = ((Node) parent).getNodes();
60 List<Node> nodes = new ArrayList<Node>();
61
62 while (ni.hasNext()) {
63 Node currNode = ni.nextNode();
64 if (!currNode.isNodeType(AkbTypes.AKB_CONNECTOR_FOLDER))
65 nodes.add(currNode);
66 }
67
68 return nodes.toArray();
69 } catch (RepositoryException e) {
70 throw new AkbException("Error while getting children nodes", e);
71 }
72 }
73
74 public boolean hasChildren(Object parent) {
75 try {
76 // refine this
77 return ((Node) parent).hasNodes();
78 } catch (RepositoryException e) {
79 throw new AkbException("Error while checking children nodes", e);
80 }
81 }
82
83 public void dispose() {
84 // FIXME implement if needed
85 }
86
87 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
88 }
89 }