Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Auto update diagram(How to automatically update table view)
Auto update diagram [message #1735133] Wed, 15 June 2016 17:42 Go to next message
Man Garg is currently offline Man GargFriend
Messages: 4
Registered: June 2016
Junior Member
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 #1735645 is a reply to message #1735133] Tue, 21 June 2016 14:50 Go to previous messageGo to next message
Julien Dupont is currently offline Julien DupontFriend
Messages: 172
Registered: July 2009
Senior Member
Hi,

Why don't you used the automatic refresh
(Help/Preferences/Sirius->Automatic Refresh) ?

Did you have other product that modify your semantic model?

Regards,

--
Julien - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Auto update diagram [message #1735797 is a reply to message #1735645] Wed, 22 June 2016 18:44 Go to previous messageGo to next message
Man Garg is currently offline Man GargFriend
Messages: 4
Registered: June 2016
Junior Member
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,
Re: Auto update diagram [message #1736044 is a reply to message #1735797] Fri, 24 June 2016 14:57 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
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 #1736068 is a reply to message #1736044] Fri, 24 June 2016 20:22 Go to previous messageGo to next message
Man Garg is currently offline Man GargFriend
Messages: 4
Registered: June 2016
Junior Member
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.

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.

Thanks

Man M Garg
Re: Auto update diagram [message #1736157 is a reply to message #1736068] Mon, 27 June 2016 07:56 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
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 #1737284 is a reply to message #1736157] Wed, 06 July 2016 22:43 Go to previous messageGo to next message
Man Garg is currently offline Man GargFriend
Messages: 4
Registered: June 2016
Junior Member
Thank you Maxime,

I am able to get the diagram to refresh by sending a RefreshRepresentationsCommand. here is the code if it helps someone:

TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(((DSemanticDecorator)rep).getTarget());
Command cmd = new RefreshRepresentationsCommand(domain, null, rep);//domain, null, DialectManager.INSTANCE.getAllRepresentations(session));
if (cmd.canExecute()) {
domain.getCommandStack().execute(cmd);
}
Re: Auto update diagram [message #1737500 is a reply to message #1737284] Fri, 08 July 2016 18:14 Go to previous messageGo to next message
Christoph Rieger is currently offline Christoph RiegerFriend
Messages: 9
Registered: April 2016
Junior Member
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). 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?

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.

Regards,
Christoph
Re: Auto update diagram [message #1737597 is a reply to message #1737500] Mon, 11 July 2016 07:29 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
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
Re: Auto update diagram [message #1737978 is a reply to message #1737597] Thu, 14 July 2016 15:49 Go to previous message
Christoph Rieger is currently offline Christoph RiegerFriend
Messages: 9
Registered: April 2016
Junior Member
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
Previous Topic:performSetCommand not using own model ItemProviderAdapter
Next Topic:Set the attribute value through java method call
Goto Forum:
  


Current Time: Thu Apr 25 05:09:23 GMT 2024

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

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

Back to the top