I am trying to make a more dynamic table. One that listens and updates on the fly with out me having to call a viewer.Refresh().
Today I have a table that is built from a ArrayList - The table is very static and does not refresh unless I call a refresh. My users can be adding data to the arraylist, while they are in the Application GUI and with table displayed. So I need to find a way to listen to the arraylist and know when something has changed. Someone suggested to me I should look at IObservableList and making the ArrayList to a WritableList. I am completely lost on how to implement these changes.
I will try and explain how my current structure is setup and what each class is performing.
AplotDataModel Class - This is the Class where I am building the ArrayList.
static ArrayList<AplotDatasetData> dataArrayList = new ArrayList<AplotDatasetData>();
public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
AplotDatasetData pp = new AplotDatasetData(tcRevision, selectedDataset);
if (!dataArrayList.contains(pp)) {
dataArrayList.add(pp);
}
}
This is the method where I am sending the ArrayList to the ContentProvider in my GUI class
public ArrayList<AplotDatasetData> getArrayData() {
return dataArrayList;
}
I was trying to add the arraylist to a WritableList and return that instead of the ArrayList
public WritableList getListData() {
WritableList wlInput = new WritableList(getArrayData(),AplotDataModel.class);
return wlInput;
}
So that is my data model class.
This is my tableviewer class
public class AplotDataTableViewer extends TableViewer {
public AplotDataTableViewer(Composite parent, int style) {
super(parent, style);
Table table = getTable();
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(gridData);
createColumns();
table.setHeaderVisible(true);
table.setLinesVisible(true);
setContentProvider(new ArrayContentProvider());
}
I was trying to change setContentProvider(new ArrayContentProvider());
to setContentProvider(new ObservableListContentProvider());
but it failed with this error : ObservableListContentProvider cannot be resolved to a type.
This is my GUI class with the table viewer
public class AplotBaseDialog extends TitleAreaDialog {
private void createTableViewer(Composite parent) {
viewer = new AplotDataTableViewer(parent, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION);
viewer.setInput(AplotDataModel.getInstance().getArrayData());
}
I was going to try and call the WritableList from the data model class
viewer.setInput(AplotDataModel.getInstance().getListData());
This what I was thinking I need to change in each class from above.
Data Model Class: (Maybe Implement Observable?)
ArrayList = WritableList
Viewer Class: (Does it need to Implement Anything?)
ContentProvider = (new ObservableListContentProvider()
setInput((AplotDataModel.getInstance().getListData())
; Move to this class from GUI class
GUI Class: (Implement IObservableList?)
create Table Viewer
Some method that knows when the list has changed?
void handleListChange() {
update buttons and etc....
}
I hope I have explained this enough to make sense to you.
I do very much appreciate your time and any help and guidance you can give me would great.