Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » change background color of a node dynamically
icon7.gif  change background color of a node dynamically [message #684383] Wed, 15 June 2011 14:09 Go to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Hi, I have a problem about changing the background color of a node dynamically. I know it has been discussed in the community. But I still don't figure out how I can get it. In my model, this is a node called Mark with an attribute called Color. Every time when I changed its value, the background color of Mark should be changed also.

I have followed several artical in the community. Someone said we should override handleNotificationEvent() OR notifychanged() function. I'm not sure about it. And what's more, how can I get the Background of a node and change it in the function precedent??

Do you have any ideas? Thank you in advance. Smile

Best regards,

Vincent
Re: change background color of a node dynamically [message #684458 is a reply to message #684383] Wed, 15 June 2011 15:00 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hi,

Is the mark really part of your semantic model? Because the GMF notation model already handles the colors of nodes. You should remove this from your domain model, and rely on the color attribute provided in the GMF notation model.

HTH

Le 15/06/2011 16:09, forums-noreply@eclipse.org a écrit :
> Hi, I have a problem about changing the background color of a node dynamically. I know it has been discussed in the community. But I still don't figure out how I can get it. In my model, this is a node called Mark with an attribute called Color. Every time when I changed its value, the background color of Mark should be changed also.
>
> I have followed several artical in the community. Someone said we should override handleNotificationEvent() OR notifychanged() function. I'm not sure about it. And what's more, how can I get the Background of a node and change it in the function precedent??
>
> Do you have any ideas? Thank you in advance. :)
> Best regards,
>
> Vincent
>


--
Mickael Istria -- BonitaSoft S.A.
http://www.bonitasoft.com/products/BPM_download.php
Eclipse Community Award 2011: Best Modeling Tool
Re: change background color of a node dynamically [message #684461 is a reply to message #684458] Wed, 15 June 2011 15:52 Go to previous messageGo to next message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Hi, thank you for your help. Actually, in my model, Mark is a compartment node of Place (another node) and is placed in the Place. I want to change the background color of a mark in run time, so I add a background color for Mark in .gmfgraph file. Now I should develop the code to change it dynamically. Do you have any ideas? Do I go to the wrong direction? Thank you

Vincent
Re: change background color of a node dynamically [message #684489 is a reply to message #684461] Wed, 15 June 2011 16:47 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

I think you should not have the color in your domain model (ecore). The color is included in the GMF Notation model, and GMF editors provide tools to handle this background color. If you generated your diagram editor with GMF-Tooling, you should have an "appearance" tab in your properties view that you can use to change the color of nodes and compartments (I am not really sure about how it behaves with compartments). Take a look at the code behind this tab to see how to handle a color change programatically.

HTH

Le 15/06/2011 17:52, forums-noreply@eclipse.org a écrit :
> Hi, thank you for your help. Actually, in my model, Mark is a compartment node of Place (another node) and is placed in the Place. I want to change the background color of a mark in run time, so I add a background color for Mark in .gmfgraph file. Now I should develop the code to change it dynamically. Do you have any ideas? Do I go to the wrong direction? Thank you
>
> Vincent


--
Mickael Istria -- BonitaSoft S.A.
http://www.bonitasoft.com/products/BPM_download.php
Eclipse Community Award 2011: Best Modeling Tool
Re: change background color of a node dynamically [message #685734 is a reply to message #684489] Sat, 18 June 2011 12:23 Go to previous messageGo to next message
Ivar Refsdal is currently offline Ivar RefsdalFriend
Messages: 24
Registered: May 2011
Junior Member
Hi Vincent,

did you solve this? I think your direction is good.
Does the new default background color show up in the editor?
If so it should also be possible to change dynamically.

I'm not sure from what context you want to change the color,
but if you have access to your XXXEditPart, it should be fine.
If you want this with a context menu (popupmenu), see one of the GMF
tutorials.

I did something like this:

> GraphicalEditPart part = ....;
> TransactionalEditingDomain ted = part.getEditingDomain();
> CompoundCommand cc = new CompoundCommand();
> View v = (View) part.getModel();
> if (v instanceof FillStyle) {
> SetCommand cmd = new SetCommand(ted, v, NotationPackage.Literals.FILL_STYLE__FILL_COLOR, 0xffaabb);
> cc.append(cmd);
> }
> ted.getCommandStack().execute(cc);

You can have look at org.eclipse.gmf.runtime.notation
model/notation.ecore for more details.

The class hierarchy looks something like this:
View -> EModelElement
Node -> View
Style
FillStyle -> Style
fillColor
ShapeStyle -> FillStyle, ...
Shape -> Node, ShapeStyle

Somehow, the gmf notation view representing the figure should be a Shape.
I'm not sure how/where the exact mapping is...
Also I cannot really find where the Shape/ShapeImpl is created.
Anybody knows?

If you want to see how the default colors/settings are created, have a
look at XXXViewProvider's createXXX_XXXX functions.
Example:
> final IPreferenceStore prefStore = (IPreferenceStore) XXXXEditorPlugin.DIAGRAM_PREFERENCES_HINT.getPreferenceStore();
> org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_FILL_COLOR);

Hope this helps,
Best,
Ivar


Mickael Istria wrote, on 06/15/2011 06:47 PM:
> I think you should not have the color in your domain model (ecore). The
> color is included in the GMF Notation model, and GMF editors provide
> tools to handle this background color. If you generated your diagram
> editor with GMF-Tooling, you should have an "appearance" tab in your
> properties view that you can use to change the color of nodes and
> compartments (I am not really sure about how it behaves with
> compartments). Take a look at the code behind this tab to see how to
> handle a color change programatically.
>
> HTH
>
> Le 15/06/2011 17:52, forums-noreply@eclipse.org a écrit :
>> Hi, thank you for your help. Actually, in my model, Mark is a
>> compartment node of Place (another node) and is placed in the Place. I
>> want to change the background color of a mark in run time, so I add a
>> background color for Mark in .gmfgraph file. Now I should develop the
>> code to change it dynamically. Do you have any ideas? Do I go to the
>> wrong direction? Thank you
>>
>> Vincent
>
>
Re: change background color of a node dynamically [message #685859 is a reply to message #685734] Mon, 20 June 2011 12:26 Go to previous message
vincent988923 is currently offline vincent988923Friend
Messages: 29
Registered: June 2011
Junior Member
Hi,Ivar. I'm appreciated of your reply. I understand more right now. But I still have some problem.

1.<<GraphicalEditPart part = ....;>> can you precise a little? part = ?? and Where should I put your code??
2.About the GMF notation, I don't really understand, I have seen a solution which used the notation. It seems a XML file which designs every node's attributes. But I can't find it also. And you have mentioned Shape/ShapeImpl file. I have found some files like this in XXX.src.impl including all the implementations of the interfaces.

Thank you for your help. I'm waiting for your answers. Smile

best regards,
Vincent

[Updated on: Mon, 20 June 2011 12:28]

Report message to a moderator

Previous Topic:HTML table in GEF
Next Topic:Multiple GMF Editors: modify related diagrams by code
Goto Forum:
  


Current Time: Tue Apr 23 11:04:36 GMT 2024

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

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

Back to the top