public void itemStateChanged(final ItemEvent e) {
if (handlingEvent || !formatChooser.isEnabled() || e.getStateChange() != ItemEvent.SELECTED)
return;
handlingEvent = true;
final PatternFormat newFormat = toPatternFormat(e.getItem());
final AttributeTable table = attributeView.getAttributeTable();
if (table.getSelectedColumn() == 1 && table.getSelectedRow() != -1) {
final Object value = table.getValueAt(table.getSelectedRow(), table.getSelectedColumn());
try {
final Object newValue = formatValue(newFormat, table, value);
if (newValue != null)
table.setValueAt(newValue, table.getSelectedRow(), table.getSelectedColumn());
}
catch (Exception e2) {
Controller.getCurrentController().getViewController()
.out("Pattern is not applicable: " + e2.getMessage());
LogUtils.warn("pattern is not applicable", e2);
}
}
handlingEvent = false;
}
public PatternFormat toPatternFormat(Object value) {
if (value instanceof PatternFormat)
return (PatternFormat) value;
final PatternFormat patternFormat = PatternFormat.guessPatternFormat(value.toString());
return (patternFormat == null) ? PatternFormat.getIdentityPatternFormat() : patternFormat;
}
private Object formatValue(final PatternFormat newFormat, final AttributeTable table,
final Object objectToBeFormatted) {