Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Changing from a Arraylist to a WritableList
Changing from a Arraylist to a WritableList [message #988940] Mon, 03 December 2012 22:11 Go to next message
James Teater is currently offline James Teater
Messages: 17
Registered: July 2011
Junior Member
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.
Re: Changing from a Arraylist to a WritableList [message #990433 is a reply to message #988940] Wed, 12 December 2012 13:41 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 919
Registered: July 2009
Senior Member
Hi James,

You are doing the right things...

1. The ObservableListContentProvider should simply exist. (import?).
2. The input to the viewer should be an IObservableList, so an IWriteableList will do.
3. You might want to use an ObservableMapLabelProvider, fed with an IObservableMap, this will trigger label provider updates, when the properties of your model change. An IObservableMap can be something like this: (In my case I observe properties from an EMF package, but the idea is similar for Beans..).

IObservableMap[] observeMaps = EMFObservables
				.observeMaps(
						listContentProvider.getKnownElements(),
						new EStructuralFeature[] {
								MetricsPackage.Literals.METRIC_SOURCE__NAME,
								MetricsPackage.Literals.METRIC_SOURCE__METRIC_LOCATION });


tell us what happens?
Cheers Chrisophe
Re: Changing from a Arraylist to a WritableList [message #990488 is a reply to message #990433] Wed, 12 December 2012 16:46 Go to previous message
James Teater is currently offline James Teater
Messages: 17
Registered: July 2011
Junior Member
Here is what I have tried thus far.

In my data model class.

I am creating a ObservableList from a WritableList

IObservableList observableList = new WritableList();


Then I am building the observableList by adding data to the List(this was the method I used to build the arraylist)

public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
   AplotDatasetData pp = new AplotDatasetData(tcRevision, selectedDataset);
   if (!observableList.contains(pp)) {
        observableList.add(pp);
   }
}// end add()


Then I have a method to return the observableList

public IObservableList getObservableList() {
   return observableList;
}


END OF Data Model Class

My TableViewer class

I am setting the contentProvider

ObservableListContentProvider contentProvider = new ObservableListContentProvider();
setContentProvider(contentProvider);


This class extends TableViewer, I think it read somewhere that it has to be AbstractTableViewer to use ObservableListContentProvider?

Is that true?

END OF TABLE VIEWER CLASS

This is my GUI Class - where the table is displayed in the viewer

viewer = new AplotDataTableViewer(parent, SWT.BORDER|SWT.V_SCROLL|SWT.FULL_SELECTION);
viewer.setInput(AplotDataModel.getInstance().getObservableList());


So how do I listen for changing to my ObservableList? I have tried to implement IListChangeListener and use the handleListChange method to update my viewer.

END GUI CLASS

Right now as it is above, I do not get any errors but I also get no data in my table.
Please Help!!
Previous Topic:Prevent Dialog from Closing
Next Topic:TableViewer SWT.VIRTUAL or not ?
Goto Forum:
  


Current Time: Sat Sep 20 20:20:22 GMT 2014

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

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