Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How do I change color in programmatic way
How do I change color in programmatic way [message #859692] Fri, 27 April 2012 19:15 Go to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Hi there,

I created my ChangeStateColorFeature which extends AbstractCustomFeature, registered it in feature provider. It all works well.

Right now I am trying to change color of state (a rectangle in diagram) in programmatic way, in other words, change its color without clicking any button. Firstly I was trying to get access to the context object which seems to have control of everything. Later I thought there should be some event system going on. Neither worked for me.

Could anyone give a brief idea of how to achieve this? Thanks in advance.

Sincerely,
Johnny
Re: How do I change color in programmatic way [message #865073 is a reply to message #859692] Mon, 30 April 2012 08:06 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
You should be able to use the CustomFeature you have build and construct an
CustomContext holding the information you need in your feature. The piece
you will have to build still is how the feature gets triggered. Graphiti
always uses a user interaction to start any functionality, but you might
e.g. use a thread that triggers the feature periodically; this could be done
e.g. by finding the diagram editor and using it's executeFeature() method (I
think available starting with 0.8) or getting the command stack from the
editing domain of the editor and executing it there.

Michael
Re: How do I change color in programmatic way [message #865745 is a reply to message #865073] Mon, 30 April 2012 14:49 Go to previous messageGo to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Thanks Michael.

Seems "by finding the diagram editor and using it's executeFeature() method" worth a try. I can find the diagram editor, however the question is how to get the Context object. Seems Graphiti gets context objects by tracking user interaction (e.g. mouse click).

Actually I made a little progress by loading pictogram models in ecore and updating color of certain graphical object from there. This way pictogram models do get correct update while the editor doesn't reflect the change unless reopen the file. I tried refreshContent(), refresh(), getContentEditPart().refresh() and quite a lot other ways but could not manage to refresh editor. I also tried reset editor input as well but got some thread control issue.

Any suggestions on either approach are welcomed and appreciated!

Thanks a lot.
Johnny
Re: How do I change color in programmatic way [message #868183 is a reply to message #865745] Tue, 01 May 2012 17:34 Go to previous messageGo to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Finally it works (I believe there must be a better way)

load pictogram model in ecore
update color in object hierarchy
save the pictogram model
// till now the diagram file is updated, the next is to update editor to present the color change visually
find the diagram editor from eclipse platform ui
find its resource
call unload() method on the pictogram model resource
// now color change is visual

what unload() does is
Clears the contents, errors, and warnings of the resource and marks it as unloaded.
It walks the content tree, and sets each content object to be a proxy. The resource will remain in the resource set,
and can be subsequently reloaded.

If anyone find a better solution, please shoot me a message. Thanks in advance!

Sincerely,
Johnny
Re: How do I change color in programmatic way [message #1065711 is a reply to message #868183] Thu, 27 June 2013 08:46 Go to previous message
anudeep arya is currently offline anudeep aryaFriend
Messages: 49
Registered: March 2013
Member
Hi All,

The solution above(by Micheal wenz) works but.once the selection is removed back from pictogram element it is not reverted back to its previous color.can you shed any views on this.

Regards,
Anudeep

[Updated on: Thu, 27 June 2013 08:48]

Report message to a moderator

Previous Topic:Newbie Question - Incremental Development - Updating GA's and Styles
Next Topic:Highlight a PictogramElement
Goto Forum:
  


Current Time: Fri Mar 29 01:27:07 GMT 2024

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

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

Back to the top