Class GlazedListsEventLayer<T>

Type Parameters:
T - Type of the bean in the backing list.
All Implemented Interfaces:
ca.odell.glazedlists.event.ListEventListener<T>, PropertyChangeListener, EventListener, ILayer, ILayerListener, IUniqueIndexLayer, IPersistable

public class GlazedListsEventLayer<T> extends AbstractLayerTransform implements IUniqueIndexLayer, ca.odell.glazedlists.event.ListEventListener<T>, PropertyChangeListener
This layer acts as the event listener for:
  1. GlazedLists events - ListEvent
  2. Bean updates - PropertyChangeEvent(s)
GlazedLists events are conflated at a 100ms interval i.e a single RowStructuralRefreshEvent is fired for any number of GlazedLists events received during that interval.

PropertyChangeEvent(s) are propagated immediately as a PropertyUpdateEvent.

  • Constructor Details

    • GlazedListsEventLayer

      public GlazedListsEventLayer(IUniqueIndexLayer underlyingLayer, ca.odell.glazedlists.EventList<T> eventList)
  • Method Details

    • getEventNotifier

      protected Runnable getEventNotifier()
      Returns:
      The Runnable that is triggered all 100ms to fire a NatTable refresh event.
    • listChanged

      public void listChanged(ca.odell.glazedlists.event.ListEvent<T> event)
      Specified by:
      listChanged in interface ca.odell.glazedlists.event.ListEventListener<T>
    • propertyChange

      public void propertyChange(PropertyChangeEvent event)
      Specified by:
      propertyChange in interface PropertyChangeListener
    • fireEventFromSWTDisplayThread

      protected void fireEventFromSWTDisplayThread(ILayerEvent event)
      Fires the given ILayerEvent on the SWT Display thread in case testMode is false. Needed because the GlazedLists list change handling is done in a background thread, but NatTable event handling needs to be triggered in the UI thread to be able to trigger repainting.
      Parameters:
      event - The event to fire
    • doCommand

      public boolean doCommand(ILayerCommand command)
      Description copied from interface: ILayer
      Opportunity to respond to a command as it flows down the stack. If the layer is not interested in the command it should allow the command to keep traveling down the stack.

      Note: Before the layer can process a command it must convert the command to its local coordinates using ILayerCommand.convertToTargetLayer(ILayer)

      Specified by:
      doCommand in interface ILayer
      Overrides:
      doCommand in class AbstractLayerTransform
      Parameters:
      command - The command to execute.
      Returns:
      true if the command has been handled and was therefore consumed, false otherwise.
    • isDisposed

      public boolean isDisposed()
      Returns:
      true if this layer was terminated, false if it is still active.
    • setEventList

      public void setEventList(ca.odell.glazedlists.EventList<T> newEventList)
      Parameters:
      newEventList - the EventList to listen on.
    • setTestMode

      public void setTestMode(boolean testMode)
      Activate the test mode, which is needed for unit testing. When enabling the test mode, the events are not fired in the UI thread.
      Parameters:
      testMode - true to enable the test mode, false for real mode.
    • activate

      public void activate()
      Activates the handling of GlazedLists events. By activating on receiving GlazedLists change events, there will be NatTable events fired to indicate that re-rendering is necessary.

      This is usually necessary to perform huge updates of the data model to avoid concurrency issues. By default the GlazedListsEventLayer is activated. You can deactivate it prior performing bulk updates and activate it again after the update is finished for a better event handling.

    • deactivate

      public void deactivate()
      Deactivates the handling of GlazedLists events. By deactivating there will be no NatTable events fired on GlazedLists change events.

      This is usually necessary to perform huge updates of the data model to avoid concurrency issues. By default the GlazedListsEventLayer is activated. You can deactivate it prior performing bulk updates and activate it again after the update is finished for a better event handling.

    • isActive

      public boolean isActive()
      Returns:
      Whether this GlazedListsEventLayer will propagate ListEvents into NatTable or not.
    • discardEventsToProcess

      public void discardEventsToProcess()
      This method can be used to discard event processing.

      It is useful in cases scenarios where list changes are tracked while the handling is deactivated. By default list changes are also tracked while the handling is deactivated, so automatically a refresh is triggered on activation. For cases where a custom event is fired for updates, it could make sense to discard the events to process to avoid that a full refresh event is triggered.

      Since:
      1.6
    • getColumnPositionByIndex

      public int getColumnPositionByIndex(int columnIndex)
      Specified by:
      getColumnPositionByIndex in interface IUniqueIndexLayer
    • getRowPositionByIndex

      public int getRowPositionByIndex(int rowIndex)
      Specified by:
      getRowPositionByIndex in interface IUniqueIndexLayer