Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Label based on referenced Nodes
Label based on referenced Nodes [message #220496] Wed, 04 March 2009 09:30 Go to next message
Eclipse UserFriend
Originally posted by: user.domain.invalid

Hi,
my Problem is: I have a Node A and a Node B with a Label and a Reference
from A to B. Now I want the the Label to be shown in Node B (no problem)
, but in Node A there should be a Label based on the text of the Label
in Node B.

Regards
Henning Selt
Re: Label based on referenced Nodes [message #220519 is a reply to message #220496] Wed, 04 March 2009 10:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cayla_sha.gmx.net

Hello Henning!

I have an idea how you can solve this:

In the EditPart of A there must be an inner class called something with
"..Figure". There you add the code, which sets the label-text.
I wouldn`t add the label for A in the gmfgraph-file (like you would do
it for B). I would add the label programmatically in this inner class.
- add a variable before the constructor of the inner class:
private WrappingLabel myALabel;
- at the end of the constructor add
createContents();
updateFace();
- if not existing, add a method createContents() and initialize the
WrappingLabel.
- add a method updateFace():
There you get the Object A:
A aObject = (A) ((View) AEditPart.this.getModel()).getElement();
And then you can ask for references to B and set the Text of myALabel
accordingly.

Now you can set the Label of A according to the label in B.

But at the moment this works only on the creation of A. So the EditPart
of A needs to listen for changes of B`s attribute.
In the EditPart of A:
- add a NotationalListener:
/**
* @generated NOT
*/
@Override
protected void addNotationalListeners()
{
Diagram diagram = this.getDiagramView();
if (diagram != null)
{
addListenerFilter("ListenForBsChanges", this, diagram,
EditorPackage.Literals.B__ATTRIBUTE_NAME);
}
super.addNotationalListeners();
}

- add the remove-method:
/**
* @generated NOT
*/
@Override
protected void removeNotationalListeners()
{
removeListenerFilter("ListenForBsChanges");
super.removeNotationalListeners();
}

- add a handleNotificationEvent()-method, where you catch the event of
the listener:
/**
* @generated NOT
*/
@Override
protected void handleNotificationEvent(Notification notification)
{
Object feature = notification.getFeature();
if(EditorPackage.Literals.B__ATTRIBUTE_NAME.equals(feature))
{
getPrimaryShape().updateFace();
return;
}
super.handleNotificationEvent(notification);
}

I think this should work.
Best wishes
Julia


user@domain.invalid schrieb:
> Hi,
> my Problem is: I have a Node A and a Node B with a Label and a Reference
> from A to B. Now I want the the Label to be shown in Node B (no problem)
> , but in Node A there should be a Label based on the text of the Label
> in Node B.
>
> Regards
> Henning Selt
Re: Label based on referenced Nodes [message #220970 is a reply to message #220496] Tue, 10 March 2009 14:35 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello exquisitus,

The easiest way is to create derived attribute "labelB" in class A, generate
code, implement appropriate method in EMF-generated implementation and then
use it in GMF.

-----------------
Alex Shatalin
Previous Topic:How can I use self-defined model as EMF generated editors' input? How to handle the resource synchro
Next Topic:Connection happens only for first linking mapping
Goto Forum:
  


Current Time: Thu Apr 25 08:37:29 GMT 2024

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

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

Back to the top