Set backgound color depending on model elements property [message #219037] |
Mon, 16 February 2009 17:46  |
Eclipse User |
|
|
|
Hi,
I have a class ClassA with an attribute color:String in my domain
model. Now I'd like to update the background color of the nodes
representing instances of ClassA based on the color property. I did not
find anything in the graph/mapping models, so I guess I need to code it
manually. Can anyone give me a hint at what classes I need to look and
how I could possibly achieve what I want?
Many thanks!
Best regards,
Marc Moser
|
|
|
|
Re: [solved] Re: Set backgound color depending on model elements property [message #676106 is a reply to message #219097] |
Thu, 02 June 2011 16:32   |
Eclipse User |
|
|
|
Thanks, this worked for me as well..!
Does anyone know if this is the "right" way to do it?
Best
Ivar
Marc Moser wrote, on 02/17/2009 03:45 PM:
> Hi,
>
> A short description how I solved the problem, in case anyone is interested.
>
> In the generated class *.diagram.edit.parts.ClassAEditPart, I've
> overridden method refreshBackgroundColor() something like this:
>
> protected void refreshBackgroundColor() {
> Color backgroundColor = THIS_BACK; // THIS_BACK is created by setting
> background color in figure
> View notationView = getNotationView();
> EObject element = notationView.getElement();
> if (element instanceof ClassA) {
> ClassA a = (ClassA) element;
> backgroundColor = a.getColor();
> }
>
> setBackgroundColor(backgroundColor);
> }
>
> Best,
> Marc
>
> On 2009-02-16 23:46:26 +0100, Marc Moser <moser@montages.com> said:
>
>> Hi,
>>
>> I have a class ClassA with an attribute color:String in my domain
>> model. Now I'd like to update the background color of the nodes
>> representing instances of ClassA based on the color property. I did
>> not find anything in the graph/mapping models, so I guess I need to
>> code it manually. Can anyone give me a hint at what classes I need to
>> look and how I could possibly achieve what I want?
>>
>> Many thanks!
>>
>> Best regards,
>> Marc Moser
>
>
|
|
|
|
|
Re: [solved] Re: Set backgound color depending on model elements property [message #687937 is a reply to message #687849] |
Thu, 23 June 2011 10:50   |
Eclipse User |
|
|
|
@Ivar, Thank you for you replay 
In my model, there is an int attribute called TIRER, the background color of the NODE will be changed dynamically according the value of TIRER (0: balck; 1: red).
In XXXEditPart.java, I write a new function called ChangeColor
protected void ChangeColor()
{
int tirer = this.tirer;
Color backgroundColor;
switch (tirer)
{
case 1:
backgroundColor = ColorConstants.red;
break;
case 0:
backgroundColor = ColorConstants.gray;
break;
default:
backgroundColor = ColorConstants.gray;
};
View notationView = getNotationView();
EObject element = notationView.getElement();
if(element instanceof TransitionEditPart)
{
TransitionEditPart transitionEditPart = (TransitionEditPart) element;
}
setBackgroundColor(backgroundColor);
After that, I override the function handleNotificationEvent.
protected void handleNotificationEvent(Notification event)
{
super.handleNotificationEvent(event);
this.ChangeColor();
}
It works for me every time when I change everything of the node (position, name, etc). Right now, I hope that it change its background color in no time only when the value of TIRER is changed.
Do you have any idea? Thanks;)
Best Regards,
Vincent
[Updated on: Thu, 23 June 2011 10:53] by Moderator
|
|
|
Re: [solved] Re: Set backgound color depending on model elements property [message #687956 is a reply to message #687937] |
Thu, 23 June 2011 11:12   |
Eclipse User |
|
|
|
Hi again,
did you try to override isAffectingEvent in your
class which extends AbstractParser?
AbstractParser.isAffectingEvent(Object, int)
Best,
Ivar
forums-noreply@eclipse.org wrote, on 06/23/2011 04:50 PM:
> @Ivar, Thank you for you replay ;)
>
> In my model, there is an int attribute called TIRER, the background
> color of the NODE will be changed dynamically according the value of
> TIRER (0: balck; 1: red).
> In XXXEditPart.java, I write a new function called ChangeColor
>
> int tirer = this.tirer;
> Color backgroundColor;
> switch (tirer)
> {
> case 1:
> backgroundColor = ColorConstants.red;
> break;
> case 0:
> backgroundColor = ColorConstants.gray;
> break;
> default:
> backgroundColor = ColorConstants.gray;
> };
> View notationView = getNotationView();
> EObject element = notationView.getElement();
> if(element instanceof TransitionEditPart)
> {
> TransitionEditPart transitionEditPart = (TransitionEditPart) element;
> }
> setBackgroundColor(backgroundColor);
>
>
> After that, I override the function handleNotificationEvent.
>
> protected void handleNotificationEvent(Notification event)
> {
> super.handleNotificationEvent(event);
> this.ChangeColor();
> }
>
>
> It works for me every time when I change everything of the node
> (position, name, etc). Right now, I hope that it change its background
> color in no time only when the value of TIRER is changed.
>
> Do you have any idea? Thanks;)
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11571 seconds