|
|
|
|
Re: Display value different than data value in editing cells [message #989405 is a reply to message #989266] |
Thu, 06 December 2012 06:14 |
Mauricio Bustamante Messages: 3 Registered: December 2012 |
Junior Member |
|
|
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.03620 seconds