Bug 442261 - Allow to use Sirius based editors with the Eclipse editor framework
Summary: Allow to use Sirius based editors with the Eclipse editor framework
Status: NEW
Alias: None
Product: Sirius
Classification: Modeling
Component: Diagram (show other bugs)
Version: 1.0.1   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2014-08-21 08:48 EDT by Christian Pontesegger CLA
Modified: 2015-05-04 09:12 EDT (History)
3 users (show)

See Also:


Attachments
Editor project (51.05 KB, application/zip)
2014-09-04 03:19 EDT, Christian Pontesegger CLA
no flags Details
Family test data (2.51 KB, application/zip)
2014-09-04 03:19 EDT, Christian Pontesegger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Pontesegger CLA 2014-08-21 08:48:39 EDT
Right now sirius based editors are opened using the Model explorer. There also exists a way to open editors progrmmatically (see https://www.eclipse.org/forums/index.php/t/633830/ )

But as eclipse has already a nice editor framework with UI support in navigator views (open editor on registered file types with a doubleclick, right click on files -> Open with) I would like to request support to embed a Sirius based editor into that framework.

In the end I would like to register a sirius editor using the org.eclipse.ui.editors extension point
Comment 1 Cedric Brun CLA 2014-08-25 05:28:20 EDT
Hi Christian,

there is an example of that in EcoreTools (which I commented out for now )

Have a look in the plugin.xml : http://git.eclipse.org/c/ecoretools/org.eclipse.ecoretools.git/tree/org.eclipse.emf.ecoretools.design/plugin.xml


   <!--
   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="org.eclipse.emf.ecoretools.design.editor.EcoreEntitiesReadOnlyEditor"
            contributorClass="org.eclipse.sirius.diagram.part.ViewpointDiagramActionBarContributor"
            default="false"
            extensions="ecore"
            icon="icons/full/obj16/EcoreModelFile.gif"
            id="org.eclipse.emf.ecoretools.design.editor.entities"
            matchingStrategy="org.eclipse.emf.ecoretools.design.editor.EcoreEntitiesMatchingStrategy"
            name="Viewpoint Ecore Editor">
      </editor>
   </extension>
   --> 

This declare an editor on .ecore file which will use Sirius and will keep all the representation data in a transient area. 

The editor class itself is fairly simple : 

public class EcoreEntitiesReadOnlyEditor extends AbstractSpecificDDiagramEditor {

	public String getDiagramDescriptionName() {
		return "Entities";
	}

	public URI getViewpointURI() {
		return URI
				.createURI("viewpoint:/org.eclipse.emf.ecoretools.design/Design");
	}

	public boolean isSessionStoredInWorkspace() {
		return false;
	}
}


There are very few (known) usages of this capability to us so that has not been extensively tested in the wild and might lack flexibility depending on your use case.
Comment 2 Christian Pontesegger CLA 2014-09-03 02:14:24 EDT
I am trying to use our code sample to create an editor for the basicfamily sample project from the sirius website. How do you find out the URI for the viewpoint?
Comment 3 Maxime Porhel CLA 2014-09-03 03:14:50 EDT
Hi Christian, 

For the EcoreTool's editor, if you look at the snippet given by Cédric, you will see: "viewpoint:/org.eclipse.emf.ecoretools.design/Design"

 viewpoint:/  is a specific URI scheme allowing to reference a Viewpoint with its containing plugin id and its name/id (and not the label). 

In your case, if you create a Viewpoint Specification Project for the basic family sample, the viewpoint uri should be viewpoint:/yourBasicFamilyDesignPluginId/yourViewpointId

Rds,

Maxime
Comment 4 Christian Pontesegger CLA 2014-09-03 09:32:06 EDT
Thanks, found the viewpoint ID:
viewpoint:/org.eclipse.sirius.sample.basicfamily.design/Basic%20Family

I am able to open the editor now. Regarding the example given in comment 1 I could not find org.eclipse.sirius.diagram.part.ViewpointDiagramActionBarContributor in Sirius 1.0.1. Instead I found
org.eclipse.sirius.editor.editorPlugin.ViewpointActionBarContributor

which seems to work. Is this the correct class to use?
Comment 5 Maxime Porhel CLA 2014-09-03 10:36:33 EDT
org.eclipse.sirius.editor.editorPlugin.ViewpointActionBarContributor si the action bar contributor for the VSM (.odesign) editor. 

You should try to use org.eclipse.sirius.diagram.ui.part.SiriusDiagramActionBarContributor instead.
Comment 6 Christian Pontesegger CLA 2014-09-04 03:19:02 EDT
Created attachment 246704 [details]
Editor project
Comment 7 Christian Pontesegger CLA 2014-09-04 03:19:38 EDT
Created attachment 246705 [details]
Family test data
Comment 8 Christian Pontesegger CLA 2014-09-04 03:20:55 EDT
Still not there. Created a test project along with test data. The editor opens, but shows a note saying: "This diagram was not saved. You can close the editor" instead of displaying the representation.

For the sample project just uploaded I used the basicfamily example from Sirius. I adapted the code a bit to use the representations.aird file.
Comment 9 Maxime Porhel CLA 2015-05-04 09:12:12 EDT
Hi Christian, 

The message seems to indicate that the editor uri input does not point to a gmf Diagram element.

private URI getNewEditorInputURI(final DRepresentation representation) {
	return EcoreUtil.getURI(representation);
}

You return the uri of the DRepresentation, the Sirius diagram in your case, but the editor expects the uri of the corresponding gmf Diagram. 
You can use org.eclipse.sirius.diagram.business.api.refresh.DiagramCreationUtil.findAssociatedGMFDiagram() or org.eclipse.sirius.diagram.ui.business.api.view.SiriusGMFHelper.getGmfDiagram(DDiagram, Session) to retrieve the diagram. 

It seems that the DDiagramEditorEditorImpl is able to take Diagram or DDiagram as input but we might have to improve org.eclipse.sirius.diagram.ui.tools.internal.resource.CustomSiriusDocumentProvider.caseURIEditorInput(IDocument, URIEditorInput, TransactionalEditingDomain) to make it able to take a UriEditorInput targeting a DDiagram (see org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.setInput(IEditorInput)