|
|
|
|
Re: change background color of a node dynamically [message #685734 is a reply to message #684489] |
Sat, 18 June 2011 08:23   |
Eclipse User |
|
|
|
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
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.05289 seconds