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 06:21  |
Eclipse User |
|
|
|
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 #1848015 is a reply to message #1847832] |
Wed, 17 November 2021 08:09   |
Eclipse User |
|
|
|
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 08:09] by Moderator
|
|
| |
Re: How to refresh the opened Sirius Diagram Editor? [message #1848042 is a reply to message #1848036] |
Thu, 18 November 2021 03:49   |
Eclipse User |
|
|
|
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 13:58   |
Eclipse User |
|
|
|
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
|
|
|
Re: How to refresh the opened Sirius Diagram Editor? [message #1848091 is a reply to message #1848061] |
Fri, 19 November 2021 07:38   |
Eclipse User |
|
|
|
Steve Monnier wrote on Thu, 18 November 2021 18:58Hello 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 #1848134 is a reply to message #1848061] |
Mon, 22 November 2021 07:14   |
Eclipse User |
|
|
|
Steve Monnier wrote on Thu, 18 November 2021 18:58Hello 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 14:22   |
Eclipse User |
|
|
|
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
|
|
| |
Re: How to refresh the opened Sirius Diagram Editor? [message #1848366 is a reply to message #1848343] |
Mon, 29 November 2021 13:17  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Tue May 13 19:31:33 EDT 2025
Powered by FUDForum. Page generated in 0.04261 seconds
|