Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Programmatically change border color
Programmatically change border color [message #1717795] Wed, 16 December 2015 18:51 Go to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Hi all,

I am trying to change programmatically the border color of an element. The reason why I am doing this is because I need to update the color using an external java action.

I am using a code like this now (see below) and it works pretty well EXCEPT that it changes the color for ALL the elements with the same style. I am wondering how I can change the color ONLY for the selected element. Any hint/help for doing it?

Thanks!



Node node = (Node) dnode.getTarget();
System.out.println ("[ImpactAction] node=" + node);

Style style = dnode.getStyle();
SquareDescription sd = (SquareDescription)style.getDescription();

ColorDescription cd = sd.getBorderColor();
SystemColor sc = (SystemColor) cd;
LineStyle ls = sd.getBorderLineStyle();

sc.setBlue(0);
sc.setGreen(255);
sc.setRed(0);
sd.setBorderColor(sc);
sd.setWidth(10);
sd.setBorderSizeComputationExpression("2");

Re: Programmatically change border color [message #1718622 is a reply to message #1717795] Mon, 28 December 2015 11:08 Go to previous message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi Julien,

ColorDescription is a EClass from odesign metamodel, which is used only
when defining your modeler, your need is about customize the border
color from diagram editor. By hand this can be done through properties
view or tabbar and after customization the "Reset style properties to
default values" action is enabled because the style is noted customized
in aird resource using Customizable.customFeatures attribute.
Then to do the same programmatically :

1. you get the BorderedStyle of your node as in the beginning of your code
2. Set the wished color
3. Add the customized feature in BorderedStyle.customFeatures list by
calling
borderStyle.getCustomFeatures().add(DiagramPackage.Literals.BORDERED_STYLE__BORDER_COLOR.getName());

Best Regards.

Le 16/12/2015 19:51, Julien Delange a écrit :
> Hi all,
>
> I am trying to change programmatically the border color of an element.
> The reason why I am doing this is because I need to update the color
> using an external java action.
>
> I am using a code like this now (see below) and it works pretty well
> EXCEPT that it changes the color for ALL the elements with the same
> style. I am wondering how I can change the color ONLY for the selected
> element. Any hint/help for doing it?
>
> Thanks!
>
>
>
> Node node = (Node) dnode.getTarget();
> System.out.println ("[ImpactAction] node=" + node);
>
> Style style = dnode.getStyle();
> SquareDescription sd =
> (SquareDescription)style.getDescription();
>
> ColorDescription cd = sd.getBorderColor();
> SystemColor sc = (SystemColor) cd;
> LineStyle ls = sd.getBorderLineStyle();
>
> sc.setBlue(0);
> sc.setGreen(255);
> sc.setRed(0);
> sd.setBorderColor(sc);
> sd.setWidth(10);
> sd.setBorderSizeComputationExpression("2");
>
>



--
Esteban Dugueperoux - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Label Expression with String
Next Topic:Expand a newly created Tree element from the create tool
Goto Forum:
  


Current Time: Mon Jan 25 02:33:51 GMT 2021

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

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

Back to the top