Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324556

Summary: Hide Shapes - enable simple collapse/expand
Product: [Modeling] Graphiti Reporter: Tim Kaiser <tim.kaiser>
Component: CoreAssignee: Michael Wenz <michael.wenz>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P4 CC: juergen.pasch, matteo.miraz, michael.wenz, selvam.jp
Version: 0.7.0Flags: michael.wenz: juno+
Target Milestone: 0.9.0   
Hardware: All   
OS: All   
Whiteboard: Juno M5 Theme_bugs

Description Tim Kaiser CLA 2010-09-06 05:20:49 EDT
Currently, a collapse/expand functionality can be realized by
removing the shapes from the diagram (remove feature) and then adding
them again (add feature).
This process leads to loosing the coordinates of the shapes, so
on expand after collapse new coordinates have to be computed
automatically.

We should discuss if and how we can enable a "true hide" for shapes,
such that the model elements are preserved and only the visualization
is changed. 

We would have to discuss several issues, e.g. what about editparts etc
Comment 1 Michael Wenz CLA 2010-09-08 11:16:20 EDT
Added to the backlog for post 0.7.0
Comment 2 Panneer Selvam CLA 2010-10-19 06:09:05 EDT
We would need this feature soon.. we need the feature collapse/expand and filtering the connections without making the editor dirty.
Comment 3 Michael Wenz CLA 2010-10-19 06:29:53 EDT
Raised priority (in planning for 0.8.0). Needs further clarification and technical discussions.
Comment 4 Michael Wenz CLA 2011-07-18 06:38:38 EDT
Out-of-scope for Juno unless there are contributions in this area
Comment 5 Matteo Miraz CLA 2011-12-23 11:47:55 EST
Does there is any progress?

Using the current milestone(0.9.0v20111028-1029) it almost works, as you can hide both inner shapes and inner connectors, and re-layout the pictogramElement.

The only problem is that the selection stops working: the hidden shape causes 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)
Comment 6 Michael Wenz CLA 2011-12-28 08:26:47 EST
Could you post some more details on the solution you built for hiding and showing stuff? We only sketched a possible solution, but that idea turned out to be more complex, so this topic was postponed.
(So, the answer to your question would be no, there has been no progress in this.)
Comment 7 Matteo Miraz CLA 2011-12-28 08:46:50 EST
It is explained here: http://www.eclipse.org/forums/index.php/t/264388/

In short, I use a property to store if an element is expanded or collapsed. The collapse feature just toggle that property and forces a layout. The layout verifies the actual and the desired collapse status, and:
* hides (shows) inner connectors & shapes, using method setVisible
* updates the graphical representation of the element 

This approach seems to work, as the the element is shown correctly. The only problem I found is with selection.

I have a view that shows all the element of the model. When I select an element, the linked graphical shapes & connectors are highlighted (selected). Note that a model element can be linked to several graphical elements: when such element is selected, several shapes are highlighted. The problem arises when one of the shapes is not visible (i.e., belongs to a collapsed shape). In this case, an exception is thrown (see later) and the diagram has a wrong set of elements highlighted. Instead, only the visible elements should be highlighted.

The exception I experience is:
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)
Comment 8 Michael Wenz CLA 2011-12-30 04:23:35 EST
Matteo,

that sounds really good, but almost too easy... ;-)

I had a look into this and it appears as if the only thing we need to do is to prevent that the diagram editor tries to force the selection for EditParts that are not selectable (e.g. invisible). Sounds very much reasonable as weel in general.

I checked in a change doing exactly this in head and pushed it to Eclipse:
commit a4dc363edfbadb61ea8897069fe9683ab3af0289
Author: mwenz <michael.wenz@sap.com> 2011-12-30 10:10:35
Committer: mwenz <michael.wenz@sap.com> 2011-12-30 10:10:35
Parent: 70c4695586a0f149d4f618bc797f60296c29c7d7 (Bug 367204: Correctly return the added PE inAbstractFeatureProvider's addIfPossible method by enhancing the IDiagramEditor.executeFeature method with a return value)
Branches: origin/master, master
Comment 9 Michael Wenz CLA 2011-12-30 04:28:29 EST
Matteo,

Could you try that change if it works for you,please?

Unfortunatly this is all on top of our editor restructoring, so it will probably not be ease for you to test. So here's the change I did to the selectPictogramElements method in DiagramEditor (you will need to apply the changes to DiagramEditorInternal):
	public void selectPictogramElements(PictogramElement[] pictogramElements) {
		List<EditPart> editParts = new ArrayList<EditPart>();
		Map<?, ?> editPartRegistry = getGraphicalViewer().getEditPartRegistry();
		if (editPartRegistry != null) {
			for (int i = 0; i < pictogramElements.length; i++) {
				PictogramElement pe = pictogramElements[i];
				Object obj = editPartRegistry.get(pe);
				if (obj instanceof EditPart && ((EditPart) obj).isSelectable()) {
					editParts.add((EditPart) obj);
				}
			}
			getSite().getSelectionProvider().setSelection(new StructuredSelection(editParts));
			if (editParts.size() > 0) {
				final EditPart editpart = editParts.get(0);
				if (!(editpart instanceof IConnectionEditPart)) {
					Display.getDefault().asyncExec(new Runnable() {
						public void run() {
							getGraphicalViewer().reveal(editpart);
						}
					});
				}
			}
		}
	}
Comment 10 Matteo Miraz CLA 2012-01-02 12:21:06 EST
Michael,

the patch you sent me solves the exception I was speaking about, and now everything seems to work smoothly (at least, in my application)!

Thank you very much for your help!
Comment 11 Michael Wenz CLA 2012-01-03 05:08:25 EST
So it appears that collapse/expand works now. Aparently, the only missing piece needed was a bugfix as described here.
Therefor I flag this as a bug and close the issue with the bugfix being part of Juno M5.
Comment 12 Juergen Pasch CLA 2012-01-26 08:22:10 EST
I checked it and it is O.K.
Comment 13 Michael Wenz CLA 2012-04-11 10:52:00 EDT
Bookkeeping: Set target release
Comment 14 Michael Wenz CLA 2012-06-29 04:18:27 EDT
Part of Graphiti 0.9.0 (Eclipse Juno)