Home » Eclipse Projects » Sirius » Open Diagram programmatically
|
Re: Open Diagram programmatically [message #1228068 is a reply to message #1227183] |
Mon, 06 January 2014 10:46 |
|
Hi Camilo,
you can use:
- the org.eclipse.sirius.business.api.dialect.DialectManager to create,
delete, copy (etc...) representations (e.g. DDiagrams, DTables...)
- the org.eclipse.sirius.ui.business.api.dialect.DialectUIManager to
open and close editors.
So to open a diagram programmatically, use
DialectUIManager.INSTANCE.openEditor(mySession, myDiagram,
myProgressMonitor);
You may use a NullProgressMonitor if you are not interested in giving
progression feedback to end-user.
Best regards, and please let my know if you have follow-up questions,
Alex
Le 03/01/2014 20:48, Camilo Alvarez a écrit :
> Hi,
>
> How can I open a diagram programmatically?
>
> Thanks,
> Camilo.
>
>
|
|
|
Re: Open Diagram programmatically [message #1239387 is a reply to message #1228068] |
Tue, 04 February 2014 04:17 |
Camilo Alvarez Messages: 5 Registered: July 2013 |
Junior Member |
|
|
Hi Alex,
Thank you for the answer.
I implemented the functionality looking into the source code of the Model Explorer, using this code:
org.eclipse.sirius.ui.business.api.session.SessionEditorInput sEditor =
new SessionEditorInput(diagramURI, "New Diagram", null);
IEditorPart openEditor = IDE.openEditor(page, sEditor,"org.eclipse.sirius.diagram.part.SiriusDiagramEditorID", true);
Im trying to use the DialectUIManager
diagramURI = URI.createURI("/" + dFile.getProject().getName() + "/" + dFile.getProjectRelativePath().toOSString());
ResourceSet rs = new ResourceSetImpl();
Resource rsc = rs.createResource(diagramURI);
try {
load(null);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
DAnalysis root = (DAnalysis) rsc.getContents().get(0);
DView dView = root.getOwnedViews().get(0);
DRepresentation rep = dView.getOwnedRepresentations().get(0);
DialectUIManager.INSTANCE.openEditor(SessionManager.INSTANCE.getSession(diagramURI, new NullProgressMonitor()), rep, new NullProgressMonitor());
but i get this exception
!ENTRY org.eclipse.sirius 4 0 2014-02-03 22:26:16.667
!MESSAGE Impossible to find an interpreter - Could not find a session for model element : org.eclipse.sirius.viewpoint.impl.DAnalysisImpl@5d73d6f0 (eProxyURI: genCode.mtc#/)
!STACK 0
java.lang.RuntimeException
at org.eclipse.sirius.tools.api.interpreter.InterpreterRegistry.getInterpreter(InterpreterRegistry.java:111)
at org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.hookGraphicalViewer(DDiagramEditorImpl.java:649)
at org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createOriginalGraphicalViewer(DDiagramEditorImpl.java:1444)
at org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createMainDiagramSection(DDiagramEditorImpl.java:1366)
at org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createGraphicalViewer(DDiagramEditorImpl.java:1359)
at org.eclipse.gef.ui.parts.GraphicalEditor.createPartControl(GraphicalEditor.java:171)
at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.createPartControl(DiagramEditor.java:1580)
at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette.createPartControl(DiagramEditorWithFlyOutPalette.java:328)
at org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.createPartControl(DiagramDocumentEditor.java:1514)
at org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createPartControl(DDiagramEditorImpl.java:431)
What Im trying to do is to have a file per Diagram with my own file extension, i created an editor that invokes the Sirius code to open the representation file.
Is possible to store only a diagram in the archive an open directly with an editor?. It would be nice if i can use a ExtensionPoint that associate my extension with the sirius diagram/table/etc..
Best Regards,
Camilo
|
|
|
Re: Open Diagram programmatically [message #1239455 is a reply to message #1239387] |
Tue, 04 February 2014 08:44 |
|
Hi Camilo,
this is the Sirius "Session" which is in charge of loading models (and
many other things e.g. initializing Interpreters).
Moreover, you should not create an editor input by yourself, and use the
DialectUIManager.openEditor() method (as explained in my previous post).
So to give you a complete example similar to what you wrote:
// Step 1: get the .aird file and the corresponding Sirius Session
URI myRepresentationsFileURI = URI.createURI("/" +
dFile.getProject().getName() + "/" +
dFile.getProjectRelativePath().toOSString());
Session siriusSession =
SessionManager.INSTANCE.getSession(myRepresentationsFileURI , new
NullProgressMonitor());
// Step 2: get the DRepresentation to open
DAnalysis root =siriusSession.getSessionResource().getContents().get(0);
DView dView = root.getOwnedViews().get(0);
DRepresentation myRepresentation = dView.getOwnedRepresentations().get(0);
// Step 3: open representation
DialectUIManager.INSTANCE.openEditor(siriusSession, myRepresentation,
new NullProgressMonitor());
In regards to your last question, I do not understand why you would need
to change the file extension we use by defaul (".aird"), this does not
prevent you from creating a new aird file per representation.
Maybe you should take a look at the DAnalysisSelector interface, that
you can implement to customize the .aird file in which new
representations will be created, and create a new .aird file for each
new representation. You can then plug this custom DAnalysisSelector by
calling siriusSession.setAnalysisSelector().
Please let me know if have any further question,
Alex
Le 04/02/2014 05:17, Camilo Alvarez a écrit :
> Hi Alex,
>
> Thank you for the answer.
> I implemented the functionality looking into the source code of the
> Model Explorer, using this code:
>
>
> org.eclipse.sirius.ui.business.api.session.SessionEditorInput sEditor =
> new SessionEditorInput(diagramURI, "New Diagram", null);
> IEditorPart openEditor = IDE.openEditor(page,
> sEditor,"org.eclipse.sirius.diagram.part.SiriusDiagramEditorID", true);
>
>
> Im trying to use the DialectUIManager
> diagramURI = URI.createURI("/" + dFile.getProject().getName() + "/" +
> dFile.getProjectRelativePath().toOSString());
> ResourceSet rs = new ResourceSetImpl(); Resource rsc =
> rs.createResource(diagramURI);
> try {
> load(null);
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
>
> DAnalysis root = (DAnalysis) rsc.getContents().get(0);
> DView dView = root.getOwnedViews().get(0);
> DRepresentation rep = dView.getOwnedRepresentations().get(0);
> DialectUIManager.INSTANCE.openEditor(SessionManager.INSTANCE.getSession(diagramURI,
> new NullProgressMonitor()), rep, new NullProgressMonitor());
>
>
> but i get this exception
>
>
> !ENTRY org.eclipse.sirius 4 0 2014-02-03 22:26:16.667
> !MESSAGE Impossible to find an interpreter - Could not find a session
> for model element :
> org.eclipse.sirius.viewpoint.impl.DAnalysisImpl@5d73d6f0 (eProxyURI:
> genCode.mtc#/)
> !STACK 0
> java.lang.RuntimeException
> at
> org.eclipse.sirius.tools.api.interpreter.InterpreterRegistry.getInterpreter(InterpreterRegistry.java:111)
>
> at
> org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.hookGraphicalViewer(DDiagramEditorImpl.java:649)
>
> at
> org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createOriginalGraphicalViewer(DDiagramEditorImpl.java:1444)
>
> at
> org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createMainDiagramSection(DDiagramEditorImpl.java:1366)
>
> at
> org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createGraphicalViewer(DDiagramEditorImpl.java:1359)
>
> at
> org.eclipse.gef.ui.parts.GraphicalEditor.createPartControl(GraphicalEditor.java:171)
>
> at
> org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.createPartControl(DiagramEditor.java:1580)
>
> at
> org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette.createPartControl(DiagramEditorWithFlyOutPalette.java:328)
>
> at
> org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.createPartControl(DiagramDocumentEditor.java:1514)
>
> at
> org.eclipse.sirius.diagram.tools.internal.editor.DDiagramEditorImpl.createPartControl(DDiagramEditorImpl.java:431)
>
>
>
> What Im trying to do is to have a file per Diagram with my own file
> extension, i created an editor that invokes the Sirius code to open the
> representation file. Is possible to store only a diagram in the archive
> an open directly with an editor?. It would be nice if i can use a
> ExtensionPoint that associate my extension with the sirius
> diagram/table/etc..
>
> Best Regards,
> Camilo
|
|
| |
Re: Open Diagram programmatically [message #1410637 is a reply to message #1410289] |
Thu, 21 August 2014 09:02 |
|
Le 20/08/2014 12:18, Christian Pontesegger a écrit :
> Followup as my question is similar:
> I see how I can open an editor programmatically now. Is there a way to
> register an editor for a given file extension similar to the way text
> editors are registered?
> So if I have a file mydata.ext I would like to use the defined sirius
> editor as the default editor, while the user still could use the "Open
> with" context menu for other choices (or even other sirius diagram types).
>
> Double clicking mydata.ext in the resource navigator view should then
> fire up the sirius editor.
Hi,
There is no specific API for this in Sirius.
It may be possible using the Eclipse API to detect a double click on
mydata.ext and then reuse the code of this post to open the desired
representation.
There is also an option on representation, "Show on Startup", to open
automatically the representations of this kind when a session is opened.
I'm not sure it meets your needs, but I preferred to indicate.
Best regards,
--
Laurent - Obeo
Need professional services for Sirius?
http://www.obeodesigner.com/sirius
Laurent Redor - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
| | | | | |
Goto Forum:
Current Time: Fri Apr 19 21:21:51 GMT 2024
Powered by FUDForum. Page generated in 0.03504 seconds
|