Auto update diagram [message #1735133] |
Wed, 15 June 2016 13:42  |
Eclipse User |
|
|
|
I have a project where we are displaying a table view of dynamic data.
I am able to manually right-click and 'refresh' the table but is there a way to have the table refresh automatically on a timer - say every 10 seconds?
|
|
|
|
|
|
|
|
|
|
Re: Auto update diagram [message #1737597 is a reply to message #1737500] |
Mon, 11 July 2016 03:29   |
Eclipse User |
|
|
|
Hi Christoph,
Le 08/07/2016 à 20:14, Christoph Rieger a écrit :
> Hello,
> I have a very similar issue and want to refresh a diagram
> programatically for dependent changes on other elements when changing
> one (not a table but that should be no harm).
Did you try to use the "Associated Elements Expression" available on
each mapping (see [1] for diagrams, [2] for tables, [3] for trees):
"Associated Semantic Elements. To associate more semantic elements to a
graphical element than just its semantic target, you can specify the
Associated Elements Expression (in the Advanced category). It will be
evaluated for each instance of the mapping in the context of the
semantic target, and should return a set of semantic elements. These
will be visible to the end-user in the Properties view when the
graphical element is selected, and any change on one of these elements
will trigger a refresh of the graphical element. This means that if you
use properties of other elements than the target to compute an element’s
label or conditional style (for example), you should make sure that
these other elements appear in the Associated Elements, otherwise the
label or style will not be properly refreshed when the elements are
modified."
I use basically the same code
> Session session = SessionManager.INSTANCE.getSession(obj); // the
> semantic EObject
> TransactionalEditingDomain domain =
> session.getTransactionalEditingDomain();
> CommandStack stack = domain.getCommandStack();
> for(DView view : session.getOwnedViews()){
> Command cmd = new RefreshRepresentationsCommand(domain, null,
> view.getOwnedRepresentations());
> domain.getCommandStack().execute(cmd);
> }
>
> I get the error
> java.lang.IllegalStateException: Cannot activate read/write transaction
> in read-only transaction context
> What am I doing wrong? From what I read the error relates to some EMF
> transaction problem (being called within a wrong context, potentially
> because issued at the end of the observed change to the first element?).
> I don't care if the representation is refreshed separately or a bit
> later but how can I make it work?
>
From which context do you call this code ? The message of your
IllegalStateException means that you are in a read-only transaction
context and so it cannot open a read-write transaction.
Do you try to react to changes on the diagram in post-commit or
something like that ?
> Actually I just want to get the refreshVisuals method called for my
> custom edit parts. This approach seemed like being "right" instead of
> trying to get those objects from some registry. But if there is some
> other way I'm happy with that too.
You might call the refreshVisuals method in post-commit, but Sirius's
figures will use the Sirius internal model computed from the Viewpoint
Specification Model (odesign) to do the configuration of figures.
This model is updated during the transaction by the tools behavior for
example or in reaction to semantic changes in pre-commit through several
means (pre-commits listeners, ModelChangeTriggers, ..).
The RefreshRepresentationsCommand will update the representation model,
then if some of them are opened, the edit pars will be refreshed in the
post-commit phase of the transaction.
If your custom figure is configured regarding the aspect of semantic
elements which are not the "displayed" semantic element, but will always
be the same elements, you should consider/try the "Associated Element
Expression". Sirius will listen the changes of those elements.
You might also try to do like Sirius and GMF for the semantic elements:
during the activate() method of the edit part they register some
pre/post commit listener to the DiagramEventBroker [4]
Otherwise it looks like you might need to call you refreshVisuals
methods from a ResourceSetListener configured as post-commit but you
will have to retrieve the your edit parts for the opened/active editor.
>
> Regards,
> Christoph
>
Regards
--
Maxime - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
--
[1]
https://www.eclipse.org/sirius/doc/specifier/diagrams/Diagrams.html#graphical_elements
[2]
https://www.eclipse.org/sirius/doc/specifier/tables/Tables.html#line_mappings
[3] https://www.eclipse.org/sirius/doc/specifier/trees/Trees.html#mappings
[4]
org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker.addNotificationListener(EObject,
NotificationListener)
[5] org.eclipse.gmf.runtime.diagram.ui.editparts.TreeEditPart
|
|
|
Re: Auto update diagram [message #1737978 is a reply to message #1737597] |
Thu, 14 July 2016 11:49  |
Eclipse User |
|
|
|
Hi Maxime,
thank you for the fast reply and suggestions, I now found a solution.
The underlying model itself was not changed (only deriving information). Therefore, Associated Semantic Elements seems not to be working as no change can be registered.
The other problem indeed was the position where I called this method. For example from within a set operation the transaction allows write access to the model.
With this in mind I would have probably managed to get my code working. My solution now was an even cleaner approach of modifying and integrating the the additional values in the metamodel instead of using some derived data structure outside of the actual model. This also solves the problem of previously unnoticed changes.
Thanks again,
Christoph
|
|
|
Powered by
FUDForum. Page generated in 0.04098 seconds