- 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 Classes Modifier and Type Class Description protected static class
AbstractRearrangeableTreeModel.HorizontalDirection
Promote/demote.static class
AbstractRearrangeableTreeModel.PromotionBehavior
protected static class
AbstractRearrangeableTreeModel.VerticalDirection
-
Nested classes/interfaces inherited from interface com.iamsoft.util.ui.swing.RearrangeableTreeModel
RearrangeableTreeModel.IllegalNodeMoveException
-
-
Constructor Summary
Constructors Constructor Description AbstractRearrangeableTreeModel(TreeModel pModel)
AbstractRearrangeableTreeModel(TreeModel pModel, AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
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.Object
getChild(Object pParent, int pIdx)
int
getChildCount(Object pParent)
int
getIndexOfChild(Object pParent, Object pChild)
protected TreeModel
getModel()
protected Map<TreePath,TreePath>
getOldToNewPaths()
Map from original to new path for elements that were moved.protected AbstractRearrangeableTreeModel.PromotionBehavior
getPromotionBehavior()
Object
getRoot()
protected abstract void
insertNodes(TreePath pParentPath, Collection<Object> pNodes, int pIdx)
Used by rearrangement methods to shuffle nodes around.boolean
isLeaf(Object pNode)
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 Detail
-
AbstractRearrangeableTreeModel
public AbstractRearrangeableTreeModel(TreeModel pModel)
-
AbstractRearrangeableTreeModel
public AbstractRearrangeableTreeModel(TreeModel pModel, AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior)
-
-
Method Detail
-
getModel
protected TreeModel getModel()
-
getOldToNewPaths
protected Map<TreePath,TreePath> getOldToNewPaths()
Map from original to new path for elements that were moved.
-
getPromotionBehavior
protected AbstractRearrangeableTreeModel.PromotionBehavior getPromotionBehavior()
-
setPromotionBehavior
protected void setPromotionBehavior(AbstractRearrangeableTreeModel.PromotionBehavior pPromotionBehavior)
-
addTreeModelListener
public void addTreeModelListener(TreeModelListener pListener)
- Specified by:
addTreeModelListener
in interfaceTreeModel
-
removeTreeModelListener
public void removeTreeModelListener(TreeModelListener pListener)
- Specified by:
removeTreeModelListener
in interfaceTreeModel
-
getChildCount
public int getChildCount(Object pParent)
- Specified by:
getChildCount
in interfaceTreeModel
-
getIndexOfChild
public int getIndexOfChild(Object pParent, Object pChild)
- Specified by:
getIndexOfChild
in interfaceTreeModel
-
valueForPathChanged
public void valueForPathChanged(TreePath pPath, Object pNewValue)
- Specified by:
valueForPathChanged
in interfaceTreeModel
-
canPromote
public boolean canPromote(Collection<TreePath> pPaths)
True if !pPaths.isEmpty() and root and its direct descendents are not selected. False if pPaths is null.- Specified by:
canPromote
in interfaceRearrangeableTreeModel
-
canDemote
public boolean canDemote(Collection<TreePath> pPaths)
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
public boolean canMoveUp(Collection<TreePath> pPaths)
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
public boolean canMoveDown(Collection<TreePath> pPaths)
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:
demote(java.util.Collection)
,promote(java.util.Collection)
,moveUp(java.util.Collection)
,moveDown(java.util.Collection)
-
removeNodes
protected abstract void removeNodes(TreePath pParentPath, Map<Integer,Object> pNodes) throws RearrangeableTreeModel.IllegalNodeMoveException
Used 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:
demote(java.util.Collection)
,promote(java.util.Collection)
,moveUp(java.util.Collection)
,moveDown(java.util.Collection)
-
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
-
-