Using JGraphX in a Swing Application.

\n

I have a group with some mxCells and I want to avoid that user can move the children outside the parent cell. Any Idea.?

\n

tahnks in Advance

asked 25 Feb '11, 12:19

madmad's gravatar image

madmad
1613
accept rate: 0%

edited 25 Feb '11, 12:52

David's gravatar image

David
4.9k21831


For drag and drop in general, override mxGraphComponent.canExportCell and canImportCell. For removing from groups, override mxGraphHandler.shouldRemoveCellFromParent, eg.

\n
mxGraphComponent graphComponent = new mxGraphComponent(graph)\n{\n  public mxGraphHandler createGraphHandler()\n  {\n    return new mxGraphHandler(this)\n    {\n      // ...\n    }\n  }\n}\n
link

answered 01 Mar '11, 12:10

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

edited 01 Mar '11, 21:17

Gaudenz thanks for the answer that was helpful for me and now the child vertexes can't go out from the parent doing this:

\n
mxGraphComponent graphComponent = new mxGraphComponent(graph){\n            public mxGraphHandler createGraphHandler(){\n                return new mxGraphHandler(this){\n                    @Override\n                    public boolean isRemoveCellsFromParent(){\n                        return false;\n                    }\n                };\n            }\n        };
\n\n

Then I noticed that I could do this too:

mxGraphComponent graphComponent = new mxGraphComponent(graph);\ngraphComponent.setRemoveCellsFromParent(false);

\n

Now I need to avoid the child to move at all.\nI want that the parent cell can be dragged and dropped (with all his content inside that follows him) as the default but I don't want that the childs inside him can move as well. I want the childs to stay inside the parent exactly were they where while I created them with no possibility to move them.

\n

Sorry for my bad english but I hope someone can help me doing this.

link

answered 14 Apr '11, 12:52

vinnie's gravatar image

vinnie
95210
accept rate: 9%

Override mxGraph.isCellMovable.

link

answered 14 Apr '11, 21:53

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

Thanks for the answer but if I do it I will not be able to move ANY cell of the graph and I need to move parent cells.

\n

This is my situation:

\n
-----------------------\n|--------             |\n||      |             |\n||      |   --------  |\n|--------   |      |  |\n||      |   |      |  |\n||      |   |      |  |\n|--------   --------  | \n-----------------------\n
\n\n

The big square is the parent and I want it to be moved. The rectangles inside are his children and I want them still. I want to drag and drop the big square cell as I wish but I dont want to be able to drag and drop the three (as they are in the ascii image) children inside it.\nThey have to move with their parent when I'm dragging it (and this is ensured by default because if I move a parent all his child will be adapted to the new parent position) but they have to remain exaclty in that position avoiding drag and dropping.

\n

It's like having a container with freezed content. I can move the container but I can't move his content.

\n

I hope this is clear now.

\n

Thanks in advance

link

answered 15 Apr '11, 00:26

vinnie's gravatar image

vinnie
95210
accept rate: 9%

edited 15 Apr '11, 00:28

It has a cell argument, you need to check if it has a parent etc.

link

answered 15 Apr '11, 00:27

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

It is the parent because I inserted the children vertex into it. Infact If I move it all the children inside it follow it. My problem is not in setting cells as parents or children but in avoiding them to move.

\n

To override mxGraph.isCellMovable() avoid me to move all the cells inside an mxGraph but I don't want this because some cells (the parent cells) have to move.

\n

How can I set only some cells to avoid them moving?

link

answered 15 Apr '11, 00:34

vinnie's gravatar image

vinnie
95210
accept rate: 9%

return !graph.getModel().isVertex(graph.getModel().getParent(cell))

link

answered 15 Apr '11, 00:50

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

edited 15 Apr '11, 00:52

I did this:

\n
mxGraph graph = new mxGraph(){\n   public boolean isCellMovable(Object cell){\n       return isCellsMovable() && !isCellLocked(cell) && getModel().isVertex(getModel().getParent(cell));\n   }\n};
\n\n

but with it I can't move any cell inside the graph.

link

answered 15 Apr '11, 01:16

vinnie's gravatar image

vinnie
95210
accept rate: 9%

Try !getModel().isVertex(getModel().getParent(cell))

link

answered 15 Apr '11, 01:17

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

YES I did it! I saw you added the "!"

\n

THANKS A LOT!!!

\n

Now it works as I wanted. Thank you very much Gaudenz!

link

answered 15 Apr '11, 01:19

vinnie's gravatar image

vinnie
95210
accept rate: 9%

edited 15 Apr '11, 01:23

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×194
×37
×9
×5
×1

Asked: 25 Feb '11, 12:19

Seen: 6,282 times

Last updated: 15 Apr '11, 01:23