Display value different than data value in editing cells [message #988963] |
Tue, 04 December 2012 00:35  |
Eclipse User |
|
|
|
hi!
(i'm not a native english speaker so please forgive my grammar mistakes)
I want to display derived data in a cell but when i'll try to edit the cell, i want to show me the original data value instead of the derived data. For example, let's say i'm selling a tablet at $300 and a costumer buys me 5. I want a column "Value" shows $1500 but when i'll edit it, it will show me 5.
From the example EditableGridExample.java i tried something like this:
private static IDisplayConverter getMillionsDisplayConverter() {
return new DisplayConverter(){
NumberFormat numberFormatter = new DecimalFormat("###,###,###");
int price = 300;
public Object canonicalToDisplayValue(Object canonicalValue) {
if (canonicalValue == null) {
return null;
}
return numberFormatter.format(Integer.valueOf(canonicalValue.toString())*price);
}
public Object displayToCanonicalValue(Object displayValue) {
return (numberFormatter.parse(displayValue.toString(), new ParsePosition(0))).intValue();
}
};
}
This partially works. The thing is when a try to edit it for the second time, takes the value that it was displayed ($1500) instead of the value that i entered before (5).
could someone help me ?
thanks
|
|
|
|
|
|
Re: Display value different than data value in editing cells [message #989405 is a reply to message #989266] |
Thu, 06 December 2012 01:14  |
Eclipse User |
|
|
|
i started playing with the "CalculatingGridExample" because is a lot more simpler than EditableGridExample and i learned how to do it.
What i did was to make my own DisplayConverter class and register it as "DisplayMode.NORMAL", that was the solution 
Here is the code
thanks
class CalulatingEditConfiguration extends AbstractRegistryConfiguration {
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE,
DisplayMode.EDIT, CalculatingGridExample.COLUMN_FOUR_LABEL);
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE,
DisplayMode.EDIT, CalculatingGridExample.COLUMN_FIVE_LABEL);
//configure the summary row to be not editable
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE,
DisplayMode.EDIT, SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
configRegistry.registerConfigAttribute(
CellConfigAttributes.DISPLAY_CONVERTER, new PriceConverter(), DisplayMode.NORMAL);
configRegistry.registerConfigAttribute(
CellConfigAttributes.DISPLAY_CONVERTER, new DefaultIntegerDisplayConverter(), DisplayMode.EDIT);
configRegistry.registerConfigAttribute(
CellConfigAttributes.DISPLAY_CONVERTER, new PercentageDisplayConverter(),
DisplayMode.NORMAL, CalculatingGridExample.COLUMN_FIVE_LABEL);
configRegistry.registerConfigAttribute(
CellConfigAttributes.DISPLAY_CONVERTER, new PercentageDisplayConverter(),
DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 4);
}
class PriceConverter extends DisplayConverter {
public Object canonicalToDisplayValue(Object canonicalValue) {
try {
if (isNotNull(canonicalValue)) {
int num = Integer.valueOf(canonicalValue.toString());
num = num*300;
return num;
}
return null;
} catch (Exception e) {
return canonicalValue;
}
}
public Object displayToCanonicalValue(Object displayValue) {
try {
if (isNotNull(displayValue) && isNotEmpty(displayValue.toString())) {
return Integer.valueOf(displayValue.toString())/300;
}
return null;
} catch (Exception e) {
throw new ConversionFailedException(
Messages.getString("NumericDisplayConverter.failure", //$NON-NLS-1$
new Object[] {displayValue}), e);
}
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.35895 seconds