Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Set backgound color depending on model elements property
Set backgound color depending on model elements property [message #219037] Mon, 16 February 2009 17:46 Go to next message
Eclipse UserFriend
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
[solved] Re: Set backgound color depending on model elements property [message #219097 is a reply to message #219037] Tue, 17 February 2009 09:45 Go to previous messageGo to next message
Eclipse UserFriend
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 #676106 is a reply to message #219097] Thu, 02 June 2011 16:32 Go to previous messageGo to next message
Eclipse UserFriend
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 #687841 is a reply to message #676106] Thu, 23 June 2011 07:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi, Marc. I have tried your solution. It works for me. Thank you very much. But when I do that, it will change the color of all the nodes. If I only want to change some of them according to there contribute respectively, do you have any ideas? Thanks

Best Regards,
Vincent
Re: [solved] Re: Set backgound color depending on model elements property [message #687849 is a reply to message #687841] Thu, 23 June 2011 07:44 Go to previous messageGo to next message
Eclipse UserFriend
Hi.

What does
> If I only want to change some of them according to there contribute
> respectively, do you have any ideas?
mean? Can you be more precise?

> View notationView = getNotationView();
> EObject element = notationView.getElement();
With those you have access to the view and your domain element/model if
you want to base the color on those...

Best,
Ivar


forums-noreply@eclipse.org wrote, on 06/23/2011 01:17 PM:
> Hi, Marc. I have tried your solution. It works for me. Thank you very
> much. But when I do that, it will change the color of all the nodes. If
> I only want to change some of them according to there contribute
> respectively, do you have any ideas? Thanks
>
> Best Regards,
> Vincent
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 Go to previous messageGo to next message
Eclipse UserFriend
@Ivar, Thank you for you replay Wink

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 Go to previous messageGo to next message
Eclipse UserFriend
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;)
>
>
>
Re: [solved] Re: Set backgound color depending on model elements property [message #687966 is a reply to message #687956] Thu, 23 June 2011 11:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi, I didn't do that. About <<AbstractParser.isAffectingEvent(Object, int)>>, how does it work? What is the code and where should I add them? Thanks again Wink
Re: [solved] Re: Set backgound color depending on model elements property [message #701139 is a reply to message #687966] Sun, 24 July 2011 13:45 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

better late than never...
I think that you would like to do thi sthing: http://wiki.eclipse.org/Graphical_Modeling_Framework/Tips#Making_figures_sensitive_to_attributes_of_semantic_elements

regards,
Re: [solved] Re: Set backgound color depending on model elements property [message #908861 is a reply to message #687956] Thu, 06 September 2012 02:11 Go to previous messageGo to next message
Eclipse UserFriend
where i can find handleNotificationEvent()??
Re: [solved] Re: Set backgound color depending on model elements property [message #908871 is a reply to message #908861] Thu, 06 September 2012 02:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

please read again the pointing article.
it is in PortEditPart, so in all XXXEditPart. The method might not be generated. You can add it to override the super behavior.

Regards,
Re: [solved] Re: Set backgound color depending on model elements property [message #909515 is a reply to message #687937] Fri, 07 September 2012 05:07 Go to previous messageGo to next message
Eclipse UserFriend
ur idea seems good. but my problem is that u have used:
int tirer = this.tirer;
tirer is a attribute of ur model. but i cant get my attribute is my code.
My attribute name is packetSize. but when i write,
int packetSize = this.packetSize.... packetSize is unknown.
that means i cant access my attribute list....

any help will be appreciable...
Re: [solved] Re: Set backgound color depending on model elements property [message #909518 is a reply to message #909515] Fri, 07 September 2012 05:10 Go to previous messageGo to next message
Eclipse UserFriend
and resolveSemanticElement().packetSize with the appropriated cast?
Re: [solved] Re: Set backgound color depending on model elements property [message #909525 is a reply to message #909518] Fri, 07 September 2012 05:17 Go to previous messageGo to next message
Eclipse UserFriend
Aurelien Pupier..thnx for the quick reply but it doesnt work... does it means i made a mistake in design phrase or something??
Re: [solved] Re: Set backgound color depending on model elements property [message #909528 is a reply to message #909525] Fri, 07 September 2012 05:19 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

on which class did you add the packetSize attribute?

Regards,
Re: [solved] Re: Set backgound color depending on model elements property [message #909531 is a reply to message #909528] Fri, 07 September 2012 05:28 Go to previous messageGo to next message
Eclipse UserFriend
I tell u in details, may be u will get an idea...
actually when i design in XXX.ecorediag i have a node CBQ and I added some attribute like name, packetSize, Priority etc.
Then step by step i made XXX.diagram and other generates other code and it runs perfectly.
Now what i am trying to do is: In the editor I will put some value and the node will change its color according to it. suppose if Priority is 1 then the node becomes red. thats y i am using the function ChangeColor().


public class CBQEditPart extends ShapeNodeEditPart {
protected void ChangeColor()
{
int Priority = this.*********;
Color backgroundColor;
switch (Priority)
{
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 CBQEditPart)
{
CBQEditPart transitionEditPart = (CBQEditPart) element;
}
setBackgroundColor(backgroundColor);
}
}

I wrote this function in CBQEditPart.java and inside CBQEditPart class.


I am really if i dont make u understood. I am just a beginner.
Re: [solved] Re: Set backgound color depending on model elements property [message #912841 is a reply to message #909531] Fri, 14 September 2012 05:24 Go to previous messageGo to next message
Eclipse UserFriend
anybody have any idea????
Re: [solved] Re: Set backgound color depending on model elements property [message #924931 is a reply to message #687937] Thu, 27 September 2012 04:44 Go to previous messageGo to next message
Eclipse UserFriend
in XXXEditPart.java there are two class.

XXXFigure and XXXEditPart.... where i should put Change Color();

Re: [solved] Re: Set backgound color depending on model elements property [message #936748 is a reply to message #687937] Mon, 08 October 2012 05:43 Go to previous message
Eclipse UserFriend
can you tell me a bit details about it?
Previous Topic:RCP Build Failed: /eclipse/features/org.eclipse.gmf.tooling.runtime.source
Next Topic:Date and timezones
Goto Forum:
  


Current Time: Tue May 06 04:16:25 EDT 2025

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

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

Back to the top