]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/NodeViewerComparator.java
Restructure SLC
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / utils / NodeViewerComparator.java
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/NodeViewerComparator.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/NodeViewerComparator.java
deleted file mode 100644 (file)
index 8a0ad60..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-package org.argeo.slc.client.ui.dist.utils;
-
-import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.GenericTableComparator;
-import org.eclipse.jface.viewers.Viewer;
-
-public class NodeViewerComparator extends GenericTableComparator {
-       private final static Log log = LogFactory
-                       .getLog(NodeViewerComparator.class);
-
-       protected List<String> propertiesList;
-       protected List<Integer> propertyTypesList;
-       protected Integer propertyType;
-       protected String property;
-
-       public NodeViewerComparator(int defaultColIndex, int defaultDirection,
-                       List<String> propertiesList, List<Integer> propertyTypesList) {
-               super(defaultColIndex, defaultDirection);
-               this.propertiesList = propertiesList;
-               this.propertyTypesList = propertyTypesList;
-               this.propertyIndex = defaultColIndex;
-               this.propertyType = propertyTypesList.get(defaultColIndex);
-               this.property = propertiesList.get(defaultColIndex);
-               setColumn(defaultColIndex);
-       }
-
-       @Override
-       public int compare(Viewer viewer, Object e1, Object e2) {
-               int rc = 0;
-               long lc = 0;
-
-               try {
-                       Node n1 = (Node) e1;
-                       Node n2 = (Node) e2;
-
-                       Value v1 = null;
-                       Value v2 = null;
-                       if (n1.hasProperty(property))
-                               v1 = n1.getProperty(property).getValue();
-                       if (n2.hasProperty(property))
-                               v2 = n2.getProperty(property).getValue();
-
-                       if (v2 == null && v1 == null)
-                               return 0;
-                       else if (v2 == null)
-                               return -1;
-                       else if (v1 == null)
-                               return 1;
-
-                       switch (propertyType) {
-                       case PropertyType.STRING:
-                               rc = v1.getString().compareTo(v2.getString());
-                               break;
-                       case PropertyType.BOOLEAN:
-                               boolean b1 = v1.getBoolean();
-                               boolean b2 = v2.getBoolean();
-                               if (b1 == b2)
-                                       rc = 0;
-                               else
-                                       // we assume true is greater than false
-                                       rc = b1 ? 1 : -1;
-                               break;
-                       case PropertyType.DATE:
-                               Calendar c1 = v1.getDate();
-                               Calendar c2 = v2.getDate();
-                               if (c1 == null || c2 == null)
-                                       log.trace("undefined date");
-                               lc = c1.getTimeInMillis() - c2.getTimeInMillis();
-                               if (lc < Integer.MIN_VALUE)
-                                       // rc = Integer.MIN_VALUE;
-                                       rc = -1;
-                               else if (lc > Integer.MAX_VALUE)
-                                       // rc = Integer.MAX_VALUE;
-                                       rc = 1;
-                               else
-                                       rc = (int) lc;
-                               break;
-                       case PropertyType.LONG:
-                               long l1;
-                               long l2;
-                               // FIXME sometimes an empty string is set instead of the id 
-                               try {
-                                       l1 = v1.getLong();
-                               } catch (ValueFormatException ve) {
-                                       l1 = 0;
-                               }
-                               try {
-                                       l2 = v2.getLong();
-                               } catch (ValueFormatException ve) {
-                                       l2 = 0;
-                               }
-
-                               lc = l1 - l2;
-                               if (lc < Integer.MIN_VALUE)
-                                       // rc = Integer.MIN_VALUE;
-                                       rc = -1;
-                               else if (lc > Integer.MAX_VALUE)
-                                       // rc = Integer.MAX_VALUE;
-                                       rc = 1;
-                               else
-                                       rc = (int) lc;
-                               break;
-                       case PropertyType.DECIMAL:
-                               BigDecimal bd1 = v1.getDecimal();
-                               BigDecimal bd2 = v2.getDecimal();
-                               rc = bd1.compareTo(bd2);
-                               break;
-                       default:
-                               throw new ArgeoException(
-                                               "Unimplemented comparaison for PropertyType "
-                                                               + propertyType);
-                       }
-
-                       // If descending order, flip the direction
-                       if (direction == DESCENDING) {
-                               rc = -rc;
-                       }
-
-               } catch (RepositoryException re) {
-                       throw new ArgeoException("Unexpected error "
-                                       + "while comparing nodes", re);
-               }
-               return rc;
-       }
-
-       @Override
-       public void setColumn(int column) {
-               if (column == this.propertyIndex) {
-                       // Same column as last sort; toggle the direction
-                       direction = 1 - direction;
-               } else {
-                       // New column; do a descending sort
-                       this.propertyIndex = column;
-                       this.propertyType = propertyTypesList.get(column);
-                       this.property = propertiesList.get(column);
-                       direction = ASCENDING;
-               }
-       }
-}
\ No newline at end of file