- 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 classAbstractRearrangeableTreeModel.HorizontalDirectionPromote/demote.static classAbstractRearrangeableTreeModel.PromotionBehaviorprotected static classAbstractRearrangeableTreeModel.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 voidaddTreeModelListener(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.ObjectgetChild(Object pParent, int pIdx)intgetChildCount(Object pParent)intgetIndexOfChild(Object pParent, Object pChild)protected TreeModelgetModel()protected Map<TreePath,TreePath>getOldToNewPaths()Map from original to new path for elements that were moved.protected AbstractRearrangeableTreeModel.PromotionBehaviorgetPromotionBehavior()ObjectgetRoot()protected abstract voidinsertNodes(TreePath pParentPath, Collection<Object> pNodes, int pIdx)Used by rearrangement methods to shuffle nodes around.booleanisLeaf(Object pNode)protected 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 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:
addTreeModelListenerin interfaceTreeModel
-
removeTreeModelListener
public void removeTreeModelListener(TreeModelListener pListener)
- Specified by:
removeTreeModelListenerin interfaceTreeModel
-
getChildCount
public int getChildCount(Object pParent)
- Specified by:
getChildCountin interfaceTreeModel
-
getIndexOfChild
public int getIndexOfChild(Object pParent, Object pChild)
- Specified by:
getIndexOfChildin interfaceTreeModel
-
valueForPathChanged
public void valueForPathChanged(TreePath pPath, Object pNewValue)
- Specified by:
valueForPathChangedin 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:
canPromotein 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:
canDemotein 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:
canMoveUpin 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:
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:
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:
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
-
-