Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to achieve floating/attached labels?
How to achieve floating/attached labels? [message #1395139] Sun, 06 July 2014 12:34 Go to next message
Homer S is currently offline Homer SFriend
Messages: 13
Registered: June 2014
Junior Member
Hi,

I'm curious on what's the best way to achieve floating labels.

Andreas Graf mentions aspects of one method in his post here: https://www.eclipse.org/forums/index.php/m/932517/?srch=floating+text#msg_932517

But I can't quite follow the procedure.

My situation:
My model consists of en element MyDiagram (white Rectangle with black border) that can contain Lifelines (vertical Polyline) side by side. Each Lifeline gets a name upon creation.

Now, I'd like to have these names appear as a Text within a Shape that is positioned outside of the MyDiagram Rectangle.

I tried to workaround the problem via adding the Text to top of the Shape with the Polyline and the white Rectangle of MyDiagram would be inactive and act as a background inside a transparent container Rectangle.
The white rectangle's y coordinate would then be positioned with the Polylines start.

But this results in a lot of layout fuss when the Text element has multiple lines.

Additionally this feels like I'm using Graphiti against it's nature.

Any ideas?
Thanks

--
Homer
Re: How to achieve floating/attached labels? [message #1395943 is a reply to message #1395139] Mon, 07 July 2014 16:36 Go to previous messageGo to next message
Martin Hanysz is currently offline Martin HanyszFriend
Messages: 30
Registered: November 2013
Member
Hello Homer,

there are actually multiple ways to achieve this.

What I did in my project is to create an invisible container shape that holds the shape you want to label and the label itself. This way you have them grouped together very nicely, but the downside is that you will be able to select the invisible shape and manipulate it. This will most likely confuse your users. To overcome this, I decided to makt the invisible container shape inactive, but that in turn requires special treatment in some places, e.g. the children of inactive shapes are not automatically updated and the coordinate system of the active children is not relative to the inactive parent but to the next active parent up the hierarchy. But these limitations can be handled at a few places in your code if you design your classes right.

Another way you may consider is to simply have two separate shapes, the one you want to label and the label itself, that have a reference to each other. For that reference you can use the property mechanism to give the labeled shape a "label" property and vice versa. Once you manipulate the position of the labeled shape, you need to remember to move the label, too.

I hope these two ideas give you a starting point.

Best regards,
Martin
Re: How to achieve floating/attached labels? [message #1396635 is a reply to message #1395943] Tue, 08 July 2014 15:26 Go to previous messageGo to next message
Homer S is currently offline Homer SFriend
Messages: 13
Registered: June 2014
Junior Member
Hi Martin,

thanks for this detailed answer!

Martin Hanysz wrote on Mon, 07 July 2014 16:36
What I did in my project is to create an invisible container shape that holds the shape you want to label and the label itself. This way you have them grouped together very nicely, but the downside is that you will be able to select the invisible shape and manipulate it. This will most likely confuse your users. To overcome this, I decided to makt the invisible container shape inactive, but that in turn requires special treatment in some places, e.g. the children of inactive shapes are not automatically updated and the coordinate system of the active children is not relative to the inactive parent but to the next active parent up the hierarchy. But these limitations can be handled at a few places in your code if you design your classes right.


Before the project started I, too, thought I could use this approach. But:
The labeled shape is inside a container shape and the label should be outside the frame of the container. Since shapes clip any of their children when they go beyond their frame.

Martin Hanysz wrote on Mon, 07 July 2014 16:36
Another way you may consider is to simply have two separate shapes, the one you want to label and the label itself, that have a reference to each other. For that reference you can use the property mechanism to give the labeled shape a "label" property and vice versa. Once you manipulate the position of the labeled shape, you need to remember to move the label, too.


Well, I guess I've missed something on the docs.
Thanks for the hint. I suspect you meant this entry: Using User-Defined Properties

I'll go and dig through it then.
But feel free to respond in more detail regarding the property approach Wink

Best regards,
Homer

Re: How to achieve floating/attached labels? [message #1397865 is a reply to message #1396635] Thu, 10 July 2014 09:09 Go to previous messageGo to next message
Martin Hanysz is currently offline Martin HanyszFriend
Messages: 30
Registered: November 2013
Member
Hi Homer,

I think you missed a point of the first approach with the invisible container: using this approach you have 3 shapes:

  1. the shape you want to label
  2. the label that contains the text
  3. an invisible container

By nesting both, the label and the labelled shape, in the invisible container, you can place the label outside of the bounds of the shape you want to label e.g. below it. As far as I know, inactive shapes do not clip their children at their own borders. That means the size of the invisible and inactive container does not matter at all.

Regarding the property approach: you got the right link. User defined Properties are really just a string to string map that each property container (a superclass of all shapes) has. So you just need to find a way to map shapes to strings somehow.

Best regards,
Martin
Re: How to achieve floating/attached labels? [message #1398018 is a reply to message #1397865] Thu, 10 July 2014 13:44 Go to previous messageGo to next message
Homer S is currently offline Homer SFriend
Messages: 13
Registered: June 2014
Junior Member
Martin Hanysz wrote on Thu, 10 July 2014 09:09
By nesting both, the label and the labelled shape, in the invisible container, you can place the label outside of the bounds of the shape you want to label e.g. below it. As far as I know, inactive shapes do not clip their children at their own borders. That means the size of the invisible and inactive container does not matter at all.


My problem is, that the label needs to outside the bounds of my visible container. Maybe a visual is better to explain my problem:
index.php/fa/18513/0/

The big solid rectangle is my visible container. The red lines are the shapes/GAs to be labeled. The texts are the labels, obvious Wink And the dashed rectangles are the invisible containers.

So my visible container will clip the labels inside the invisible containers. The invisible container to group label and labeled shape can't be inactive, cause the user has to be able to move them horizontally, so he can define his own spacing, but that's a whole other story.


Martin Hanysz wrote on Thu, 10 July 2014 09:09
Regarding the property approach: you got the right link. User defined Properties are really just a string to string map that each property container (a superclass of all shapes) has. So you just need to find a way to map shapes to strings somehow.


So, I'd need to implement some kind of search function, right? Isn't this already accomplished via the IdPattern?

Has anybody done this before and could help explain this to me?


Thanks!
Re: How to achieve floating/attached labels? [message #1398712 is a reply to message #1398018] Fri, 11 July 2014 13:18 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
Hi,
As I stated in this topic: http://www.eclipse.org/forums/index.php/m/1176751/

You can look how this is made in in bpmn2-modeler: http://eclipse.org/bpmn2-modeler/

Regards,

Marek
Re: How to achieve floating/attached labels? [message #1401275 is a reply to message #1398712] Tue, 15 July 2014 11:35 Go to previous messageGo to next message
Homer S is currently offline Homer SFriend
Messages: 13
Registered: June 2014
Junior Member
Marek Jagielski wrote on Fri, 11 July 2014 13:18
Hi,
As I stated in this topic: http://www.eclipse.org/forums/index.php/m/1176751/

You can look how this is made in in bpmn2-modeler: http://eclipse.org/bpmn2-modeler/


Hi Marek,

thank you for the response and hint. I've found your answer in the linked thread and the bpmn2 project before, but I couldn't really wrap my head around how and where they exactly did this in their code. Been going through the git repo of bpmn2 a couple of times.

Do you know where?

Thank you
Re: How to achieve floating/attached labels? [message #1401315 is a reply to message #1401275] Tue, 15 July 2014 12:44 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
For my project I took from bpmn2-modeler only the idea how to make labels. I see now that it was a little bit refactored since the time I was looking at that. It seems cleaner than what I have in my project:
+ Here you have all features concerning label. https://github.com/eclipse/bpmn2-modeler/tree/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/label
+ I think here is the code that has inspired me: https://github.com/eclipse/bpmn2-modeler/blob/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/label/AbstractAddLabelFeature.java
There you have lines that links label and shape with business object:
peService.setPropertyValue(labelShape, GraphitiConstants.LABEL_SHAPE, Boolean.toString(true));

link(labelShape, new Object[] {businessObject, labelOwner});
link(labelOwner, new Object[] {labelShape});


In bpmn2-modeler they are grouping features in containers: https://github.com/eclipse/bpmn2-modeler/blob/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/label/LabelFeatureContainer.java

+ A lot of utils related to labels you can find here: https://github.com/eclipse/bpmn2-modeler/blob/master/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/FeatureSupport.java

The most aptly called method is:
public static boolean isLabelShape(PictogramElement shape) {
	if (shape==null)
		return false;
	return Graphiti.getPeService().getPropertyValue(shape, GraphitiConstants.LABEL_SHAPE) != null;
}


I don't know how in this project but in my project I have some amount of small bugs concerning this solution to be still treated. For example, if I select more objects shapes and labels and I move them with arrays on keyboard, the labels are "moved twice". You have to think about these things.
Marek

[Updated on: Tue, 15 July 2014 12:47]

Report message to a moderator

Re: How to achieve floating/attached labels? [message #1401325 is a reply to message #1401315] Tue, 15 July 2014 12:55 Go to previous messageGo to next message
Marek Jagielski is currently offline Marek JagielskiFriend
Messages: 97
Registered: April 2012
Member
But maybe in your case it would be better that lines and text is one shape. In my case I wanted that user can move labels also separately. If your labels are stick to lines in one place, maybe you should "fight" a little to make it a part of principal shape.

Marek
Re: How to achieve floating/attached labels? [message #1401327 is a reply to message #1401325] Tue, 15 July 2014 12:58 Go to previous messageGo to next message
Homer S is currently offline Homer SFriend
Messages: 13
Registered: June 2014
Junior Member
Thanks for the detailed answer!

Marek Jagielski wrote on Tue, 15 July 2014 12:55
But maybe in your case it would be better that lines and text is one shape. In my case I wanted that user can move labels also separately. If your labels are stick to lines in one place, maybe you should "fight" a little to make it a part of principal shape.


Well, at the moment lines and text are one shape, but as I said, they get clipped.
Re: How to achieve floating/attached labels? [message #1402611 is a reply to message #1401327] Thu, 17 July 2014 08:24 Go to previous message
Homer S is currently offline Homer SFriend
Messages: 13
Registered: June 2014
Junior Member
One thing I think I didn't strain in my initial post, yet:
The labels are not optional and should be added when a line is created and added to the MyDiagram rectangle container. They should be fixed in their position relative to the line.

I'm really stuck on this one Confused
Previous Topic:Wrapping text in a textbox created by gaService
Next Topic:Drag-n-drop from Project Explorer - invoking Create Feature
Goto Forum:
  


Current Time: Fri Apr 26 13:33:16 GMT 2024

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

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

Back to the top