org.browsecode.helpers.reorderablelistpanel
Class ReorderableListModelWithOrderIndexStub<E>

java.lang.Object
  extended by org.browsecode.helpers.reorderablelistpanel.ReorderableListModelWithOrderIndexStub<E>
All Implemented Interfaces:
ReorderableListModel<E>
Direct Known Subclasses:
AuxillaryQuestionPartSetTable, ChoicesDataBitSetSQL, PageTable, SurveyTable

public class ReorderableListModelWithOrderIndexStub<E>
extends java.lang.Object
implements ReorderableListModel<E>

A stub for making a ReorderableListModel which has a IntegerDataBit for the OrderIndex -- i.e. this uses the ReorderableObject interface to keep track of the items in the list. The OrderIndex is a number which duplicates the place in the list where the data is. First, implement ReorderableObject for your object -- this has both the item and a reference to it's OrderIndex. Also supports undo (in progress!)


Nested Class Summary
static interface ReorderableListModelWithOrderIndexStub.ReorderableObject<E2>
           
 
Field Summary
static java.lang.String ABSTRACTION_ERROR
           
protected  java.util.Vector<javax.swing.event.UndoableEditListener> undoableEditListeners
           
 
Fields inherited from interface org.browsecode.helpers.reorderablelistpanel.ReorderableListModel
INSERTED_FROM_DELETED_HERE, INSERTED_FROM_ELSEWHERE
 
Constructor Summary
ReorderableListModelWithOrderIndexStub()
           
 
Method Summary
 void addReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)
           
 void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
          Registers the given observer to begin receiving notifications when undoable edits are made to the document.
 boolean canItemBeMovedElsewhere()
          Removed means can it be moved to somewhere else, NOT deleted -- it must always be deletable.
 boolean deleteItem(E item, int oldIndex)
          Call this when an item has been deleted.
protected  void deleteItem(ReorderableListModelWithOrderIndexStub.ReorderableObject<E> justDeleted)
          If an object is deleted from the list, this method is fired and should be used to keep track of which items should not be saved anymore and deleted when this set is saved.
protected  boolean deleteItemProtected(E item, int oldIndex, boolean fireUndoableEdit)
           
 void fireUndoableEdit(ReorderableListModelWithOrderIndexStub fireOn, javax.swing.undo.UndoableEdit edit)
          For other classes that want to use the same list of undoableEditListeners.
protected  void fireUndoableEdit(javax.swing.undo.UndoableEdit edit)
           
protected  boolean getHasBeenChanged()
           
 int getItemCount()
           
protected  java.lang.String getItemsName()
          For undos and presentation names -- so we can say what we're moving/deleting/inserting
protected  java.util.Vector<ReorderableListModelWithOrderIndexStub.ReorderableObject<E>> getItemsVector()
          Should return a non-cloned version of the list of items -- the vector will be changed to reflect the order, etc.
protected  E getNewItem()
          Creates a new item for the list, but does not insert it into the list.
protected  ReorderableListModelWithOrderIndexStub.ReorderableObject<E> getNewItem(int indexAt)
          Should not insert item, but should get a new one and return it.
protected  ReorderableListModelWithOrderIndexStub.ReorderableObject<E> getReorderableObjectFor(E reorderableItem)
           
protected  java.util.Vector<E> getVectorOfReorderableItems()
          This may be wrong for your class, if your ReorderableListItem is not the item itself.
 E insertNewItemAt(int indexAt)
          Creates a new item for the list and puts it into the index that it's listed as.
protected  E insertNewItemAtProtected(ReorderableListModelWithOrderIndexStub.ReorderableObject<E> item, int indexAt, boolean fireUndoableEdit)
           
 java.util.Iterator<E> iterator()
          Get the items.
 boolean moveItemElsewhere(E item, int oldIndex)
          Removed means it was moved to somewhere else, NOT deleted.
protected  boolean moveItemElsewhereProtected(E item, int oldIndex, boolean fireUndoableEdit)
           
 boolean moveItemToIndex(E item, java.lang.Integer oldIndex, int newIndex)
          Items are moved around in the list, or added to the list this way, too.
protected  boolean moveItemToIndexProtected(E item, java.lang.Integer oldIndex, int newIndex, boolean fireUndoableEdit)
           
 void removeReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)
           
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
          Unregisters the given observer from the notification list so it will no longer receive updates.
protected  void resetHasBeenChanged()
           
protected  void setCachedReorderableItems(java.util.Vector<E> cache)
           
 boolean shouldFireUndoableEdits()
          Also public for other classes that want to use the same list of undoableEditListeners.
protected  boolean undeleteItem(ReorderableListModelWithOrderIndexStub.ReorderableObject<E> aboutToUndelete)
          Undelete an item that was just deleted using deleteItem().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ABSTRACTION_ERROR

public static java.lang.String ABSTRACTION_ERROR

undoableEditListeners

protected java.util.Vector<javax.swing.event.UndoableEditListener> undoableEditListeners
Constructor Detail

ReorderableListModelWithOrderIndexStub

public ReorderableListModelWithOrderIndexStub()
Method Detail

getItemsVector

protected java.util.Vector<ReorderableListModelWithOrderIndexStub.ReorderableObject<E>> getItemsVector()
Should return a non-cloned version of the list of items -- the vector will be changed to reflect the order, etc.

Returns:
Vector

getItemsName

protected java.lang.String getItemsName()
For undos and presentation names -- so we can say what we're moving/deleting/inserting


deleteItem

protected void deleteItem(ReorderableListModelWithOrderIndexStub.ReorderableObject<E> justDeleted)
If an object is deleted from the list, this method is fired and should be used to keep track of which items should not be saved anymore and deleted when this set is saved.

Parameters:
justDeleted -

undeleteItem

protected boolean undeleteItem(ReorderableListModelWithOrderIndexStub.ReorderableObject<E> aboutToUndelete)
Undelete an item that was just deleted using deleteItem(). Return true if it works and is implemented, return false if it doesn't work or isn't implemented. Implemented for now as a convenience to those who

Parameters:
justUndeleted -

moveItemToIndex

public boolean moveItemToIndex(E item,
                               java.lang.Integer oldIndex,
                               int newIndex)
Description copied from interface: ReorderableListModel
Items are moved around in the list, or added to the list this way, too.

Specified by:
moveItemToIndex in interface ReorderableListModel<E>
oldIndex - The old index it had in this parent -- if it is new or dropped from another pane, oldIndex is null.
newIndex - The index it should be dropped into
Returns:
true if it worked, false if it did not work. If this returns false, the GUI is assumed to cancel the move and possibly mention the bug to the user.

moveItemToIndexProtected

protected boolean moveItemToIndexProtected(E item,
                                           java.lang.Integer oldIndex,
                                           int newIndex,
                                           boolean fireUndoableEdit)

deleteItem

public boolean deleteItem(E item,
                          int oldIndex)
Description copied from interface: ReorderableListModel
Call this when an item has been deleted. It will delete it from this list. After deleting an item, you CANNOT use it again. The only way to re-insert the same item is to call ReorderableListener.itemMovedToIndex(deletedObject, INSERTED_FROM_DELETED_HERE, newIndex);

Specified by:
deleteItem in interface ReorderableListModel<E>
Returns:
true if it worked, false if it did not work.

deleteItemProtected

protected boolean deleteItemProtected(E item,
                                      int oldIndex,
                                      boolean fireUndoableEdit)

getNewItem

protected ReorderableListModelWithOrderIndexStub.ReorderableObject<E> getNewItem(int indexAt)
Should not insert item, but should get a new one and return it. The item made with this will not necessarily be inserted, and even if it is, it might be inserted into another ReorderableSQLSet. This can be overrided if an item created at a parti


getNewItem

protected E getNewItem()
Creates a new item for the list, but does not insert it into the list. Required for getNewItem(int), which does the job correctly if you implement this.;

Returns:

insertNewItemAt

public E insertNewItemAt(int indexAt)
Description copied from interface: ReorderableListModel
Creates a new item for the list and puts it into the index that it's listed as.

Specified by:
insertNewItemAt in interface ReorderableListModel<E>
Returns:
the object if it made a new one, and null if it failed to make a new one.

insertNewItemAtProtected

protected E insertNewItemAtProtected(ReorderableListModelWithOrderIndexStub.ReorderableObject<E> item,
                                     int indexAt,
                                     boolean fireUndoableEdit)

canItemBeMovedElsewhere

public boolean canItemBeMovedElsewhere()
Description copied from interface: ReorderableListModel
Removed means can it be moved to somewhere else, NOT deleted -- it must always be deletable.

Specified by:
canItemBeMovedElsewhere in interface ReorderableListModel<E>
Returns:
whether or not this item can be moved to another location. False if it cannot be moved to another location.

moveItemElsewhere

public boolean moveItemElsewhere(E item,
                                 int oldIndex)
Description copied from interface: ReorderableListModel
Removed means it was moved to somewhere else, NOT deleted.

Specified by:
moveItemElsewhere in interface ReorderableListModel<E>
Returns:
true if it happened, false if it did not happen. If this returns false, it either means that (a) canItemBeMovedElsewhere() should have been called, and it would return false, or (b) if canItemBeMovedElsewhere() returned true, then the call didn't work.

moveItemElsewhereProtected

protected boolean moveItemElsewhereProtected(E item,
                                             int oldIndex,
                                             boolean fireUndoableEdit)

iterator

public java.util.Iterator<E> iterator()
Description copied from interface: ReorderableListModel
Get the items. Primarily to be used for rendering the list of items, using a ReorderableListItemRenderer. Each item in the list will be

Specified by:
iterator in interface ReorderableListModel<E>
Returns:

getItemCount

public int getItemCount()
Specified by:
getItemCount in interface ReorderableListModel<E>

addReorderableChangeListener

public void addReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)
Specified by:
addReorderableChangeListener in interface ReorderableListModel<E>

removeReorderableChangeListener

public void removeReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)
Specified by:
removeReorderableChangeListener in interface ReorderableListModel<E>
Parameters:
reorderableChangeListener - the ReorderableChangeListener to remove

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Registers the given observer to begin receiving notifications when undoable edits are made to the document.

Parameters:
listener - the observer to register
See Also:
UndoableEditEvent

removeUndoableEditListener

public void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Unregisters the given observer from the notification list so it will no longer receive updates.

Parameters:
listener - the observer to register
See Also:
UndoableEditEvent

shouldFireUndoableEdits

public boolean shouldFireUndoableEdits()
Also public for other classes that want to use the same list of undoableEditListeners.

Parameters:
fireOn -
edit -

fireUndoableEdit

protected void fireUndoableEdit(javax.swing.undo.UndoableEdit edit)

fireUndoableEdit

public void fireUndoableEdit(ReorderableListModelWithOrderIndexStub fireOn,
                             javax.swing.undo.UndoableEdit edit)
For other classes that want to use the same list of undoableEditListeners.

Parameters:
fireOn -
edit -

getHasBeenChanged

protected boolean getHasBeenChanged()

resetHasBeenChanged

protected void resetHasBeenChanged()

setCachedReorderableItems

protected void setCachedReorderableItems(java.util.Vector<E> cache)

getVectorOfReorderableItems

protected java.util.Vector<E> getVectorOfReorderableItems()
This may be wrong for your class, if your ReorderableListItem is not the item itself. You may want to override it.

Returns:

getReorderableObjectFor

protected ReorderableListModelWithOrderIndexStub.ReorderableObject<E> getReorderableObjectFor(E reorderableItem)