org.browsecode.helpers.reorderablelistpanel
Interface ReorderableListModel<E>

All Known Subinterfaces:
AuxillaryQuestionPartSet, ChoicesDataBitSet, Page, Survey
All Known Implementing Classes:
AuxillaryQuestionPartSetSQL, AuxillaryQuestionPartSetTable, ChoicesDataBitSetSQL, PageSQL, PageTable, ReorderableListModelWithOrderIndexStub, SurveyTable

public interface ReorderableListModel<E>

ReorderableListModel is a data model of a list of items that can be manipulated in a variety of ways, specifically aimed for a GUI that allows reordering, creating, and deleting items. It will have the following features: 1) Handle list actions – create items in the list, remove items in the list. 1.newItem() returns a new ReorderableListItem that can be inserted into anywhere in the list. 2.deleteItem(ReorderableListItem, int oldIndex) deletes the item from the list. 2) Allow listeners, ReorderableListListener which can listen for: 1.Any changes (and must know what the change is or what the change's source was) 3) It can return the list of items in a List<ReorderableListItem>. Each item is a ReorderableListItem. 1.Each item should have a renderer that can be referred to for getting the item out of the list into a GUI. This is a different interface, ReorderableListItemRenderer (extends JComponent). In general, the GUI should not actually move/delete/insert anything on its own. It should only issue the move/delete/insert command to this model and then wait until it gets an event via ReorderableChangeListener. That way, if there's a bug in this model for some reason and the operation can't be done, the operation can be cancelled. (Whether the operation worked is duplicated in the return of each move method -- so theoretically you could use that, but it won't be quite as clean).


Field Summary
static int INSERTED_FROM_DELETED_HERE
          When you've deleted a object from this list, and are inserting it back into this list, pass INSERTED_FROM_DELETED_HERE into itemMovedToIndex() as the second parameter -- oldIndexInThisList.
static int INSERTED_FROM_ELSEWHERE
           
 
Method Summary
 void addReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)
           
 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.
 int getItemCount()
           
 E insertNewItemAt(int indexAt)
          Creates a new item for the list and puts it into the index that it's listed as.
 java.util.Iterator<E> iterator()
          Get the items.
 boolean moveItemElsewhere(E item, int oldIndex)
          Removed means it was moved to somewhere else, NOT deleted.
 boolean moveItemToIndex(E item, java.lang.Integer oldIndexInThisList, int newIndex)
          Items are moved around in the list, or added to the list this way, too.
 void removeReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)
           
 

Field Detail

INSERTED_FROM_ELSEWHERE

static final int INSERTED_FROM_ELSEWHERE
See Also:
Constant Field Values

INSERTED_FROM_DELETED_HERE

static final int INSERTED_FROM_DELETED_HERE
When you've deleted a object from this list, and are inserting it back into this list, pass INSERTED_FROM_DELETED_HERE into itemMovedToIndex() as the second parameter -- oldIndexInThisList. Then it will pull it out of the deleted list.

See Also:
Constant Field Values
Method Detail

moveItemToIndex

boolean moveItemToIndex(E item,
                        java.lang.Integer oldIndexInThisList,
                        int newIndex)
Items are moved around in the list, or added to the list this way, too.

Parameters:
item -
oldIndexInThisList - 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.

canItemBeMovedElsewhere

boolean canItemBeMovedElsewhere()
Removed means can it be moved to somewhere else, NOT deleted -- it must always be deletable.

Returns:
whether or not this item can be moved to another location. False if it cannot be moved to another location.

moveItemElsewhere

boolean moveItemElsewhere(E item,
                          int oldIndex)
Removed means it was moved to somewhere else, NOT deleted.

Parameters:
item -
oldIndex -
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.

deleteItem

boolean deleteItem(E item,
                   int oldIndex)
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);

Parameters:
item -
oldIndex -
Returns:
true if it worked, false if it did not work.

insertNewItemAt

E insertNewItemAt(int indexAt)
Creates a new item for the list and puts it into the index that it's listed as.

Parameters:
indexAt -
Returns:
the object if it made a new one, and null if it failed to make a new one.

iterator

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

Returns:

getItemCount

int getItemCount()

addReorderableChangeListener

void addReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)

removeReorderableChangeListener

void removeReorderableChangeListener(ReorderableChangeListener<E> reorderableChangeListener)
Parameters:
reorderableChangeListener - the ReorderableChangeListener to remove