]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/ArtifactsTreeContentProvider.java
+ introduce advanced submenu for distribution view
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / controllers / ArtifactsTreeContentProvider.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.client.ui.dist.controllers;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import javax.jcr.Node;
23 import javax.jcr.NodeIterator;
24 import javax.jcr.RepositoryException;
25
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;
31
32 public class ArtifactsTreeContentProvider implements ITreeContentProvider,
33 SlcTypes {
34
35 // Utils
36 private boolean sortChildren = true;
37 private JcrItemsComparator itemComparator = new JcrItemsComparator();
38
39 public Object[] getElements(Object parent) {
40 return getChildren(parent);
41 }
42
43 public Object getParent(Object child) {
44 return null;
45 }
46
47 public Object[] getChildren(Object parent) {
48 Object[] elements = null;
49 try {
50 if (parent instanceof Node) {
51 Node node = (Node) parent;
52 NodeIterator ni = node.getNodes();
53 List<Node> nodesList = new ArrayList<Node>();
54 while (ni.hasNext()) {
55 nodesList.add(ni.nextNode());
56 }
57 if (sortChildren) {
58 Node[] arr = (Node[]) nodesList.toArray(new Node[nodesList
59 .size()]);
60 Arrays.sort(arr, itemComparator);
61 return arr;
62 } else
63 return nodesList.toArray();
64
65 }
66 } catch (RepositoryException e) {
67 throw new ArgeoException(
68 "Unexpected exception while listing node properties", e);
69 }
70 return elements;
71 }
72
73 public boolean hasChildren(Object parent) {
74 try {
75 if (parent instanceof Node) {
76 Node curNode = (Node) parent;
77 // We manually stop digging at this level
78 if (curNode.isNodeType(SLC_ARTIFACT_VERSION_BASE))
79 return false;
80 else if (curNode.hasNodes())
81 return true;
82 }
83 } catch (RepositoryException e) {
84 throw new ArgeoException(
85 "Unexpected exception while checking if property is multiple",
86 e);
87 }
88 return false;
89 }
90
91 public void setSortChildren(boolean sortChildren) {
92 this.sortChildren = sortChildren;
93 }
94
95 public boolean getSortChildren() {
96 return sortChildren;
97 }
98
99 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
100 }
101
102 public void dispose() {
103 }
104 }