How to change Node Graphics dynamic, depending on Node Attributes [message #169985] |
Sat, 26 January 2008 10:48 |
Eclipse User |
|
|
|
Originally posted by: Sid.v.v
Hello,
ive a node with a attribute "tokens" (just a Integer Value)
the node is displayed as a Circle.
What i want to achieve is that values from 0 to 3 are displayed as small
points inside the circle.
0=no point
1=1 point
and so on.
if values are larger then 3, then the numeric value should be displayed
instead of the points.
and more thing: negative Values shouldnt be allowed to type in.
I hope someone can help me with this. Thanks
With best regards,
Sid
|
|
|
Re: How to change Node Graphics dynamic, depending on Node Attributes [message #170139 is a reply to message #169985] |
Mon, 28 January 2008 09:15 |
Eclipse User |
|
|
|
Originally posted by: tobk42.gmx.de
This should be no problem. Override the method notifyChanged In the
state edit part (I assume that you are making something petri net
like...), something like:
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
int feature = notification.getFeatureID(VsdtPackage.class);
switch (feature) {
case VsdtPackage.STATE__TOKEN_NR:
getPrimaryShape().setTokens(getCastedModel().getTokenNr());
refreshVisuals();
break;
}
}
where getCastedModel() returns ((View)getModel).getElement, casted to
the actual class (State, I assume). setTokens, finally, is a Method you
have to implement on your figure class (which by default is generated
within the edit part class). This method then will add additional
figures (circles and numbers) to the state figure. And, of course,
remember to mark all of the changes with @generated NOT.
Regards,
Tobias
Sid schrieb:
> Hello,
>
> ive a node with a attribute "tokens" (just a Integer Value)
> the node is displayed as a Circle.
> What i want to achieve is that values from 0 to 3 are displayed as small
> points inside the circle.
> 0=no point
> 1=1 point
> and so on.
> if values are larger then 3, then the numeric value should be displayed
> instead of the points.
> and more thing: negative Values shouldnt be allowed to type in.
>
> I hope someone can help me with this. Thanks
>
> With best regards,
>
> Sid
>
>
>
>
>
>
>
|
|
|
Re: How to change Node Graphics dynamic, depending on Node Attributes [message #170263 is a reply to message #170139] |
Tue, 29 January 2008 08:49 |
Eclipse User |
|
|
|
Originally posted by: Sid.v.v
Hello Tobias,
thanks for your reply. you are right, im trying to develope a petri net
editor.
what ive done so far is: a place node (PlaceEditPart) and a feature label
tokens inside this node(PlaceTokensEditPart). I have overwritten the
notifyChanged method of PlaceTokensEditPart and just put a simple console
output inside to test it. That worked. Actually i try to get the actual
token number but without success.
Where do i have to write the method getCastedModel()?
One more Question, a little bit off-topic. How can i position the Feature
Label inside the Circle in the middle? ive tried to add a locationpoint to
the label in gmfgraph, but this didnt work.
Thanks for your help.
With best regards,
Sid
|
|
|
Re: How to change Node Graphics dynamic, depending on Node Attributes [message #170302 is a reply to message #170263] |
Tue, 29 January 2008 09:40 |
Eclipse User |
|
|
|
Originally posted by: tobk42.gmx.de
Whops, right, the circles are called places, not states. ^^;;
That getCastedModel() method is just a convenience method I got used to
implement in all of my edit parts and as I wrote it does nothing more
than returning the EObject element behind the edit part.
Actually my idea was slightly different: I assumed that you do not have
a feature label for the tokens at all, but that you would add the token
figures and the number respectively inside the place's figure, e.g. by
overwriting its paintfigure method. This would also solve the problem of
positioning the label. Of course, in that case one will have to use the
property view to set the tokens instead of direct-editing them.
Unfortunately I do not know exactly how to achieve the same using a
feature label. I think there should be some way to access the current
value(s) represented by the label in a similar way to the above. I think
you can also query the notification for the "newValue". For displaying
the tokens as dots you might succeed overwriting paintFigure as well,
but I'm not sure...
A third way could be a combination of both: having a feature label for
easyly setting the tokens and displaying the numeric value, and
additionally up to three token-dots on the figure. Here you would not
have to do any customizations to the TokeneditPart at all, but only to
the place edit part, overwriting the notifyChanged, passing the new
number of tokens to the figure and refreshing the figure, thus calling
the overwritten paintFigure method, in which the token dots are drawn as
(black or grey) dots "behind" the numeric value.
Tobias
Sid schrieb:
> Hello Tobias,
>
> thanks for your reply. you are right, im trying to develope a petri net
> editor.
> what ive done so far is: a place node (PlaceEditPart) and a feature
> label tokens inside this node(PlaceTokensEditPart). I have overwritten
> the notifyChanged method of PlaceTokensEditPart and just put a simple
> console output inside to test it. That worked. Actually i try to get the
> actual token number but without success.
> Where do i have to write the method getCastedModel()?
>
> One more Question, a little bit off-topic. How can i position the
> Feature Label inside the Circle in the middle? ive tried to add a
> locationpoint to the label in gmfgraph, but this didnt work.
>
>
>
> Thanks for your help.
> With best regards,
> Sid
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04039 seconds