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%2Futils%2FDistNodeViewerComparator.java;fp=cms%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Futils%2FDistNodeViewerComparator.java;h=0000000000000000000000000000000000000000;hb=6fc94d69efe089414ac9e63bde3efab1cbf7b7ca;hp=14119969f7a2c4d5372968921b2a30a4f18115a1;hpb=b36c62642bd0db11b3133b369cc026fd4b7a1ec6;p=gpl%2Fargeo-slc.git diff --git a/cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/utils/DistNodeViewerComparator.java b/cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/utils/DistNodeViewerComparator.java deleted file mode 100644 index 14119969f..000000000 --- a/cms/org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/utils/DistNodeViewerComparator.java +++ /dev/null @@ -1,167 +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.eclipse.ui.GenericTableComparator; -import org.argeo.slc.SlcException; -import org.eclipse.jface.viewers.Viewer; - -/** Add ability to order by name version and version */ -public class DistNodeViewerComparator extends GenericTableComparator { - private static final long serialVersionUID = -5966120108210992211L; - - private final static Log log = LogFactory - .getLog(DistNodeViewerComparator.class); - - // Jcr property type goes to 12 - public final static int NAME_VERSION_TYPE = 100; - public final static int VERSION_TYPE = 101; - - protected List propertiesList; - protected List propertyTypesList; - protected Integer propertyType; - protected String property; - - private NameVersionComparator nvc = new NameVersionComparator(); - private VersionComparator vc = new VersionComparator(); - - public DistNodeViewerComparator(int defaultColIndex, int defaultDirection, - List propertiesList, List 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 NAME_VERSION_TYPE: - rc = nvc.compare(viewer, v1.getString(), v2.getString()); - break; - case VERSION_TYPE: - rc = vc.compare(viewer, v1.getString(), v2.getString()); - break; - 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 SlcException( - "Unimplemented comparaison for PropertyType " - + propertyType); - } - - // If descending order, flip the direction - if (direction == DESCENDING) { - rc = -rc; - } - - } catch (RepositoryException re) { - throw new SlcException("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