*/
package org.argeo.slc.akb.ui.providers;
-import org.argeo.eclipse.ui.TreeParent;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.akb.AkbException;
+import org.argeo.slc.akb.AkbTypes;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
-/** Basic content provider for a tree of AKB environment templates */
+/** Basic content provider for a tree of active AKB environments */
public class TemplatesTreeContentProvider implements ITreeContentProvider {
+ private final static Log log = LogFactory
+ .getLog(TemplatesTreeContentProvider.class);
/**
* @param parent
- * Pass current user home as parameter
- *
*/
public Object[] getElements(Object parent) {
if (parent instanceof Object[])
}
public Object getParent(Object child) {
- return ((TreeParent) child).getParent();
+ try {
+ Node node = (Node) child;
+
+ // Manual sanity check to avoid exception when trying to refresh an
+ // element that displays a node which has been removed
+ try {
+ String id = node.getIdentifier();
+ node.getSession().getNodeByIdentifier(id);
+ } catch (Exception e) {
+ log.warn("Trying to refresh an unexisting node");
+ return null;
+ }
+
+ if (node.getDepth() == 0)
+ return null;
+ else
+ return node.getParent();
+
+ } catch (RepositoryException e) {
+ throw new AkbException("Error while getting parent node", e);
+ }
}
public Object[] getChildren(Object parent) {
- return ((TreeParent) parent).getChildren();
+ try {
+ NodeIterator ni = ((Node) parent).getNodes();
+ List<Node> nodes = new ArrayList<Node>();
+
+ while (ni.hasNext()) {
+ Node currNode = ni.nextNode();
+ if (!currNode.isNodeType(AkbTypes.AKB_CONNECTOR_FOLDER))
+ nodes.add(currNode);
+ }
+
+ return nodes.toArray();
+ } catch (RepositoryException e) {
+ throw new AkbException("Error while getting children nodes", e);
+ }
}
public boolean hasChildren(Object parent) {
- return ((TreeParent) parent).hasChildren();
+ try {
+ // refine this
+ return ((Node) parent).hasNodes();
+ } catch (RepositoryException e) {
+ throw new AkbException("Error while checking children nodes", e);
+ }
}
public void dispose() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
+
+
+
}
\ No newline at end of file