java.lang.Object
com.iamsoft.util.ui.swing.AbstractRearrangeableTreeModel
- All Implemented Interfaces:
RearrangeableTreeModel,TreeModel
- Direct Known Subclasses:
DefaultRearrangeableTreeModel
public abstract class AbstractRearrangeableTreeModel
extends Object
implements RearrangeableTreeModel
Basically just a wrapper for an existing tree model. The 'canX' methods of the
RearrangeableTreeModel interface are implemented to permit all reasonable
node movements. Implementation of node removal/addition methods are left to the subclass.
Many events may be fired in the course of a single operation. Tries to move nodes in
batches to minimize number of events. Will not work if duplicate tree paths exist.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumPromote/demote.static enumprotected static enumNested classes/interfaces inherited from interface com.iamsoft.util.ui.swing.RearrangeableTreeModel
RearrangeableTreeModel.IllegalNodeMoveException -
Constructor Summary
ConstructorsConstructorDescriptionAbstractRearrangeableTreeModel(TreeModel pModel, AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTreeModelListener(TreeModelListener pListener) booleancanDemote(Collection<TreePath> pPaths) True as long as a sibling exists above each selected node and !pPaths.isEmpty().booleancanMoveDown(Collection<TreePath> pPaths) True as long as a sibling exists below each selected node and !pPaths.isEmpty().booleancanMoveUp(Collection<TreePath> pPaths) True as long as a sibling exists above each selected node and !pPaths.isEmpty().booleancanPromote(Collection<TreePath> pPaths) True if !pPaths.isEmpty() and root and its direct descendents are not selected.voiddemote(Collection<TreePath> pPaths) Move nodes one level further from the root.protected TreePathfindNewPath(TreePath pPath) Identify new path by seeing if argument path starts with a path that exists in old to new path map.intgetChildCount(Object pParent) intgetIndexOfChild(Object pParent, Object pChild) protected TreeModelgetModel()Map from original to new path for elements that were moved.getRoot()protected abstract voidinsertNodes(TreePath pParentPath, Collection<Object> pNodes, int pIdx) Used by rearrangement methods to shuffle nodes around.booleanprotected voidmove(Collection<TreePath> pPaths, AbstractRearrangeableTreeModel.HorizontalDirection pDir) Promote or demote.protected voidmove(Collection<TreePath> pPaths, AbstractRearrangeableTreeModel.VerticalDirection pDir) Move up or down.voidmoveDown(Collection<TreePath> pPaths) Move nodes one space lower (swap with successors).voidmoveUp(Collection<TreePath> pPaths) Move nodes one space higher (swap with predecessors).voidpromote(Collection<TreePath> pPaths) Moves shallowest nodes first.protected abstract voidremoveNodes(TreePath pParentPath, Map<Integer, Object> pNodes) Used by rearrangement methods to shuffle nodes around.voidremoveTreeModelListener(TreeModelListener pListener) protected voidsetPromotionBehavior(AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior) voidvalueForPathChanged(TreePath pPath, Object pNewValue)
-
Constructor Details
-
AbstractRearrangeableTreeModel
-
AbstractRearrangeableTreeModel
public AbstractRearrangeableTreeModel(TreeModel pModel, AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior)
-
-
Method Details
-
getModel
-
getOldToNewPaths
Map from original to new path for elements that were moved. -
getPromotionBehavior
-
setPromotionBehavior
protected void setPromotionBehavior(AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior) -
addTreeModelListener
- Specified by:
addTreeModelListenerin interfaceTreeModel
-
removeTreeModelListener
- Specified by:
removeTreeModelListenerin interfaceTreeModel
-
getChild
-
getChildCount
- Specified by:
getChildCountin interfaceTreeModel
-
getIndexOfChild
- Specified by:
getIndexOfChildin interfaceTreeModel
-
getRoot
-
isLeaf
-
valueForPathChanged
- Specified by:
valueForPathChangedin interfaceTreeModel
-
canPromote
True if !pPaths.isEmpty() and root and its direct descendents are not selected. False if pPaths is null.- Specified by:
canPromotein interfaceRearrangeableTreeModel
-
canDemote
True as long as a sibling exists above each selected node and !pPaths.isEmpty(). Defined separately from 'canMoveUp' so as to avoid overriding issues. False if pPaths is null.- Specified by:
canDemotein interfaceRearrangeableTreeModel
-
canMoveUp
True as long as a sibling exists above each selected node and !pPaths.isEmpty(). Defined separately from 'canDemote' so as to avoid overrinding issues. False if pPaths is null.- Specified by:
canMoveUpin interfaceRearrangeableTreeModel
-
canMoveDown
True as long as a sibling exists below each selected node and !pPaths.isEmpty(). False if pPaths is null.- Specified by:
canMoveDownin interfaceRearrangeableTreeModel
-
insertNodes
protected abstract void insertNodes(TreePath pParentPath, Collection<Object> pNodes, int pIdx) throws RearrangeableTreeModel.IllegalNodeMoveException Used by rearrangement methods to shuffle nodes around. If rearrangement methods are overridden, a blank implementation will suffice. Implementation may choose to ignore pIdx- Parameters:
pParentPath- Path to parent of nodes to be inserted.pNodes- Nodes to be appended (in order).pIdx- Index of insertion. May be ignored if model wishes to impose its own node ordering strategy.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException- See Also:
-
removeNodes
protected abstract void removeNodes(TreePath pParentPath, Map<Integer, Object> pNodes) throws RearrangeableTreeModel.IllegalNodeMoveExceptionUsed by rearrangement methods to shuffle nodes around. If rearrangement methods are overridden, a blank implementation will suffice. pNodes is guaranteed to be sorted in such a way that ordered removal should succeed. That is, indices are in descending order.- Parameters:
pParentPath- Path to parent of nodes to be inserted.pNodes- Map from desired insertion index to node object.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException- See Also:
-
promote
public void promote(Collection<TreePath> pPaths) throws RearrangeableTreeModel.IllegalNodeMoveException Moves shallowest nodes first.- Specified by:
promotein interfaceRearrangeableTreeModel- Parameters:
pPaths- Paths to be moved.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException
-
demote
public void demote(Collection<TreePath> pPaths) throws RearrangeableTreeModel.IllegalNodeMoveException Description copied from interface:RearrangeableTreeModelMove nodes one level further from the root. If pPaths includes both a path and a sub-path, the former promotion occurs first.- Specified by:
demotein interfaceRearrangeableTreeModel- Parameters:
pPaths- Paths to be moved.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException
-
move
protected void move(Collection<TreePath> pPaths, AbstractRearrangeableTreeModel.HorizontalDirection pDir) throws RearrangeableTreeModel.IllegalNodeMoveException Promote or demote. -
move
protected void move(Collection<TreePath> pPaths, AbstractRearrangeableTreeModel.VerticalDirection pDir) throws RearrangeableTreeModel.IllegalNodeMoveException Move up or down. -
moveDown
public void moveDown(Collection<TreePath> pPaths) throws RearrangeableTreeModel.IllegalNodeMoveException Description copied from interface:RearrangeableTreeModelMove nodes one space lower (swap with successors).- Specified by:
moveDownin interfaceRearrangeableTreeModel- Parameters:
pPaths- Paths to be moved.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException
-
moveUp
public void moveUp(Collection<TreePath> pPaths) throws RearrangeableTreeModel.IllegalNodeMoveException Description copied from interface:RearrangeableTreeModelMove nodes one space higher (swap with predecessors).- Specified by:
moveUpin interfaceRearrangeableTreeModel- Parameters:
pPaths- Paths to be moved.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException
-
findNewPath
Identify new path by seeing if argument path starts with a path that exists in old to new path map. If not, the original (argument) path is returned.
-