]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultItemsComparator.java
Start migrating SLC client
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / model / ResultItemsComparator.java
diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultItemsComparator.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultItemsComparator.java
deleted file mode 100644 (file)
index 30e7baa..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-package org.argeo.slc.client.ui.model;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.jcr.SlcNames;
-import org.argeo.slc.jcr.SlcTypes;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-
-/** Enable specific sorting of the ResultTreeView */
-public class ResultItemsComparator extends ViewerComparator {
-
-       @Override
-       public int category(Object element) {
-               if (element instanceof SingleResultNode) {
-                       return 10;
-
-               }
-               // folder always first
-               return 5;
-       }
-
-       @Override
-       public int compare(Viewer viewer, Object e1, Object e2) {
-               int cat1 = category(e1);
-               int cat2 = category(e2);
-
-               if (cat1 != cat2) {
-                       return cat1 - cat2;
-               }
-
-               int result = 0;
-
-               if (e1 instanceof TreeParent && ((TreeParent) e1).getParent() == null) {
-                       // preserve predefined order on UI root items
-                       return 0;
-               }
-
-               if (e1 instanceof SingleResultNode && e2 instanceof SingleResultNode) {
-                       Node an = ((SingleResultNode) e1).getNode();
-                       Node bn = ((SingleResultNode) e2).getNode();
-                       try {
-                               // Order is different if we are under my Result or )in the
-                               // rest of the tree structure
-                               if (an.getParent().isNodeType(
-                                               SlcTypes.SLC_MY_RESULT_ROOT_FOLDER)
-                                               || an.getParent()
-                                                               .isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {
-                                       result = super.compare(viewer, e1, e2);
-                                       // Specific case of two result with same name
-                                       if (result == 0) {
-                                               result = an
-                                                               .getProperty(SlcNames.SLC_COMPLETED)
-                                                               .getDate()
-                                                               .compareTo(
-                                                                               bn.getProperty(SlcNames.SLC_COMPLETED)
-                                                                                               .getDate());
-                                       }
-                               } else {
-                                       result = an
-                                                       .getProperty(Property.JCR_CREATED)
-                                                       .getDate()
-                                                       .compareTo(
-                                                                       bn.getProperty(Property.JCR_CREATED)
-                                                                                       .getDate());
-                                       result = result * -1; // last are displayed first
-                               }
-                       } catch (RepositoryException e) {
-                               throw new SlcException("Unable to compare date created", e);
-                       }
-               } else if (e1 instanceof ParentNodeFolder
-                               && e2 instanceof ParentNodeFolder) {
-                       try {
-                               Node an = ((ParentNodeFolder) e1).getNode();
-                               // under my Result
-                               if (an.isNodeType(SlcTypes.SLC_MY_RESULT_ROOT_FOLDER)
-                                               || an.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {
-                                       result = super.compare(viewer, e1, e2);
-                               } else {
-                                       // only remaining objects for the time being
-                                       // NT_UNSTRUCTURED that display all result tree structures
-                                       // We want the newest folders first
-                                       result = super.compare(viewer, e1, e2) * -1;
-                               }
-                       } catch (RepositoryException e) {
-                               throw new SlcException("Unable to compare date created", e);
-                       }
-               }
-               return result;
-       }
-}
\ No newline at end of file