Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 22:46 Go to next message
Marc Moser is currently offline Marc MoserFriend
Messages: 66
Registered: July 2009
Member
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 14:45 Go to previous messageGo to next message
Marc Moser is currently offline Marc MoserFriend
Messages: 66
Registered: July 2009
Member
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 20:32 Go to previous messageGo to next message
Ivar Refsdal is currently offline Ivar RefsdalFriend
Messages: 24
Registered: May 2011
Junior Member
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 11:17 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
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 11:44 Go to previous messageGo to next message
Ivar Refsdal is currently offline Ivar RefsdalFriend
Messages: 24
Registered: May 2011
Junior Member
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 14:50 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
@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 14:53]

Report message to a moderator

Re: [solved] Re: Set backgound color depending on model elements property [message #687956 is a reply to message #687937] Thu, 23 June 2011 15:12 Go to previous messageGo to next message
Ivar Refsdal is currently offline Ivar RefsdalFriend
Messages: 24
Registered: May 2011
Junior Member
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 15:23 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
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 17:45 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 579
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

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,


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: [solved] Re: Set backgound color depending on model elements property [message #908861 is a reply to message #687956] Thu, 06 September 2012 06:11 Go to previous messageGo to next message
Iqbal Hossain is currently offline Iqbal HossainFriend
Messages: 101
Registered: May 2011
Location: Bangladesh
Senior Member
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 06:37 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 579
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

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,


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: [solved] Re: Set backgound color depending on model elements property [message #909515 is a reply to message #687937] Fri, 07 September 2012 09:07 Go to previous messageGo to next message
Iqbal Hossain is currently offline Iqbal HossainFriend
Messages: 101
Registered: May 2011
Location: Bangladesh
Senior Member
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 09:10 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 579
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

and resolveSemanticElement().packetSize with the appropriated cast?

Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: [solved] Re: Set backgound color depending on model elements property [message #909525 is a reply to message #909518] Fri, 07 September 2012 09:17 Go to previous messageGo to next message
Iqbal Hossain is currently offline Iqbal HossainFriend
Messages: 101
Registered: May 2011
Location: Bangladesh
Senior Member
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 09:19 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien PupierFriend
Messages: 579
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

on which class did you add the packetSize attribute?

Regards,


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: [solved] Re: Set backgound color depending on model elements property [message #909531 is a reply to message #909528] Fri, 07 September 2012 09:28 Go to previous messageGo to next message
Iqbal Hossain is currently offline Iqbal HossainFriend
Messages: 101
Registered: May 2011
Location: Bangladesh
Senior Member
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 09:24 Go to previous messageGo to next message
Iqbal Hossain is currently offline Iqbal HossainFriend
Messages: 101
Registered: May 2011
Location: Bangladesh
Senior Member
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 08:44 Go to previous messageGo to next message
Iqbal Hossain is currently offline Iqbal HossainFriend
Messages: 101
Registered: May 2011
Location: Bangladesh
Senior Member
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 09:43 Go to previous message
Iqbal Hossain is currently offline Iqbal HossainFriend
Messages: 101
Registered: May 2011
Location: Bangladesh
Senior Member
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: Sat Dec 20 13:41:49 GMT 2014

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

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