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 enum
Promote/demote.static enum
protected static enum
Nested 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 TypeMethodDescriptionvoid
addTreeModelListener
(TreeModelListener pListener) boolean
canDemote
(Collection<TreePath> pPaths) True as long as a sibling exists above each selected node and !pPaths.isEmpty().boolean
canMoveDown
(Collection<TreePath> pPaths) True as long as a sibling exists below each selected node and !pPaths.isEmpty().boolean
canMoveUp
(Collection<TreePath> pPaths) True as long as a sibling exists above each selected node and !pPaths.isEmpty().boolean
canPromote
(Collection<TreePath> pPaths) True if !pPaths.isEmpty() and root and its direct descendents are not selected.void
demote
(Collection<TreePath> pPaths) Move nodes one level further from the root.protected TreePath
findNewPath
(TreePath pPath) Identify new path by seeing if argument path starts with a path that exists in old to new path map.int
getChildCount
(Object pParent) int
getIndexOfChild
(Object pParent, Object pChild) protected TreeModel
getModel()
Map from original to new path for elements that were moved.getRoot()
protected abstract void
insertNodes
(TreePath pParentPath, Collection<Object> pNodes, int pIdx) Used by rearrangement methods to shuffle nodes around.boolean
protected void
move
(Collection<TreePath> pPaths, AbstractRearrangeableTreeModel.HorizontalDirection pDir) Promote or demote.protected void
move
(Collection<TreePath> pPaths, AbstractRearrangeableTreeModel.VerticalDirection pDir) Move up or down.void
moveDown
(Collection<TreePath> pPaths) Move nodes one space lower (swap with successors).void
moveUp
(Collection<TreePath> pPaths) Move nodes one space higher (swap with predecessors).void
promote
(Collection<TreePath> pPaths) Moves shallowest nodes first.protected abstract void
removeNodes
(TreePath pParentPath, Map<Integer, Object> pNodes) Used by rearrangement methods to shuffle nodes around.void
removeTreeModelListener
(TreeModelListener pListener) protected void
setPromotionBehavior
(AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior) void
valueForPathChanged
(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:
addTreeModelListener
in interfaceTreeModel
-
removeTreeModelListener
- Specified by:
removeTreeModelListener
in interfaceTreeModel
-
getChild
-
getChildCount
- Specified by:
getChildCount
in interfaceTreeModel
-
getIndexOfChild
- Specified by:
getIndexOfChild
in interfaceTreeModel
-
getRoot
-
isLeaf
-
valueForPathChanged
- Specified by:
valueForPathChanged
in interfaceTreeModel
-
canPromote
True if !pPaths.isEmpty() and root and its direct descendents are not selected. False if pPaths is null.- Specified by:
canPromote
in 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:
canDemote
in 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:
canMoveUp
in interfaceRearrangeableTreeModel
-
canMoveDown
True as long as a sibling exists below each selected node and !pPaths.isEmpty(). False if pPaths is null.- Specified by:
canMoveDown
in 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:
promote
in interfaceRearrangeableTreeModel
- Parameters:
pPaths
- Paths to be moved.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException
-
demote
public void demote(Collection<TreePath> pPaths) throws RearrangeableTreeModel.IllegalNodeMoveException Description copied from interface:RearrangeableTreeModel
Move nodes one level further from the root. If pPaths includes both a path and a sub-path, the former promotion occurs first.- Specified by:
demote
in 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:RearrangeableTreeModel
Move nodes one space lower (swap with successors).- Specified by:
moveDown
in interfaceRearrangeableTreeModel
- Parameters:
pPaths
- Paths to be moved.- Throws:
RearrangeableTreeModel.IllegalNodeMoveException
-
moveUp
public void moveUp(Collection<TreePath> pPaths) throws RearrangeableTreeModel.IllegalNodeMoveException Description copied from interface:RearrangeableTreeModel
Move nodes one space higher (swap with predecessors).- Specified by:
moveUp
in 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.
-