use of org.entirej.framework.core.data.EJDataRecord 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;
}
};
}
use of org.entirej.framework.core.data.EJDataRecord in project rap by entirej.
the class EJRWTTextItemRenderer method createColumnLabelProvider.
@Override
public ColumnLabelProvider createColumnLabelProvider(final EJScreenItemProperties item, EJScreenItemController controller) {
ColumnLabelProvider provider = new TextHtmlEscapeSupport() {
@Override
public Color getBackground(Object element) {
EJCoreVisualAttributeProperties properties = getAttributes(item, element);
if (properties != null) {
Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
if (background != null) {
return background;
}
}
return super.getBackground(element);
}
@Override
public Color getForeground(Object element) {
EJCoreVisualAttributeProperties properties = getAttributes(item, element);
if (properties != null) {
Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
if (foreground != null) {
return foreground;
}
}
return super.getForeground(element);
}
private EJCoreVisualAttributeProperties getAttributes(final EJScreenItemProperties item, Object element) {
EJCoreVisualAttributeProperties properties = null;
if (element instanceof EJDataRecord) {
EJDataRecord record = (EJDataRecord) element;
properties = record.getItem(item.getReferencedItemName()).getVisualAttribute();
}
if (properties == null) {
properties = _visualAttributeProperties;
}
return properties;
}
@Override
public Font getFont(Object element) {
EJCoreVisualAttributeProperties properties = getAttributes(item, element);
if (properties != null) {
return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, super.getFont(element));
}
return super.getFont(element);
}
@Override
public String getText(Object element) {
if (element instanceof EJDataRecord) {
EJDataRecord record = (EJDataRecord) element;
Object value = record.getValue(item.getReferencedItemName());
if (value instanceof String) {
return check(value.toString());
}
}
return "";
}
String check(String text) {
if (escapeHtml && text != null && !text.isEmpty()) {
return escapeHtml(text);
}
return text;
}
String escapeHtml(String string) {
StringBuilder escapedTxt = new StringBuilder();
for (int i = 0; i < string.length(); i++) {
char tmp = string.charAt(i);
switch(tmp) {
case '<':
escapedTxt.append("<");
break;
case '>':
escapedTxt.append(">");
break;
case '&':
escapedTxt.append("&");
break;
case '"':
escapedTxt.append(""");
break;
case '\'':
escapedTxt.append("'");
break;
case '/':
escapedTxt.append("/");
break;
default:
escapedTxt.append(tmp);
}
}
return escapedTxt.toString();
}
};
return provider;
}
Aggregations