Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Collapse Feature: how to hide an element?
icon5.gif  Collapse Feature: how to hide an element? [message #762829] Thu, 08 December 2011 17:13 Go to next message
Matteo Miraz is currently offline Matteo Miraz
Messages: 38
Registered: March 2011
Member
Hi,

I've created an editor for something similar to an UML component diagram (example), where a container can contain other components (Store in the example).

Now, I want to create a collapse feature: when the container is collapsed I want to hide the contained elements (and reduce the dimensions of the container). I am aware that such feature is not provided out-of-the-box. However, I cannot simply delete/add the contained elements, because the user wants to control their location. What should I do? Does there is a way to hide some elements?

Thanks,
Matteo
Re: Collapse Feature: how to hide an element? [message #763142 is a reply to message #762829] Fri, 09 December 2011 08:51 Go to previous messageGo to next message
Christian B is currently offline Christian B
Messages: 68
Registered: August 2011
Member
I will have to implement this too.

My first idea is setting a property to the parent shape, which shall be minimzed. Then the Layoutfeature for this shape reads this property.
If the property is set, all children of the shape are set to not visible and the height and width of the parent shape are adjusted. In addition you have to take care of connections, because they aren't children of the parent shape, but the diagram...
And as i suppose accordingly to your example, you have to change the positions of the in and out anchor of the parent shape as well.

As i didn't implement anything yet, i cannot say, if this works. Just ideas Wink
Re: Collapse Feature: how to hide an element? [message #763143 is a reply to message #762829] Fri, 09 December 2011 08:48 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1590
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Matteo,

the only way today to hide stuff is to make it invisible, but that will not
result in a real collapse, because the space needed for a graphics
algorithm is taken no matter if it is visible or not.

There is an open bugzilla dealing with this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=324556

For now I would recommend to really delete and add the contained elements
and store their location within a property at the parent. Not really
convenient but that's the only solution right from the top of my head...

HTH,
Michael
Re: Collapse Feature: how to hide an element? [message #763167 is a reply to message #763143] Fri, 09 December 2011 09:39 Go to previous messageGo to next message
Christian B is currently offline Christian B
Messages: 68
Registered: August 2011
Member
Michael Wenz wrote on Fri, 09 December 2011 09:48
Matteo,
... but that will not
result in a real collapse, because the space needed for a graphics
algorithm is taken no matter if it is visible or not...


Why is it a problem, if it takes the space anyway? If it is not visble and not selectable, i do not see a problem.
Re: Collapse Feature: how to hide an element? [message #766942 is a reply to message #763167] Fri, 16 December 2011 17:45 Go to previous messageGo to next message
Matteo Miraz is currently offline Matteo Miraz
Messages: 38
Registered: March 2011
Member
Michael,

thanks for the reference to the bug. However, it seems to me that there is too little progress, and (as you suggested) I have to figure out another way to solve the problem.

I see two main possibilities:

1. (your way) delete the inner elements and save their location in the parent.
In this case, I have to save a lot of information, including the connectors, their bend points, and all the details of the inner elements. Additionally, if the inner element contains other elements (i.e., there are 2 level of nesting), I also have to save details of these elements. I fear that this way is really complex and bug-prone.

2. (buschcobolt's way) move the inner elements out of the visible area.
In this case, I simply need to move all the inner elements so that are outside the visible are, hence they are not visible from and selectable by the user. Additionally, I also have to hide all connections (this is easy, since connections have a visible property).

I'm following the second path, and I'm implementing the collapse as layout feature. This allows me also to solve the case of elements nested at several levels, because I only need to collapse them by invoking the feature recursively (indeed, this is only required to hide inner connectors).

Given your experience with graphiti, I'd like to ask for an additional comment... Is it a really bad way?

[Updated on: Fri, 16 December 2011 17:46]

Report message to a moderator

Re: Collapse Feature: how to hide an element? [message #767957 is a reply to message #766942] Mon, 19 December 2011 09:26 Go to previous messageGo to next message
Christian B is currently offline Christian B
Messages: 68
Registered: August 2011
Member
Hey Matteo, i would appreciate it very much, if you inform me/us about your progress and if you discover any bigger problems.

thanks!
Re: Collapse Feature: how to hide an element? [message #767963 is a reply to message #767957] Mon, 19 December 2011 09:41 Go to previous messageGo to next message
Matteo Miraz is currently offline Matteo Miraz
Messages: 38
Registered: March 2011
Member
Hi,

I've done it, and it works! There is only an issue I'll discuss later in this post.

Here is how I did it. The container element has a property which pinpoints the current state (expanded / collapsed). According to this property, the layout behaves differently. My collapse feature just toggle the status and issues a layout of the element (using the standard feature calling).

If the element is expanded, it verifies if the right graphic elements are shown (i.e., the is a rectangle associated with the container shape, and the first 2 children of the elements are shapes for the line and the text, as shown in the standard graphiti tutorial).

If the element is collapsed, it verifies if the right graphic elements are shown (in my case, it is suffice to remove the rectangle, replace the line with an image, and move all the elements in the right position). When I collapse the container element:
(1) I store the current width and height, so I can correctly expand the element;
(2) I move all the contained shapes to the right and to the bottom, so I'm sure that I'm sure they are outside the collapsed container's bounds
(3) I hide all connectors (they have a visibility property).

I have to say that everything works really smoothly, but there is only an issue with selection. I have to say that I have some views to provide the user with a list of all model elements. If a user selects it, graphiti highlights the corresponding graphical element(s). However, it might happens that the user selects an hidden element: in this case, graphiti draws the selection highlights around an empty space (i.e., the location where the hidden element really is). However, I'm going to work on the selection behavior so to filter out those elements that are not visible.

Hope this helps... Smile
Re: Collapse Feature: how to hide an element? [message #770205 is a reply to message #767963] Fri, 23 December 2011 16:15 Go to previous messageGo to next message
Christian B is currently offline Christian B
Messages: 68
Registered: August 2011
Member
yeah very nice of you!

but one question Wink
Matteo wrote on Mon, 19 December 2011 10:41

(2) I move all the contained shapes to the right and to the bottom, so I'm sure that I'm sure they are outside the collapsed container's bounds

Why do you move alle the contained shapes instead of also setting them to invisible, like you did with connections? Is there anything i miss, why this might not be possible?


Re: Collapse Feature: how to hide an element? [message #770212 is a reply to message #770205] Fri, 23 December 2011 16:43 Go to previous message
Matteo Miraz is currently offline Matteo Miraz
Messages: 38
Registered: March 2011
Member
... because I was not aware that class Shape provides the method setVisible ... Wink

However, if you enable it, you'll get the following exception:
java.lang.IllegalArgumentException: An EditPart has to be selectable (isSelectable() == true) in order to get selected.
	at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
	at org.eclipse.gef.editparts.AbstractEditPart.setSelected(AbstractEditPart.java:1060)
	at org.eclipse.gef.SelectionManager.setSelection(SelectionManager.java:273)
	at org.eclipse.gef.ui.parts.AbstractEditPartViewer.setSelection(AbstractEditPartViewer.java:751)
	at org.eclipse.graphiti.ui.internal.editor.GraphitiScrollingGraphicalViewer.setSelection(GraphitiScrollingGraphicalViewer.java:62)
	at org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal.selectPictogramElements(DiagramEditorInternal.java:1560)
	at org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal.selectionChanged(DiagramEditorInternal.java:1540)
	at org.eclipse.ui.internal.AbstractSelectionService.fireSelection(AbstractSelectionService.java:156)
Previous Topic:Recent addIfPossible
Next Topic:Implement Rotate method for Pictogram Element
Goto Forum:
  


Current Time: Wed Sep 03 04:38:05 GMT 2014

Powered by FUDForum. Page generated in 0.01903 seconds