Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » How to refresh the opened Sirius Diagram Editor?
How to refresh the opened Sirius Diagram Editor? [message #1847665] Wed, 03 November 2021 10:21 Go to next message
María GM is currently offline María GMFriend
Messages: 6
Registered: November 2021
Junior Member
Hello everyone, I'm new into Eclipse Sirius.

I have a Sirius diagram editor opened which shows the content of an .ecore file as a class diagram. An external source modifies the .ecore associated to the representation but I can't find the way to refresh the current diagram (with aird extension) programmatically. Does anyone know how to do it?

I hope you can help me, thank you so much.
Regards, María.
Re: How to refresh the opened Sirius Diagram Editor? [message #1847803 is a reply to message #1847665] Mon, 08 November 2021 23:01 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello María,

You can refresh a representation (DRepresentation element from the graphical model ".aird") using the API: org.eclipse.sirius.business.api.dialect.DialectManager.INSTANCE.refresh(dRepresentation, new NullProgressMonitor()). Do you already have access with the DRepresentation element? If not, in which context do you want to trigger this refresh? Do you have the session? the editor?

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to refresh the opened Sirius Diagram Editor? [message #1847818 is a reply to message #1847803] Tue, 09 November 2021 08:21 Go to previous messageGo to next message
María GM is currently offline María GMFriend
Messages: 6
Registered: November 2021
Junior Member
Hello Steve,

Thanks for your reply.
Do you already have access with the DRepresentation element?
I don't know how to get the DRepresentation element.

If not, in which context do you want to trigger this refresh?
I want to triger the refresh when the content of the .ecore file associated to the .aird file changes, so that automatically new changes appear in the aird diagram.

Do you have the session? the editor?
I don't really know how to get the session or the editor.

It would be great if someone could help me maybe with little code snippets, I'm new into this.

Regards, María
Re: How to refresh the opened Sirius Diagram Editor? [message #1847832 is a reply to message #1847818] Tue, 09 November 2021 18:39 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

ok the context is a little bit vague for a proper answer, but you should start by having a plugin with a SessionManagerListener. This way when you open a sirius session, you can plugin your own IResourceChangeListener or ModelChangeTrigger in order to react to changes in your model and refresh your representation.
You can access the editor programmatically from the API PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
I would recommend to look at the JUnit tests [1] or other posts in the forum about these API. You should find many examples for your needs.

Best regards,
Steve

[1] https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius.tests.junit


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to refresh the opened Sirius Diagram Editor? [message #1848015 is a reply to message #1847832] Wed, 17 November 2021 13:09 Go to previous messageGo to next message
María GM is currently offline María GMFriend
Messages: 6
Registered: November 2021
Junior Member
Hello again, sorry for my late reply. I have taken into account your reply and I have a first approach but it throws IllegalStateException. The code I'm running is this one:


// In this line I modify the .ecore associated to the .aird diagram.
controller.elementsSelected("class", suggestion, fileName);

URI sessionResourceURI = URI.createPlatformResourceURI("/demo.emf/model/bookstore.aird", true);
Session createdSession = SessionManager.INSTANCE.getSession(sessionResourceURI, new NullProgressMonitor());
createdSession.open(new NullProgressMonitor());

DAnalysis root = (DAnalysis) createdSession.getSessionResource().getContents().get(0);
DView dView = root.getOwnedViews().get(0);
DRepresentation represnt = null;
for(DRepresentationDescriptor descrp : dView.getOwnedRepresentationDescriptors()) {
represnt = descrp.getRepresentation();
}
//DRepresentation dRepresentation = //(DRepresentation)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().ge//tActiveEditor();
DialectManager.INSTANCE.refresh(represnt, new NullProgressMonitor());
createdSession.save(new NullProgressMonitor());
createdSession.close(new NullProgressMonitor());


In the file attachments you can find the console output regarding the Exception thrown.

I hope you can help me.
Best regards, María.

[Updated on: Wed, 17 November 2021 13:09]

Report message to a moderator

Re: How to refresh the opened Sirius Diagram Editor? [message #1848036 is a reply to message #1848015] Wed, 17 November 2021 22:42 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello María,

No problem.

I did not think to mention it on my previous post, but Sirius executes modifications to the models in a transactional context in order to have undo/redo and rollbacks in case of exceptions thrown during a command execution. We rely on the framework EMF Transaction[1] for this part. Any model modification needs to be executed through a RecordingCommand on the editing domain.

Back to your case, when you call DialectManager.INSTANCE.refresh this means that a representation is refreshed and as a consequence the graphical model (.aird file) will probably be modified to display or remove diagram elements. You need to wrap this call in a RecordingCommand like this:
createdSession.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(createdSession.getTransactionalEditingDomain()) {
            @Override
            protected void doExecute() {
                        DialectManager.INSTANCE.refresh(represnt, new NullProgressMonitor());
            }
});


Best regards,
Steve

[1] https://www.eclipse.org/emf-transaction/


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Wed, 17 November 2021 22:48]

Report message to a moderator

Re: How to refresh the opened Sirius Diagram Editor? [message #1848042 is a reply to message #1848036] Thu, 18 November 2021 08:49 Go to previous messageGo to next message
María GM is currently offline María GMFriend
Messages: 6
Registered: November 2021
Junior Member
Hello again Steve, thanks for your support.
I have added your code snippet to my code and now it refreshes the .aird file but the graphical model (in my case it's a class diagram) doesn't get refreshed.
If I add a new class to the .ecore file, that class doesn't appear in the class diagram.
Right now my code is this one:

// In this line I modify the .ecore associated to the .aird diagram.
controller.elementsSelected("class", suggestion, fileName);

URI sessionResourceURI = URI.createPlatformResourceURI("/demo.emf/model/bookstore.aird", true);
Session createdSession = SessionManager.INSTANCE.getSession(sessionResourceURI, new NullProgressMonitor());
createdSession.open(new NullProgressMonitor());

DAnalysis root = (DAnalysis) createdSession.getSessionResource().getContents().get(0);
DView dView = root.getOwnedViews().get(0);
//DRepresentation myRepresentation = (DRepresentation) dView.getOwnedRepresentationDescriptors().get(0);
final DRepresentation represnt = dView.getOwnedRepresentationDescriptors().get(0).getRepresentation();

//DRepresentation dRepresentation = (DRepresentation) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
TransactionalEditingDomain transactional = createdSession.getTransactionalEditingDomain();
if(transactional != null) {
System.out.println("Transactional not null");
transactional.getCommandStack().execute(new RecordingCommand(createdSession.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
DialectManager.INSTANCE.refresh(represnt, new NullProgressMonitor());
}
});
}
/*createdSession.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(createdSession.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
DialectManager.INSTANCE.refresh(represnt, new NullProgressMonitor());
}
});*/
createdSession.save(new NullProgressMonitor());
createdSession.close(new NullProgressMonitor());
return true;


After executing that piece of code it shows me the screen that you can find attached in the file attachments section instead of showing the aird class diagram.

I hope you can help me solve this issue.
Thanks again, best regards.
María.
Re: How to refresh the opened Sirius Diagram Editor? [message #1848061 is a reply to message #1848042] Thu, 18 November 2021 18:58 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello María,

I am not sure to follow, so stop me if I am wrong. You have this code snippet in a custom action (I do not know how you trigger it), that modifies your semantic model, refresh the diagram and finally save and close the session. It does not open the diagram in an editor (and by the way the refresh of the diagram does not require an editor).
On your screenshot, we can see an Aird editor presenting the session content. As in your code snippet, the session is closed, I can only assume that you have this editor because you opened the session in the demo.emf.aird project.

If you want to modfify your code snippet to also open the diagram in an editor, first you will need to remove your "createdSession.close(new NullProgressMonitor());" statement (or that will close the editor at the end of your script). Then you need to call the following API:
org.eclipse.sirius.ui.business.api.dialect.DialectUIManager.INSTANCE.openEditor(createdSession, dRepresentation , new NullProgressMonitor());


Is this what you wanted to do? You can also look in Sirius JUnit test how these APIs are used if you want more examples.

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to refresh the opened Sirius Diagram Editor? [message #1848091 is a reply to message #1848061] Fri, 19 November 2021 12:38 Go to previous messageGo to next message
Hakan  Yüksek is currently offline Hakan YüksekFriend
Messages: 22
Registered: October 2021
Junior Member
Steve Monnier wrote on Thu, 18 November 2021 18:58
Hello María,

I am not sure to follow, so stop me if I am wrong. You have this code snippet in a custom action (I do not know how you trigger it), that modifies your semantic model, refresh the diagram and finally save and close the session. It does not open the diagram in an editor (and by the way the refresh of the diagram does not require an editor).
On your screenshot, we can see an Aird editor presenting the session content. As in your code snippet, the session is closed, I can only assume that you have this editor because you opened the session in the demo.emf.aird project.

If you want to modfify your code snippet to also open the diagram in an editor, first you will need to remove your "createdSession.close(new NullProgressMonitor());" statement (or that will close the editor at the end of your script). Then you need to call the following API:
org.eclipse.sirius.ui.business.api.dialect.DialectUIManager.INSTANCE.openEditor(createdSession, dRepresentation , new NullProgressMonitor());


Is this what you wanted to do? You can also look in Sirius JUnit test how these APIs are used if you want more examples.

Best regards,
Steve


Hi Steve,

I am also new into the Eclipse Sirius. I have the similar problem. Some external applications can modify the model file. But in this time, If I don't refresh manually model file, I can not see differences. My question is how can I refresh the model file for periodically?



Re: How to refresh the opened Sirius Diagram Editor? [message #1848103 is a reply to message #1848091] Fri, 19 November 2021 21:58 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hi Hakan,

I guess it depends on how external it is. If it is another application in your Eclipse, then what I mentioned in a previous comment about IResourceChangeListener (you have many implementation, look at WorkspaceListener for instance) will allow you to be triggered when the resource is modified.
If your external application that modifies the model is not in Eclipse, then I guess that I would try something with a org.eclipse.core.runtime.jobs.Job (we have jobs in our tests if you want some examples) where in the run method it would call the API org.eclipse.sirius.ecore.extender.tool.api.ModelUtils.load(URI, ResourceSet) and then schedule itself again with a timer. I have never tried it, I do not know how you would handle conflict if you modified the project from Sirius and have this reload process triggered though. I think you would have less issues in the long run if you can trigger an import wizard by a contextual action from your Sirius modeling project.

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to refresh the opened Sirius Diagram Editor? [message #1848134 is a reply to message #1848061] Mon, 22 November 2021 12:14 Go to previous messageGo to next message
María GM is currently offline María GMFriend
Messages: 6
Registered: November 2021
Junior Member
Steve Monnier wrote on Thu, 18 November 2021 18:58
Hello María,

I am not sure to follow, so stop me if I am wrong. You have this code snippet in a custom action (I do not know how you trigger it), that modifies your semantic model, refresh the diagram and finally save and close the session. It does not open the diagram in an editor (and by the way the refresh of the diagram does not require an editor).
On your screenshot, we can see an Aird editor presenting the session content. As in your code snippet, the session is closed, I can only assume that you have this editor because you opened the session in the demo.emf.aird project.

If you want to modfify your code snippet to also open the diagram in an editor, first you will need to remove your "createdSession.close(new NullProgressMonitor());" statement (or that will close the editor at the end of your script). Then you need to call the following API:
org.eclipse.sirius.ui.business.api.dialect.DialectUIManager.INSTANCE.openEditor(createdSession, dRepresentation , new NullProgressMonitor());


Is this what you wanted to do? You can also look in Sirius JUnit test how these APIs are used if you want more examples.

Best regards,
Steve



Hi again Steve,
I have tried what you mentioned (adding the openEditor call) and I have also looked in Sirius JUnit test to try to help me.

Right now, I have the following code snippet that is triggered when I click a button. When I click in that button, the opened editor should refresh and show a new Eclass with the name I selected. In my ecore file I create a new Eclass with the selected name. I would like that the editor gets refreshed with the new class so that I can see a class called Bookshop in the class diagram.

In a previous method I have the add button and its handler:

Button buttonAdd = new Button(buttonsGroup, SWT.PUSH);
buttonAdd.setSize(50, 50);
buttonAdd.setText("Add");[code][/code]
buttonAdd.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
	        switch (e.type) {
		        case SWT.Selection:
  	                System.out.println("Button Add pressed");
			updateModelRepresentation(suggestion);
		          container.getParent().getShell().close();
		          break;
		}
	 }
});


Here you can see the content of the function updateModelRepresentation:

private void updateModelRepresentation(String suggestion) {
		String fileName = "/home/maria/Escritorio/demo.projects/demo.emf/model/bookstore.ecore";
		controller.elementsSelected("class", suggestion, fileName);
		
		URI sessionResourceURI = URI.createPlatformResourceURI("/demo.emf/model/bookstore.aird", true);
		Session createdSession = SessionManager.INSTANCE.getSession(sessionResourceURI, new NullProgressMonitor());
		createdSession.open(new NullProgressMonitor());
		
		DAnalysis root = (DAnalysis) createdSession.getSessionResource().getContents().get(0);
		DView dView = root.getOwnedViews().get(0);
		
		final DRepresentation represnt = dView.getOwnedRepresentationDescriptors().get(0).getRepresentation();
		
		
		TransactionalEditingDomain transactional = createdSession.getTransactionalEditingDomain();
		if(transactional != null) {
			System.out.println("Transactional not null");
			DialectEditor editor = (DialectEditor) org.eclipse.sirius.ui.business.api.dialect.DialectUIManager.INSTANCE.openEditor(createdSession, represnt , new NullProgressMonitor());

			transactional.getCommandStack().execute(new RecordingCommand(createdSession.getTransactionalEditingDomain()) {
				@Override
				protected void doExecute() {
				     DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor());
				}
			});
		}
		createdSession.save(new NullProgressMonitor());	
	}


When I click the add button Eclipse shows me the following without ending the process of refreshing (you can find the screenshot in the file attachments). Maybe it's because I'm not placing the calls to the functions in the right place or that I don't really understand in which order I have to call functions to make it work.

I hope it helps to clarify and to solve this problem.

Thanks again, María.
Re: How to refresh the opened Sirius Diagram Editor? [message #1848157 is a reply to message #1848134] Mon, 22 November 2021 19:22 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hi María,

Here you refresh the representation from the UI action:
transactional.getCommandStack().execute(new RecordingCommand(createdSession.getTransactionalEditingDomain()) {
				@Override
				protected void doExecute() {
				     DialectUIManager.INSTANCE.refreshEditor(editor, new NullProgressMonitor());
				}
			});


Before, you did it from the API that did not use the UI:
DialectManager.INSTANCE.refresh(represnt, new NullProgressMonitor());


I am guessing that when you trigger DialectUIManager.INSTANCE.refreshEditor, at one point it tries to get the lock on the UI thread that is already taken by your buttonAdd "handleEvent" method resulting in a deadlock.
In your case, you can just use the DialectManager.INSTANCE.refresh before opening the editor, it does the same thing as DialectUIManager.INSTANCE.refreshEditor in the end.

Seeing your screenshot, I wanted to suggest a different approach. I see your window with buttons where you can create model elements and I guess this is your external source that modifies the .ecore. I do not know if this is part of a larger application, but you could quickly have a similar result using a popup action[1] that has a model operation "Open Dialog"[2]. In that dialog, you can add all the widgets you need to create the buttons you have on your screenshot.
You can also design your own properties view [3] with the same widgets so it is directly accessible without needing a popup.
The main advantage is that as you would execute these actions in the context of the Sirius session, it would refresh automatically, you would not have the need for all that custom code that open the session and refresh a diagram.

Best regards,
Steve
[1] https://www.eclipse.org/sirius/doc/specifier/diagrams/Diagrams.html#tools_specification
[2] https://www.eclipse.org/sirius/doc/specifier/general/Model_Operations.html#dialog
[3] https://www.eclipse.org/sirius/doc/specifier/properties/Properties_View_Description.html


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: How to refresh the opened Sirius Diagram Editor? [message #1848343 is a reply to message #1848157] Mon, 29 November 2021 09:05 Go to previous messageGo to next message
María GM is currently offline María GMFriend
Messages: 6
Registered: November 2021
Junior Member
Hello again Steve,

First of all, thanks for your reply.

I still haven't achieved what I want to but I think that your explanations are quite useful. I will continue doing some research more and in case I get stucked, I'll ask again.

Best regards,
María.
Re: How to refresh the opened Sirius Diagram Editor? [message #1848366 is a reply to message #1848343] Mon, 29 November 2021 18:17 Go to previous message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hi María,

I am happy to help. In you research, you can look at the different tools and model operations Sirius offers (check at the Sirius help, or the links I previously gave). I hope it can help the application you want to realise and its Sirius integration.

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Printing diagrams blurs SVG Graphics
Next Topic:viewpoint specification model can not be loaded
Goto Forum:
  


Current Time: Wed Oct 09 19:23:14 GMT 2024

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

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

Back to the top