org.eclipse.jpt.utility.model.event
Class ListChangeEvent

java.lang.Object
  extended by java.util.EventObject
      extended by org.eclipse.jpt.utility.model.event.ChangeEvent
          extended by org.eclipse.jpt.utility.model.event.ListChangeEvent
All Implemented Interfaces:
java.io.Serializable

public class ListChangeEvent
extends ChangeEvent

A "list change" event gets delivered whenever a model changes a "bound" or "constrained" list. A ListChangeEvent is sent as an argument to the ListChangeListener. Normally a ListChangeEvent is accompanied by the list name, the items that were added to or removed from the changed list, and the index of where the items are or were in the list. Design options: - create a list to wrap a single added or removed item (this is the option we implemented below and in collaborating code) since there is no way to optimize downstream code for single items, we take another performance hit by building a list each time (@see Collections#singletonList(Object)) and forcing downstream code to use a list iterator every time - fire a separate event for each item added or removed eliminates any potential for optimizations to downstream code - add protocol to support both single items and collections adds conditional logic to downstream code Provisional API: This class is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.

See Also:
Serialized Form

Constructor Summary
ListChangeEvent(Model source, java.lang.String listName)
          Construct a new list change event.
ListChangeEvent(Model source, java.lang.String listName, int targetIndex, int sourceIndex, int length)
          Construct a new list change event for a list of moved items.
ListChangeEvent(Model source, java.lang.String listName, int index, java.util.List<?> items)
          Construct a new list change event for a list of added or removed items.
ListChangeEvent(Model source, java.lang.String listName, int index, java.util.List<?> items, java.util.List<?> replacedItems)
          Construct a new list change event for a list of replaced items.
 
Method Summary
 ListChangeEvent cloneWithSource(Model newSource)
          Return a copy of the event with the specified source replacing the current source.
 ListChangeEvent cloneWithSource(Model newSource, java.lang.String newListName)
          Return a copy of the event with the specified source and list name replacing the current source and list name.
 ListChangeEvent cloneWithSource(Model newSource, java.lang.String newListName, int offset)
          Return a copy of the event with the specified source and list name replacing the current source and list name and displacing the index by the specified amount.
 java.lang.String getAspectName()
          Return the name of the aspect of the source that changed.
 int getIndex()
          Return the index at which the items were added to, removed from, or replaced in the list.
 java.lang.String getListName()
          Return the programmatic name of the list that was changed.
 int getMoveLength()
          In the case of "moved" items, this will be the number of items moved.
 int getSourceIndex()
          In the case of "moved" items, this will be the "source" index.
 int getTargetIndex()
          In the case of "moved" items, this will be the "target" index.
 java.util.ListIterator<?> items()
          Return a list iterator on the items that were added to or removed from the list.
 int itemsSize()
          Return the number of items that were added to, removed from, or replaced in the list.
 java.util.ListIterator<?> replacedItems()
          Return a list iterator on the items in the list that were replaced.
 
Methods inherited from class org.eclipse.jpt.utility.model.event.ChangeEvent
getSource, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListChangeEvent

public ListChangeEvent(Model source,
                       java.lang.String listName,
                       int index,
                       java.util.List<?> items,
                       java.util.List<?> replacedItems)
Construct a new list change event for a list of replaced items.

Parameters:
source - The object on which the event initially occurred.
listName - The programmatic name of the list that was changed.
index - The index at which the items in the list were replaced.
items - The new items in the list.
replacedItems - The items in the list that were replaced.

ListChangeEvent

public ListChangeEvent(Model source,
                       java.lang.String listName,
                       int index,
                       java.util.List<?> items)
Construct a new list change event for a list of added or removed items.

Parameters:
source - The object on which the event initially occurred.
listName - The programmatic name of the list that was changed.
index - The index at which the items were added to or removed from the list.
items - The items that were added to or removed from the list.

ListChangeEvent

public ListChangeEvent(Model source,
                       java.lang.String listName,
                       int targetIndex,
                       int sourceIndex,
                       int length)
Construct a new list change event for a list of moved items.

Parameters:
source - The object on which the event initially occurred.
listName - The programmatic name of the list that was changed.
targetIndex - The index to which the items were moved.
sourceIndex - The index from which the items were moved.

ListChangeEvent

public ListChangeEvent(Model source,
                       java.lang.String listName)
Construct a new list change event.

Parameters:
source - The object on which the event initially occurred.
listName - The programmatic name of the list that was changed.
Method Detail

getListName

public java.lang.String getListName()
Return the programmatic name of the list that was changed.


getAspectName

public java.lang.String getAspectName()
Description copied from class: ChangeEvent
Return the name of the aspect of the source that changed. May be null if inappropriate.

Specified by:
getAspectName in class ChangeEvent

getIndex

public int getIndex()
Return the index at which the items were added to, removed from, or replaced in the list. In the case of "moved" items, this will be the "target" index. May be -1 if inappropriate or unknown.


items

public java.util.ListIterator<?> items()
Return a list iterator on the items that were added to or removed from the list. In the case of "replaced" items, these are the new items in the list. May be empty if inappropriate or unknown.


itemsSize

public int itemsSize()
Return the number of items that were added to, removed from, or replaced in the list. May be 0 if inappropriate or unknown.


replacedItems

public java.util.ListIterator<?> replacedItems()
Return a list iterator on the items in the list that were replaced. May be empty if inappropriate or unknown.


getTargetIndex

public int getTargetIndex()
In the case of "moved" items, this will be the "target" index. May be -1 if inappropriate or unknown.


getSourceIndex

public int getSourceIndex()
In the case of "moved" items, this will be the "source" index. May be -1 if inappropriate or unknown.


getMoveLength

public int getMoveLength()
In the case of "moved" items, this will be the number of items moved. May be -1 if inappropriate or unknown.


cloneWithSource

public ListChangeEvent cloneWithSource(Model newSource)
Return a copy of the event with the specified source replacing the current source.

Specified by:
cloneWithSource in class ChangeEvent

cloneWithSource

public ListChangeEvent cloneWithSource(Model newSource,
                                       java.lang.String newListName)
Return a copy of the event with the specified source and list name replacing the current source and list name.


cloneWithSource

public ListChangeEvent cloneWithSource(Model newSource,
                                       java.lang.String newListName,
                                       int offset)
Return a copy of the event with the specified source and list name replacing the current source and list name and displacing the index by the specified amount.