I am looking into JFace for Eclipse development. I made a plugin to act as a dummy content provider for a ComboViewer. This provider essentially provides the data model as an ArrayList of hardcoded values. Anyway, I tried to understand the approach.
I set the model on the ComboViewer via the comboViewer.setInput(list) method.
On the press of a button I call another object’s method that updates the list I passed as input to the ComboViewer (adds another element) and I call comboViewer.refresh to reflect the change, but nothing happens.
Turns out:
I need to call comboViewer.setInput(list) with the updated list to see the changes in the data (i.e. the previous addition) in my UI combo. I found that comboViewer.refresh reflects any updates only if I get the a hold of comboViewer‘s passed as input Object and modify that. I.e. if I do:
List<SomeObject> data = ((List<SomeObject>)(comboViewer.getInput()));
data.add(new SomeObject("aaa","cccc"));
comboViewer.refresh();
Only like this the data are refreshed. But I don’t understand what is the proper way to use these APIs.
Am I supposed to ever get a hold and modify the object I pass in the setInput method? It feels I should not be doing it. So what is the purpose of refresh?
What is the proper way to do updates of the data that are provided to the Viewers?
The proper way to reflect changes is to call
refresh. Thelistcreate components
when you push the button the combo viewer is updated.