Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » How to create an object view from an external java action?
How to create an object view from an external java action? [message #1732415] Tue, 17 May 2016 06:54 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 344
Registered: August 2013
Senior Member
Hi

I have an external java action, which creates several objects in my model. The objects are marked as "not synchronized", because I don't want to show a whole model on the diagram.

How can I programmatically create views for these newly created objects?
Re: How to create an object view from an external java action? [message #1732419 is a reply to message #1732415] Tue, 17 May 2016 07:17 Go to previous messageGo to next message
Alx Hvx is currently offline Alx HvxFriend
Messages: 40
Registered: March 2016
Member
Hi,

Here is what I did (simplified code):

You need your semantic diagram, the session you are working on and the semantical eObject that needs to have a view created :

EObject yourEObject;
DSemanticDiagram d;
Session s = SessionManager.INSTANCE.getSession(yourEObject);

//Then get the container mappings of the diagram and retreive the one you want :

ContainerMapping cm = null
ArrayList<ContainerMapping> al = new ArrayList<> (d.getDescription().getDefaultLayer().getContainerMappings());
		for (ContainerMapping containerMapping : al) {
			if(containerMapping.getName().equals("The name of the mapping of the view you want to create")) {
				cm = containerMapping;
			}
		}

//And then execute the creation of the view :

RecordingCommand cmd = new CreateDDiagramElementCommand(s.getTransactionalEditingDomain(), yourEObject, cm, d);
s.getTransactionalEditingDomain().getCommandStack().execute(cmd);



Hope it helps.
Re: How to create an object view from an external java action? [message #1732429 is a reply to message #1732419] Tue, 17 May 2016 08:52 Go to previous message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 344
Registered: August 2013
Senior Member
Thanks a lot, it works!

Here is the fragment of my final code:

        DDiagramEditor editor = (DDiagramEditor) EclipseUIUtil.getActiveEditor();
        DSemanticDiagram diagram = (DSemanticDiagram) editor.getRepresentation();
        Session session = SessionManager.INSTANCE.getSession(newRelation);
        
        if (newRelation.getEnds().size() == 2) {
            EdgeMapping mapping = diagram.getDescription().getDefaultLayer().getEdgeMappings().stream()
                    .filter(m -> m.getName().equals("Relation"))
                    .findFirst()
                    .get();
            
            Concept concept1 = newRelation.getEnds().get(0).getRole().getConcept();
            Concept concept2 = newRelation.getEnds().get(1).getRole().getConcept();

            DNodeList source = (DNodeList) getDDiagramElement(concept1, diagram);
            DNodeList target = (DNodeList) getDDiagramElement(concept2, diagram);
            
            RecordingCommand cmd = new CreateDDiagramElementCommand(session.getTransactionalEditingDomain(), newRelation, mapping, source, target);
            session.getTransactionalEditingDomain().getCommandStack().execute(cmd);
        }

    private DDiagramElement getDDiagramElement(EObject obj, DDiagram diagram) {
        return new EObjectQuery(obj)
                .getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET)
                .stream()
                .map(el -> (DDiagramElement) el)
                .filter(el -> el.getParentDiagram() == diagram)
                .findFirst()
                .get();
    }
Previous Topic:Disable automatic arrange all on diagram opening
Next Topic:reloading the Sirius diagram editor
Goto Forum:
  


Current Time: Wed Apr 24 22:21:29 GMT 2024

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

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

Back to the top