Check Data Binding Values [message #682917] |
Sun, 12 June 2011 09:17  |
Eclipse User |
|
|
|
I am trying to bind some model data to my TableViewer widgets. I have no problems binding the data. But the only thing is that the widget gets bound value and then display it on the widget with the direct data value.
So for example, if it was some kind of enumeration datatype like Movement.WALK, Movement.RUN, etc, the widget will show directly as WALK, RUN. I wish I could check the bound value and then display the data according to my own preference. In other words, if the bound value had a change in value and it was Movement.WALK, I wish to show in the TableViewer that "Player 1 is walking".
I am using windowsbuilder pro and I am using the generated code with something like this:
IObservableValue tableViewer_myTestObserveSingleSelection = ViewersObservables.observeSingleSelection(tableViewer_myTest);
IObservableList tableViewer_myTestDataContentObserveDetailList = BeansObservables.observeDetailList(tableViewer_myTestObserveSingleSelection, "DataContent", TestModelData.class);
tableViewer_DataContent.setInput(tableViewer_myTestDataContentObserveDetailList);
So, is there a way to check a bound value before displaying it on the widget? Thanks!
|
|
|
Re: Check Data Binding Values [message #683126 is a reply to message #682917] |
Sun, 12 June 2011 23:51  |
Eclipse User |
|
|
|
You can use converter for displaying modifying content.
Write a converter class for accepting enum value and append your text with value. Now use this class in UpdateValueStrategy of the binding. Similarly write one more converter class for text to enum conversion.
//////Converter///////////
public class EnumtoTextConverter extends Converter {
public EnumtoTextConverter() {
this(MyEnum.class, Strin.class);
}
public EnumtoTextConverter(Object fromType, Object toType) {
super(fromType, toType);
}
@Override
public Object convert(Object fromObject) {
try{
// your convertion code..
}
catch(Exception ex){
// Handle exception
}
return result;
}
}
/////////////Binding//////
UpdateValueStrategy strategy = new UpdateValueStrategy();
strategy.setConverter(new EnumtoTextConverter());
UpdateValueStrategy strategy_1 = new UpdateValueStrategy();
strategy_1.setConverter(new TexttoEnumConverter());
bindingContext.bindValue(observer1, observer2, strategy, strategy_1);
|
|
|
Powered by
FUDForum. Page generated in 0.05386 seconds