X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=cms%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcontrollers%2FArtifactsTreeContentProvider.java;fp=cms%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcontrollers%2FArtifactsTreeContentProvider.java;h=5559b44687e4e2da9f4f495c67b1910ec09c06d2;hb=ecc22e604e47533c79de9cecdcdeacbc752cbff1;hp=0000000000000000000000000000000000000000;hpb=e07ded4632e53f8b8869763bc1f1f4091361e76e;p=gpl%2Fargeo-slc.git diff --git a/cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/controllers/ArtifactsTreeContentProvider.java b/cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/controllers/ArtifactsTreeContentProvider.java new file mode 100644 index 000000000..5559b4468 --- /dev/null +++ b/cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/controllers/ArtifactsTreeContentProvider.java @@ -0,0 +1,91 @@ +package org.argeo.slc.client.ui.dist.controllers; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.RepositoryException; + +import org.argeo.eclipse.ui.jcr.util.JcrItemsComparator; +import org.argeo.slc.SlcException; +import org.argeo.slc.SlcTypes; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** Enable specific browsing of an artifact tree */ +public class ArtifactsTreeContentProvider implements ITreeContentProvider, + SlcTypes { + private static final long serialVersionUID = -8097817288192073987L; + + // Utils + private boolean sortChildren = true; + private JcrItemsComparator itemComparator = new JcrItemsComparator(); + + public Object[] getElements(Object parent) { + return getChildren(parent); + } + + public Object getParent(Object child) { + return null; + } + + public Object[] getChildren(Object parent) { + Object[] elements = null; + try { + if (parent instanceof Node) { + Node node = (Node) parent; + NodeIterator ni = node.getNodes(); + List nodesList = new ArrayList(); + while (ni.hasNext()) { + nodesList.add(ni.nextNode()); + } + if (sortChildren) { + Node[] arr = (Node[]) nodesList.toArray(new Node[nodesList + .size()]); + Arrays.sort(arr, itemComparator); + return arr; + } else + return nodesList.toArray(); + + } + } catch (RepositoryException e) { + throw new SlcException( + "Unexpected exception while listing node properties", e); + } + return elements; + } + + public boolean hasChildren(Object parent) { + try { + if (parent instanceof Node) { + Node curNode = (Node) parent; + // We manually stop digging at this level + if (curNode.isNodeType(SLC_ARTIFACT_VERSION_BASE)) + return false; + else if (curNode.hasNodes()) + return true; + } + } catch (RepositoryException e) { + throw new SlcException( + "Unexpected exception while checking if property is multiple", + e); + } + return false; + } + + public void setSortChildren(boolean sortChildren) { + this.sortChildren = sortChildren; + } + + public boolean getSortChildren() { + return sortChildren; + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } +} \ No newline at end of file