|
|
|
Re: Auto update diagram [message #1736044 is a reply to message #1735797] |
Fri, 24 June 2016 14:57 |
|
Hi,
How do you modify your model ?
Not that if you modify the model by executing a command on the command
stack of the editing domain of the current Sirius session, Sirius will
refresh all its opened editors and take your modifications into account.
Regards
Le 22/06/2016 à 20:44, Man Garg a écrit :
> Thank you for the reply Julien,
>
> I have 'Automatic Refresh' checked. The issue is that the underlying
> data changes (attributes of the model items) and I need to run a thread
> that would periodically read the attributes and refresh the visible model.
> Based on the attribute values I have decorations/styles/labels that
> should change automatically.
> I am trying to find how/where such automated task can be inserted.
>
> Thanks,
>
--
Maxime - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Re: Auto update diagram [message #1736157 is a reply to message #1736068] |
Mon, 27 June 2016 07:56 |
|
Hi,
Le 24/06/2016 à 22:22, Man Garg a écrit :
> Thank you Maxim for helping,
> Currently I am updating the underlying model by a worker thread that
> runs under the hood. This is because I am polling for changes (to the
> server) every n-seconds.
How do you initialize this worker ?
Do you pass your model to update as a parameter somewhere ?
I think you might just pass the session as an additional parameter.
Then you just have to encapsulate your changes in a
org.eclipse.emf.transaction.RecordingCommand.
To get your session from a semantic element:
org.eclipse.sirius.business.api.session.SessionManager.eInstance().getSession(semanticObjectOrSemanticResource)
Then from a session, after checking that is still opened:
session.getTransactionalEditingDomain().getCommandStack().execute(yourCommand);
Another way might be to use
org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(semanticElement).getCommandStack().execute(vcc);
>
> I see you comment about command stack. Is it possible to insert a
> command in the command stack by a timer so that it executes every
> n-seconds. That way I can update the model in the command-execution. If
> yes please advice how to do that.
You might configure your worker or a org.eclipse.core.runtime.jobs.Job
to be able to poll the changes every n-second and then execute your
update command.
Note that you might decide to create/stop your worker/job only when the
Sirius session is opened on your model using a SessionListener on the
SessionManager: you can react to session creation/open/close/.. events.
>
> Thanks
>
> Man M Garg
Regards,
--
Maxime - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
|
Re: Auto update diagram [message #1737597 is a reply to message #1737500] |
Mon, 11 July 2016 07:29 |
|
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
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Powered by
FUDForum. Page generated in 0.03779 seconds