use of org.entirej.applicationframework.rwt.table.EJRWTAbstractTableSorter in project rap by entirej.
the class EJRWTTextItemRenderer method getColumnSorter.
@Override
public EJRWTAbstractTableSorter getColumnSorter(final EJScreenItemProperties item, EJScreenItemController controller) {
final Collator compareCollator = Collator.getInstance();
return new EJRWTAbstractTableSorter() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof EJDataRecord && e2 instanceof EJDataRecord) {
EJDataRecord d1 = (EJDataRecord) e1;
EJDataRecord d2 = (EJDataRecord) e2;
if (d1 != null && d2 != null) {
Object value1 = d1.getValue(item.getReferencedItemName());
Object value2 = d2.getValue(item.getReferencedItemName());
if (value1 == null && value2 == null) {
return 0;
}
if (value1 == null && value2 != null) {
return -1;
}
if (value1 != null && value2 == null) {
return 1;
}
return compareCollator.compare(value1, value2);
}
}
return 0;
}
@Override
public int compareNumber(Viewer viewer, Object e1, Object e2, DecimalFormat frm) {
if (e1 instanceof EJDataRecord && e2 instanceof EJDataRecord) {
EJDataRecord d1 = (EJDataRecord) e1;
EJDataRecord d2 = (EJDataRecord) e2;
if (d1 != null && d2 != null) {
Object value1 = d1.getValue(item.getReferencedItemName());
Object value2 = d2.getValue(item.getReferencedItemName());
if (value1 == null && value2 == null) {
return 0;
}
if (value1 == null && value2 != null) {
return -1;
}
if (value1 != null && value2 == null) {
return 1;
}
if (value1 instanceof String && value2 instanceof String) {
try {
Number dv1 = frm.parse((String) value1);
Number dv2 = frm.parse((String) value2);
return Double.compare(dv1.doubleValue(), dv2.doubleValue());
} catch (NumberFormatException f) {
return compareCollator.compare(value1, value2);
} catch (ParseException e) {
return compareCollator.compare(value1, value2);
}
}
return compareCollator.compare(value1, value2);
}
}
return 0;
}
@Override
public int compareDate(Viewer viewer, Object e1, Object e2, DateFormat format) {
if (e1 instanceof EJDataRecord && e2 instanceof EJDataRecord) {
EJDataRecord d1 = (EJDataRecord) e1;
EJDataRecord d2 = (EJDataRecord) e2;
if (d1 != null && d2 != null) {
Object value1 = d1.getValue(item.getReferencedItemName());
Object value2 = d2.getValue(item.getReferencedItemName());
if (value1 == null && value2 == null) {
return 0;
}
if (value1 == null && value2 != null) {
return -1;
}
if (value1 != null && value2 == null) {
return 1;
}
if (value1 instanceof String && value2 instanceof String) {
try {
Date dv1 = format.parse((String) value1);
Date dv2 = format.parse((String) value2);
return dv1.compareTo(dv2);
} catch (ParseException e) {
// ignore
}
}
return compareCollator.compare(value1, value2);
}
}
return 0;
}
};
}
Aggregations