JIDE 3.5.15

com.jidesoft.list
Class CompoundListDataEvent

java.lang.Object
  extended by java.util.EventObject
      extended by javax.swing.event.ListDataEvent
          extended by com.jidesoft.list.CompoundListDataEvent
All Implemented Interfaces:
Serializable

public class CompoundListDataEvent
extends ListDataEvent

Compound ListDataEvent to contain multiple subevents and the original event.

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

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

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

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

Since:
3.3.5
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.event.ListDataEvent
CONTENTS_CHANGED, INTERVAL_ADDED, INTERVAL_REMOVED
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
CompoundListDataEvent(Object source, int type, int index0, int index1)
          The constructor.
 
Method Summary
 void addEvent(int index, ListDataEvent event)
          Adds a new child event in designated position.
 void addEvent(ListDataEvent event)
          Adds a new child event to the end.
static void fireListDataEvent(EventFireListModel listModel, ListDataEvent e)
          Fires a list data event.
 ListDataEvent[] getEvents()
          Gets all child events of this CompoundListDataEvent.
 ListDataEvent getOriginalEvent()
          Gets the original event from received list data event.
 boolean isDebug()
          Gets the flag indicating if the event is in debug mode.
 boolean isOriginalChanged()
          Gets the flag indicating if the original list 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(ListDataEvent originalEvent)
          Sets the original event from received list data event.
 
Methods inherited from class javax.swing.event.ListDataEvent
getIndex0, getIndex1, getType, toString
 
Methods inherited from class java.util.EventObject
getSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompoundListDataEvent

public CompoundListDataEvent(Object source,
                             int type,
                             int index0,
                             int index1)
The constructor.

Parameters:
source - the list model
type - the event type
index0 - the start index
index1 - the end index
Method Detail

addEvent

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

Parameters:
event - the child event to be added

addEvent

public void addEvent(int index,
                     ListDataEvent 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 ListDataEvent[] getEvents()
Gets all child events of this CompoundListDataEvent.

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

fireListDataEvent

public static void fireListDataEvent(EventFireListModel listModel,
                                     ListDataEvent e)
Fires a list data event.

This is a utility method to fire a CompoundListDataEvent correctly.

Parameters:
listModel - the list model to fire list data event
e - the list model event to be fired

isOriginalChanged

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

If JIDE list model wrappers receives a list model event from the original list 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 list an information about if the original list model is able to be trusted. For example, JIDE will save selections before processing a list 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 list model if this flag is false.

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

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

getOriginalEvent

public ListDataEvent getOriginalEvent()
Gets the original event from received list data event.

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

setOriginalEvent

public void setOriginalEvent(ListDataEvent originalEvent)
Sets the original event from received list data event.

To let the list better handle the CompoundListDataEvent, it will contains an original event fired from the original list model if this event is triggered by the original list model. If this event is triggered by paging, sorting, filtering, grouping without any change to the original list 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