Label based on referenced Nodes [message #220496] |
Wed, 04 March 2009 09:30 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03089 seconds