Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Check Data Binding Values(So that the value displayed on widget can be changed accordingly)
Check Data Binding Values [message #682917] Sun, 12 June 2011 13:17 Go to next message
Ken Smith is currently offline Ken SmithFriend
Messages: 3
Registered: May 2011
Junior Member
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] Mon, 13 June 2011 03:51 Go to previous message
Eclipse user Chennai is currently offline Eclipse user ChennaiFriend
Messages: 15
Registered: May 2011
Junior Member

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);
Previous Topic:Showing an Image while the section is being regenerated in the Background
Next Topic:Is a fixed height view possible?
Goto Forum:
  


Current Time: Fri Apr 26 14:16:42 GMT 2024

Powered by FUDForum. Page generated in 0.02814 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top