Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to change the color of elements programmatically
How to change the color of elements programmatically [message #692388] Mon, 04 July 2011 11:03 Go to next message
Neslepaks  is currently offline Neslepaks
Messages: 37
Registered: April 2011
Member
Hi,

How could I change the color of diagram elements programmatically in Papyrus 0.8.0?
Re: How to change the color of elements programmatically [message #692762 is a reply to message #692388] Tue, 05 July 2011 07:35 Go to previous messageGo to next message
Neslepaks  is currently offline Neslepaks
Messages: 37
Registered: April 2011
Member
I can get the color of ShapeImpl of the elements with a code like si.getFillColor() but setting the color with si.setFillColor(10000000) throws an exception:
java.lang.IllegalStateException: Cannot modify resource set without a write transaction

How should I do the write transaction?
Re: How to change the color of elements programmatically [message #692924 is a reply to message #692762] Tue, 05 July 2011 13:19 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles David
Messages: 138
Registered: July 2009
Senior Member
Le 05/07/2011 09:35, Neslepaks a écrit :
> I can get the color of ShapeImpl of the elements with a code like
> si.getFillColor() but setting the color with si.setFillColor(10000000)
> throws an exception:
> java.lang.IllegalStateException: Cannot modify resource set without a
> write transaction
>
> How should I do the write transaction?

Not tested, but probably something like:

TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(shape);
ted.getCommandStack().execute(new RecordingCommand(ted) {
protected void doExecute() {
shape.setFillColor(myColor);
}
});
Re: How to change the color of elements programmatically [message #694216 is a reply to message #692924] Fri, 08 July 2011 06:20 Go to previous messageGo to next message
Neslepaks  is currently offline Neslepaks
Messages: 37
Registered: April 2011
Member
Thanks a lot! That seems to do the trick.
Re: How to change the color of elements programmatically [message #694228 is a reply to message #694216] Fri, 08 July 2011 06:49 Go to previous messageGo to next message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Hi Neslepaks,

a general question on this:

Did you access the DI file or the notations file to reset the color of an
element on the canvas?

Could you maybe post a snippet how to start with this? Actually, it sounds
very interesting, actually, I do not have a starting point for this
activity.

Thanks a lot

Timothy

"Neslepaks" schrieb im Newsbeitrag news:iv671f$5o4$1@news.eclipse.org...

Thanks a lot! That seems to do the trick.
Re: How to change the color of elements programmatically [message #696185 is a reply to message #694228] Wed, 13 July 2011 12:49 Go to previous messageGo to next message
Neslepaks  is currently offline Neslepaks
Messages: 37
Registered: April 2011
Member
I didn't access any files.

This is the way I changed the color:

ServicesRegistry serviceRegistry;
ISashWindowsContainer container;

serviceRegistry = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();
container = ServiceUtils.getInstance().getISashWindowsContainer(serviceRegistry);

IEditorPart activeEditor = container.getActiveEditor();
EList el = ((UmlGmfDiagramEditor) activeEditor).getDiagram().getChildren();

Iterator<ShapeImpl> iter = el.iterator();
while (iter.hasNext())
{
    ShapeImpl si = iter.next();
    final org.eclipse.gmf.runtime.notation.Shape shape = 
	  (org.eclipse.gmf.runtime.notation.Shape) si;

    final int myColor = 10265827; //red
    TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(shape);
    ted.getCommandStack().execute(new RecordingCommand(ted) {
        protected void doExecute() {
            shape.setFillColor(myColor);
    }
    });
}
Re: How to change the color of elements programmatically [message #715776 is a reply to message #696185] Mon, 15 August 2011 14:01 Go to previous messageGo to next message
Timothy Marc is currently offline Timothy Marc
Messages: 547
Registered: July 2009
Senior Member
Hey Neslepleaks,

thanks for your hint. I tried it and it worked almost as desired, BUT: how
did you manage to updat the shape within on the canvas immediately. In my
case, the shape is update after I perform a subsequent change that causes
the canvas to refresh. I'm missing something like Diagram.refresh().

Could you point me to somewhere?

Timothy

"Neslepaks" schrieb im Newsbeitrag news:ivk3mu$uni$1@news.eclipse.org...

I didn't access any files.

This is the way I changed the color:


ServicesRegistry serviceRegistry;
ISashWindowsContainer container;

serviceRegistry =
ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();
container =
ServiceUtils.getInstance().getISashWindowsContainer(serviceRegistry);

IEditorPart activeEditor = container.getActiveEditor();
EList el = ((UmlGmfDiagramEditor) activeEditor).getDiagram().getChildren();

Iterator<ShapeImpl> iter = el.iterator();
while (iter.hasNext())
{
ShapeImpl si = iter.next();
final org.eclipse.gmf.runtime.notation.Shape shape =
(org.eclipse.gmf.runtime.notation.Shape) si;

final int myColor = 10265827; //red
TransactionalEditingDomain ted =
TransactionUtil.getEditingDomain(shape);
ted.getCommandStack().execute(new RecordingCommand(ted) {
protected void doExecute() {
shape.setFillColor(myColor);
}
});
}
Re: How to change the color of elements programmatically [message #716465 is a reply to message #715776] Wed, 17 August 2011 13:50 Go to previous messageGo to next message
Neslepaks  is currently offline Neslepaks
Messages: 37
Registered: April 2011
Member
Yes, the color update happens immediately and, as far as I know, we don't use any kind of refresh or update call for canvas separately.
Re: How to change the color of elements programmatically [message #1064819 is a reply to message #692388] Fri, 21 June 2013 08:40 Go to previous message
Dennis D. is currently offline Dennis D.
Messages: 23
Registered: April 2013
Junior Member
Hi,

is there a way to resize the figure, too?

Back in the past there were nice functions in com.cea.papyrus.diagraminterchange2.di2.GraphNode but they seem to have disappeared.

GraphNode di2Component = Di2Factory.eINSTANCE.createGraphNode();
			di2Component.setPosition(new Point(100, 100));
			di2Component.setSize(new Dimension(500, 300));			
			di2Component.setIsVisible(true);
			di2Component.setLineStyle("solid");
...


thanks
Previous Topic:How to generate a sequence diagram from an interaction?
Next Topic:Can't install Papyrus (plus extras) nightly build on Kepler base
Goto Forum:
  


Current Time: Fri Oct 31 06:38:37 GMT 2014

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

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