'Is there a possibility in Java mxGraph to limit cells movement but not disable it?
I am using Java mxGraph and i have deeper nested vertices (on purpose) on 3 levels and now i am trying to keep the innermost vertices(level 3) within their parents(level 2) without executing graph.setCellsMovable(false);. I have tried to use the parents "bounding box": graph.setMaximumGraphBounds(graph.getBoundingBox(parent)); but that didn't do what i hoped it would(it didn't do anything visible to me, neither limit the level-3-vertex's movement nor limiting its max size).
So now my question: is there any method that limits the vertex's movement and not disable it? or is graph.setCellsMovable(false); the only option?
Solution 1:[1]
I don't know if this is of any help, because I use the javascript version of the library... But I have complex drag and drop rules, so I overridden the mxDragSource.prototype.drop and mxGraphHandler.prototype.mouseUp functions... From there I am able to detect the drop target and implement my own custom rules to allow drag and drop for specific cells. Consider that I have different types of cells, some of them are fixed, some of them can move but only between specific swimlanes or within the same swimlane...
Solution 2:[2]
I'm not sure that my use case is the same as yours, but I had issues with cells switching parents on move. So I've overridden the moveCells method in my extension of mxGraph:
@Override
public Object[] moveCells(Object[] cells, double dx, double dy, boolean clone, Object target, Point location) {
// We will not allow cells to change parent, so we move them individually while preserving their parent (by changing the target)
Object[] movedCells =
Arrays.stream(cells)
.map(cell -> super.moveCells(new Object[] { cell }, dx, dy, clone, ((mxCell) cell).getParent(), location))
.flatMap(Arrays::stream).toArray();
return movedCells;
}
This allows some movement, while preserving the cells' parents. I had issues moving across the boundary of the parent (your level2 vertices I presume). Therefore, the exact geometry of the parent matters.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Jacob Grydholt |
