WritableTableFormat + FilteredList

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

WritableTableFormat + FilteredList

Clayton Carter-2

What is the recommended way for dealing with editing a cell in a table row which results in the the row/Object not matching the FilteredList displayed in the table?  Specifically if the edited Object needs to be further processed in some way?

For context: I have a database, read through an ORM layer, which returns a list of Objects which are then filtered, sorted and displayed in the table.  The table displays a subset of the Object properties, with a "details" panel displaying the rest.  I turned on cell editing today (by implementing WritableTableFormat) which is working (updating in UI and db) when sort/filter is not affected, and I have it working if the change affects sort order by using

masterListSorted.setMode(SortedList.AVOID_MOVING_ELEMENTS);

and I'm monitoring for changes with ListEventListener, checking as follows:

public void listChanged( ListEvent listChanges ) {

      Object source = listChanges.getSource();

      if ( source == masterListSorted ) {
        if ( masterListSorted.size() > 0 ) {
          listChanges.next();
          if ( listChanges.getType() == ListEvent.UPDATE )
            updateRecordInDB( masterListSorted.get( listChanges.getIndex() ));
        }
      }
}

I'm using getIndex() which of course is wrong after the list is sorted or the filtered list changed.  Perhaps I'm misreading the API, but is getIndex() really the closest I can get to finding out which specific Object was changed?  Any suggestions for a more robust technique?

Thank you,
Clayton


Reply | Threaded
Open this post in threaded view
|

Re: WritableTableFormat + FilteredList

James Lemieux
we can't see which EventList you're listening to with your ListEventListener in your example code, but it would be more robust to avoid referring to masterListSorted directly in your listener, and instead use

listChanges.getSourceList().

It's more clear in the code that you're intending to read from the source of the changes (whatever kind of EventList that might be), rather than a specific list referenced in a member variable.

James

On Fri, Feb 22, 2013 at 12:16 PM, Clayton Carter <[hidden email]> wrote:

What is the recommended way for dealing with editing a cell in a table row which results in the the row/Object not matching the FilteredList displayed in the table?  Specifically if the edited Object needs to be further processed in some way?

For context: I have a database, read through an ORM layer, which returns a list of Objects which are then filtered, sorted and displayed in the table.  The table displays a subset of the Object properties, with a "details" panel displaying the rest.  I turned on cell editing today (by implementing WritableTableFormat) which is working (updating in UI and db) when sort/filter is not affected, and I have it working if the change affects sort order by using

masterListSorted.setMode(SortedList.AVOID_MOVING_ELEMENTS);

and I'm monitoring for changes with ListEventListener, checking as follows:

public void listChanged( ListEvent listChanges ) {

      Object source = listChanges.getSource();

      if ( source == masterListSorted ) {
        if ( masterListSorted.size() > 0 ) {
          listChanges.next();
          if ( listChanges.getType() == ListEvent.UPDATE )
            updateRecordInDB( masterListSorted.get( listChanges.getIndex() ));
        }
      }
}

I'm using getIndex() which of course is wrong after the list is sorted or the filtered list changed.  Perhaps I'm misreading the API, but is getIndex() really the closest I can get to finding out which specific Object was changed?  Any suggestions for a more robust technique?

Thank you,
Clayton



Reply | Threaded
Open this post in threaded view
|

Re: WritableTableFormat + FilteredList

Clayton Carter-2

Thank you, James.  This and a brief walk cleared out my head and I realized that I was listening to events on the wrong list.  I switched things to the BasicEventList upon which the FilteredList and SortedList is based and it all worked out.

Thank you once again,
Clayton



On Fri, Feb 22, 2013 at 6:20 PM, James Lemieux <[hidden email]> wrote:
we can't see which EventList you're listening to with your ListEventListener in your example code, but it would be more robust to avoid referring to masterListSorted directly in your listener, and instead use

listChanges.getSourceList().

It's more clear in the code that you're intending to read from the source of the changes (whatever kind of EventList that might be), rather than a specific list referenced in a member variable.

James


On Fri, Feb 22, 2013 at 12:16 PM, Clayton Carter <[hidden email]> wrote:

What is the recommended way for dealing with editing a cell in a table row which results in the the row/Object not matching the FilteredList displayed in the table?  Specifically if the edited Object needs to be further processed in some way?

For context: I have a database, read through an ORM layer, which returns a list of Objects which are then filtered, sorted and displayed in the table.  The table displays a subset of the Object properties, with a "details" panel displaying the rest.  I turned on cell editing today (by implementing WritableTableFormat) which is working (updating in UI and db) when sort/filter is not affected, and I have it working if the change affects sort order by using

masterListSorted.setMode(SortedList.AVOID_MOVING_ELEMENTS);

and I'm monitoring for changes with ListEventListener, checking as follows:

public void listChanged( ListEvent listChanges ) {

      Object source = listChanges.getSource();

      if ( source == masterListSorted ) {
        if ( masterListSorted.size() > 0 ) {
          listChanges.next();
          if ( listChanges.getType() == ListEvent.UPDATE )
            updateRecordInDB( masterListSorted.get( listChanges.getIndex() ));
        }
      }
}

I'm using getIndex() which of course is wrong after the list is sorted or the filtered list changed.  Perhaps I'm misreading the API, but is getIndex() really the closest I can get to finding out which specific Object was changed?  Any suggestions for a more robust technique?

Thank you,
Clayton