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.
Michael Wenz Messages: 1640 Registered: July 2009 Location: Walldorf, Germany
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.
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!
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!