Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » freely positionable labels outside of labeled shape(How to create a label outside of a shape that can be positioned anywhere on the diagram?)
freely positionable labels outside of labeled shape [message #1176751] Fri, 08 November 2013 14:31 Go to next message
Martin Hanysz is currently offline Martin HanyszFriend
Messages: 30
Registered: November 2013
Member
Hello Graphiti community,

I am currently developing a diagram editor with Graphiti and am struggeling to place a label outside of a shape.

After a bit of research in this forum I found out that the "standard" way to achieve this is to use a ContainerShape with an invisible rectangle as its GraphicsAlgorithm that contains the Shapes for the label and the labeled element. But this method has two drawbacks:

1. The user should be able to move the label to whereever he wants it to be on the diagram. But due to the nesting of the label Shape it cannot be moved outside of its invisible ContainerShape. Even if it is possible to overcome this limitation, it would likely include a resize of the invisible ContainerShape, which leads to drawback #2.

2. The user must not be able to interact with the invisible ContainerShape by e.g. selecting it or dropping other elements "into" it. I know that I can adjust the selection behavior to "redirect" the selection to another PictoramElement if the invisible ContainerShape is clicked, but that would still select an element even though the user clicked on an apparently empty part of the diagram. Additionally, the invisible ContainerShape seems to overlap PictogramElements that were created before the invisible ContainerShape, thus the overlapped section would not select the visible element, but the target of the "redirection". The attached picture gives an illustration of the described setup.
index.php/fa/16704/0/

It seems that making the invisible ContainerShape inactive is exactly what I need as it is not selectable, shapes cannot be dropped into it and it allows the label Shape to be placed anywhere on the diagram. But the problem with this method is that the diagram is not redrawn when Shapes that are nested in the inactive ContainerShape are moved or resized (to my surprise direct editing of the label works).

Finally, simply making two separate Shapes came to my mind, but the Graphiti Feature API seems to expect that an AddFeature always creates one Shape at a time so I didn't investigate that.

So my questions are:
1. What is the best way to have a freely positionable label outside of the labeled element?
2. If the answer to question 1 is having an invisible ContainerShape, how do I overcome the issues mentioned above?
3. Is there a way to trigger a redraw of the diagram when the children of an inactive Shape are moved or resized?

Thanks in advance for the help and best regards,
Martin
Re: freely positionable labels outside of labeled shape [message #1176811 is a reply to message #1176751] Fri, 08 November 2013 15:16 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
You can look how it is made in bpmn2-modeler:

http://eclipse.org/bpmn2-modeler/

They made separate pictograms for the element and the label and they linked them one with another as business objects.

In this way you can move label as you want.

Marek
Re: freely positionable labels outside of labeled shape [message #1184213 is a reply to message #1176751] Wed, 13 November 2013 09:50 Go to previous messageGo to next message
Martin Hanysz is currently offline Martin HanyszFriend
Messages: 30
Registered: November 2013
Member
After a bit of testing different approaches to the aforementioned problems, I stumbled upon the method refreshContent() of the DiagramBehavior class. This allows me to trigger a redraw of the Diagram content from within a feature and I use it whenever a Shape with an inactive parent is moved or resized.

Thus, my solution to the "freely positionable label" problem is to create an inactive ContainerShape and make the Shapes of the labeled element and the label children of this container. Additionally, I make sure to trigger a redraw of the Diagrams content with the method mentioned above. This way, there is exactly one ContainerShape for each instance of a business model element in the Diagram, which leads to a clear structure of the pictogram model and should ease the handling of PictogramElements to some extent.
The approach of creating two independent Shapes that are linked to the same business model element seems to lack this clear structure which is why I preferred the solution described above.

Best regards,
Martin

Re: freely positionable labels outside of labeled shape [message #1186546 is a reply to message #1184213] Thu, 14 November 2013 19:17 Go to previous message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
It is true that there are some works to do with two shapes. I had to extend DefaultMoveShapeFeature and DefaultResizeShapeFeature for the top element in the business object inheritance hierarchy. However in my case this solution fits.

For example:
	@Override
	protected void postMoveShape(final IMoveShapeContext context) {
		Shape shape = context.getShape();
		
		// move also label
		for (EObject o : shape.getLink().getBusinessObjects()) {
			if (o instanceof Shape && Graphiti.getPeService().getPropertyValue((Shape)o, AddElementFeature.LABEL_PROPERTY) != null) {
				ContainerShape textContainerShape = (ContainerShape)o;
				int dx = context.getDeltaX();
				int dy = context.getDeltaY();
				
				textContainerShape.getGraphicsAlgorithm().setX(textContainerShape.getGraphicsAlgorithm().getX() + dx);
				textContainerShape.getGraphicsAlgorithm().setY(textContainerShape.getGraphicsAlgorithm().getY() + dy);
			}
		}
		
		super.postMoveShape(context);
	}


Marek
Previous Topic:Load and Synchronize business objects across several resource files
Next Topic:Allow Anchor to "follow" the mouse
Goto Forum:
  


Current Time: Thu Mar 28 13:49:38 GMT 2024

Powered by FUDForum. Page generated in 0.02318 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top