JIDE 3.5.15

com.jidesoft.grid
Class CompoundTableModelEvent

java.lang.Object
  extended by java.util.EventObject
      extended by javax.swing.event.TableModelEvent
          extended by com.jidesoft.grid.CompoundTableModelEvent
All Implemented Interfaces:
Serializable

public class CompoundTableModelEvent
extends TableModelEvent

This is a subclass of TableModelEvent. Inside this event, there could be more than one child event.

We introduce this event to handle some duplicated scenario which is hard to fire one single event. For example, if a sorted SortableTableModel receives a row updated event from its underlying table model, the updated row could change its position. In this case, SortableTable needs to get a tableRowsDeleted event for the original position and another tableRowsInserted event for the updated position. However, it's not appropriate to fire two separate events for one action. It will also impact the performance if we simply fire tableDataChanged event. That's why we introduce this class.

Another advantage for CompoundTableModelEvent is that, by invoking CompoundTableModelEvent#getOriginalEvent(), you could now get if the table model event is triggered by the real data modification in the original table model level or it's simply triggered by actions like sorting/filtering/grouping.

If JIDE fires this CompoundTableModelEvent with two or more child events embedded in. The event itself will represent as a tableDataChanged event. That means, if you don't try to distinguish it with regular TableModelEvents, it will fall into the branch you handle tableDataChanged event. However, it doesn't mean that CompoundTableModelEvent has to be a tableDataChanged event. You could fire whichever event you want following the instruction of TableModelEvent.

You could invoke getEvents() to get the embedded child events inside the event. The order of those child events inside the CompoundTableModelEvent matters. The listener is expected to handle the embedded events one by one. For example, if a CompoundTableModelEvent contains two events, the first one is row insertion at 2 while the other one is row deletion at 5, you need insert first then delete. Otherwise, you may get a wrong result.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.event.TableModelEvent
ALL_COLUMNS, column, DELETE, firstRow, HEADER_ROW, INSERT, lastRow, type, UPDATE
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
CompoundTableModelEvent(TableModel source)
           
CompoundTableModelEvent(TableModel source, int row)
           
CompoundTableModelEvent(TableModel source, int firstRow, int lastRow)
           
CompoundTableModelEvent(TableModel source, int firstRow, int lastRow, int column)
           
CompoundTableModelEvent(TableModel source, int firstRow, int lastRow, int column, int type)
           
 
Method Summary
 void addEvent(int index, TableModelEvent event)
          Adds a new child event in designated position.
 void addEvent(TableModelEvent event)
          Adds a new child event to the end.
static void fireTableModelEvent(AbstractTableModel tableModel, TableModelEvent e)
          Fires a table model event.
 TableModelEvent[] getEvents()
          Gets all child events of this CompoundTableModelEvent.
 TableModelEvent getOriginalEvent()
          Gets the original event from received table model event.
 boolean isDebug()
          Gets the flag indicating if the event is in debug mode.
 boolean isOriginalChanged()
          Gets the flag indicating if the original table model is changed or not which causes this event.
protected  String printDebugInfo()
          Prints debug information to a string.
 void removeEvent(int index)
          Removes the event at a position
 void setDebug(boolean debug)
          Sets the flag indicating if the event is in debug mode.
 void setOriginalEvent(TableModelEvent originalEvent)
          Sets the original event from received table model event.
 
Methods inherited from class javax.swing.event.TableModelEvent
getColumn, getFirstRow, getLastRow, getType
 
Methods inherited from class java.util.EventObject
getSource, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompoundTableModelEvent

public CompoundTableModelEvent(TableModel source)

CompoundTableModelEvent

public CompoundTableModelEvent(TableModel source,
                               int row)

CompoundTableModelEvent

public CompoundTableModelEvent(TableModel source,
                               int firstRow,
                               int lastRow)

CompoundTableModelEvent

public CompoundTableModelEvent(TableModel source,
                               int firstRow,
                               int lastRow,
                               int column)

CompoundTableModelEvent

public CompoundTableModelEvent(TableModel source,
                               int firstRow,
                               int lastRow,
                               int column,
                               int type)
Method Detail

addEvent

public void addEvent(TableModelEvent event)
Adds a new child event to the end.

Parameters:
event - the child event to be added

addEvent

public void addEvent(int index,
                     TableModelEvent event)
Adds a new child event in designated position.

Parameters:
index - the event index
event - the child event to be added

removeEvent

public void removeEvent(int index)
Removes the event at a position

Parameters:
index - the event index to be removed

getEvents

public TableModelEvent[] getEvents()
Gets all child events of this CompoundTableModelEvent.

Returns:
the child event array. An empty array if no child event presented.

printDebugInfo

protected String printDebugInfo()
Prints debug information to a string.

Returns:
the debug information string

fireTableModelEvent

public static void fireTableModelEvent(AbstractTableModel tableModel,
                                       TableModelEvent e)
Fires a table model event.

This is a utility method to make sure JIDE will neither fire a CompoundTableModelEvent with less than two child events nor a CompoundTableModelEvent with a table structure or data changed child event embedded.

Parameters:
tableModel - the table model to fire table model event
e - the table model event to be fired

isOriginalChanged

public boolean isOriginalChanged()
Gets the flag indicating if the original table model is changed or not which causes this event.

If JIDE table model wrappers receives a table model event from the original table model, JIDE will fire this event with this flag as true. If JIDE is doing operations like sorting, filtering, changing pages, grouping, aggregating, JIDE will fire an event with this flag as false.

This flag will give table an information about if the original table model is able to be trusted. For example, JIDE will save selections before processing a table model event and load saved selections back after processing the event. JIDE will be able to perform the load operations based on the row index of original table model if this flag is false.

To be safe, you'd better consider original table model NOT changed only if the event is a CompoundTableModelEvent instance and isOriginalChanged() returns false.

Returns:
true if original table model is changed. Otherwise false.

getOriginalEvent

public TableModelEvent getOriginalEvent()
Gets the original event from received table model event.

Returns:
the original event
See Also:
setOriginalEvent(javax.swing.event.TableModelEvent)

setOriginalEvent

public void setOriginalEvent(TableModelEvent originalEvent)
Sets the original event from received table model event.

To let the table better handle the CompoundTableModelEvent, it will contains an original event fired from the original table model if this event is triggered by the original table model. If this event is triggered by paging, sorting, filtering, grouping without any change to the original table model, this field should be null.

Parameters:
originalEvent - the original event

isDebug

public boolean isDebug()
Gets the flag indicating if the event is in debug mode.

Returns:
true if debug mode is on. Otherwise false.
See Also:
setDebug(boolean)

setDebug

public void setDebug(boolean debug)
Sets the flag indicating if the event is in debug mode.

JIDE will record the stack information where adds the event, which will help debug in future trouble shooting. By default, this flag is false.

Parameters:
debug - the flag

JIDE 3.5.15