Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Creating aird in editor(code: create resource aird and link it to the resource file)
Creating aird in editor [message #1819652] Mon, 20 January 2020 12:19 Go to next message
Viet Dinh is currently offline Viet DinhFriend
Messages: 2
Registered: December 2019
Junior Member

I am struggling to find out how to automatically create an .aird representation file in the wizard.
For example changing basicfamily.editor in such a way, that after you select the wizard in the standard folder 'Example EMF Model Creation Wizards', it will create the resource 'My.basicfamily' within the chosen parent directory and chosen model object. Additionally, now, it shall also create automatically the .aird representation and link it to the resource, and then, enabling viewpoint and create a new Person diagram.

Somehow the code should look similar to this:
// Create a resource set
ResourceSet resourceSet = new ResourceSetImpl();

// Get the URI of the model file.
URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);

// Create a resource for this file.
Resource resource = resourceSet.createResource(fileURI);

Thanks in advance for any hints! :)

Re: Creating aird in editor [message #1819657 is a reply to message #1819652] Mon, 20 January 2020 14:14 Go to previous message
Emmanuel Chebbi is currently offline Emmanuel ChebbiFriend
Messages: 123
Registered: February 2018
Senior Member

So basically you want to programmatically create the representation of an existing model, right? This question has already been addressed in the forum:

You'll find below a code snippet showing how I achieved a similar behavior in a pet project. There may be better implementations but this one worked for me.

private static void createRepresentation(Activity model, IProject project, IProgressMonitor monitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(monitor);
    subMonitor.setTaskName("Creating the diagram");
    // Create a new Sirius session to handle the representation
    Session session = ModelingProject.asModelingProject(project).get().getSession();
    // Allow to create a representation for the activity thereafter
           .execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
               protected void doExecute() {
                   SubMonitor commandMonitor = SubMonitor.convert(subMonitor);
                   session.addSemanticResource(model.eResource().getURI(), commandMonitor);
    // Add the 'workflow' viewpoint to the representation
    Viewpoint workflowViewpoint = workflowViewpoint();
    ChangeViewpointSelectionCommand cc = new ChangeViewpointSelectionCommand(session, new ViewpointSelectionCallback(), new HashSet<>(asList(workflowViewpoint)), Collections.emptySet(), monitor);
    // Actually add the model's root element to the representation
           .execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
                protected void doExecute() {
                    SubMonitor commandMonitor = SubMonitor.convert(subMonitor);
                    session.createView(workflowViewpoint, asList(model), true, commandMonitor);

public static Viewpoint workflowViewpoint() {
    return ViewpointRegistry
                .registerFromPlugin(PLUGIN_ID + "/description/workflow-editor.odesign")).stream()
                .filter(viewpoint -> WORKFLOW_NAME.equals(viewpoint.getName()))

[Updated on: Thu, 23 January 2020 09:21]

Report message to a moderator

Previous Topic:Removing an enumeration from a collection
Next Topic:How to get the selection event of source node during edge creation
Goto Forum:

Current Time: Tue Oct 27 23:34:45 GMT 2020

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

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

Back to the top