I have a use case where we want to allow the user to reorder timeline objects (default activity objects, actually) relative to one another. One of those operations is to move the timeline object into another folder. So, we would like to move the entire node to that new folder, assuming drag and drop requirements are met. I’m struggling with how I might do this and not seeing any code like this in the samples Can you give me the basic steps I should be thinking about?
We have two sorts of dragging. First, we drag tree nodes around, much like the file folder you mention. We have leaf nodes that we place in certain folders and the user can move them to other folders. in that case, the user is grabbing the visual representation of the node and moving it around, so the framework handles the task of keeping the timeline objects with the node they belong to.
We are also OK for cases where the user moves the timeline horizontally, since it stays associated with the same tree table node. But, in the case where the user grabs a timeline object and moves it vertically. the timeline object becomes associated with a different node. That default framework behavior is not what we want in this case. I’ve got some of the drag and drop code in place and expect that I need to handle the move to another node in that code. I’m expecting that I need to do something like figure out the node associated with the timelineobject, determine the start position and the end position, then reorder the tree model to reflect the movement of the entire node (not just the movement of the timelineobject).
I’m just not seeing how I can get to the ganttchart or model and don’t see how to move the node around. Just occurred to me that I should gain some insight from DefaultNodeDragAndDropCommand and DefaultNodeDragAndDropPolicy. But, I’m sure your advice would still be helpful. This is my first time working with Swing drag & drop.
No, we would like to the user to be able to move the TLO vertically, but if the drop is acceptable, then we want to move the entire node to that location. This is just the opposite of what happens when they move the node and the TLO follows.
Maybe I am not into the details enough to understand the implication of your question. I guess I was thinking the new node would be passed into the function. If that was a folder, then I can add the dragged leaf to it anywhere. If the newNode is also a leaf, the dragged node can go before or after it, I don’t think it matters too much.
No I got the full picture. So you will need to subclass the DefaultDragAndDropPolicy and register your subclass on the LayerContainer.
LayerContainer lc = gantt.getLayerContainer(); lc.getPolicyProvider().setPolicy(IDragAndDropPolicy.class, new BriansPolicy());
Inside BriansPolicy you need to return a different command for performing the actual model changes after the drop. Instead of returning the default command for moving a timeline object from one node to another you will need to return the command used to reassign a node from one parent to a new one: DefaultNodeDragAndDropCommand.