Search in sources :

Example 6 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class ElkGraphBuilder method buildLayoutGraph.

private LayoutMapping buildLayoutGraph(final DiagramNode rootDiagramNode) {
    // Create the graph
    final LayoutMapping mapping = new LayoutMapping(null);
    final ElkNode rootNode = ElkGraphUtil.createGraph();
    rootNode.setProperty(CoreOptions.DIRECTION, Direction.RIGHT);
    mapping.setLayoutGraph(rootNode);
    // As of 2020-04-06, INCLUDE_CHILDREN causes layout issues. In particular, labels can overlap with children
    // https://github.com/eclipse/elk/issues/316
    // https://github.com/eclipse/elk/issues/412
    rootNode.setProperty(CoreOptions.HIERARCHY_HANDLING, HierarchyHandling.SEPARATE_CHILDREN);
    if (rootDiagramNode instanceof AgeDiagram) {
        final ElkNode diagramElkNode = ElkGraphUtil.createNode(rootNode);
        mapping.getGraphMap().put(diagramElkNode, rootDiagramNode);
        createElkGraphElementsForNonLabelChildShapes(rootDiagramNode, diagramElkNode, mapping);
    } else if (rootDiagramNode instanceof DiagramElement) {
        createElkGraphElementsForElements(Collections.singleton((DiagramElement) rootDiagramNode), rootNode, mapping);
    }
    createElkGraphElementsForConnections(rootDiagramNode, mapping);
    return mapping;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ElkNode(org.eclipse.elk.graph.ElkNode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping)

Example 7 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class SetBindingTool method activated.

@Override
public void activated(final ActivatedEvent ctx) {
    final BusinessObjectContext[] selectedBocs = ctx.getSelectedBocs().toArray(new BusinessObjectContext[ctx.getSelectedBocs().size()]);
    final AgeDiagram diagram = ctx.getDiagram();
    final AadlModificationService aadlModService = ctx.getAadlModificatonService();
    final UiService uiService = ctx.getUiService();
    try {
        final BusinessObjectContext componentImplementationBoc = ToolUtil.findComponentImplementationBoc(selectedBocs[0]);
        // Open Dialog
        if (currentWindow == null && componentImplementationBoc != null) {
            currentWindow = new SetBindingWindow(Display.getCurrent().getActiveShell(), componentImplementationBoc, selectedBocs);
            if (currentWindow.open() == Window.OK) {
                // Ensure the diagram is configured to show the specified binding property
                if (!diagram.getConfiguration().getEnabledAadlPropertyNames().contains(currentWindow.getSelectedProperty().getQualifiedName().toLowerCase())) {
                    diagram.modify("Configure Diagram", m -> {
                        m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagram.getConfiguration()).addAadlProperty(currentWindow.getSelectedProperty().getQualifiedName()).build());
                    });
                }
                // Create the property association
                createPropertyAssociations(aadlModService);
            }
            currentWindow = null;
        }
    } finally {
        uiService.deactivateActiveTool();
    }
}
Also used : UiService(org.osate.ge.internal.services.UiService) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 8 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class DefaultGraphicalEditorService method getObjectDetails.

@Override
public Optional<ObjectDetails> getObjectDetails(Object selectedObject) {
    if (!(selectedObject instanceof DiagramElement)) {
        return Optional.empty();
    }
    final DiagramElement selectedDiagramElement = (DiagramElement) selectedObject;
    final Object bo = selectedDiagramElement.getBusinessObject();
    if (bo == null) {
        return Optional.empty();
    }
    // Diagrams do not have a reference to the context business object. It is non-trivial to resolve the context business object using the diagram
    // configuration. Instead, return the business object associated with the only root child which is is associated with a non-embedded business object.
    // If there are multiple such root children then the diagram is a contextless diagram and null will be returned.
    final AgeDiagram diagram = DiagramElementUtil.getDiagram(selectedDiagramElement);
    Object diagramBo = null;
    if (diagram != null) {
        final List<BusinessObjectContext> rootChildren = diagram.getChildren().stream().filter(boc -> boc.getBusinessObject() != null && !(boc.getBusinessObject() instanceof EmbeddedBusinessObject)).collect(Collectors.toUnmodifiableList());
        if (rootChildren.size() == 1) {
            diagramBo = rootChildren.get(0).getBusinessObject();
        }
    }
    return Optional.of(new ObjectDetails(diagramBo, bo));
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) SimpleServiceContextFunction(org.osate.ge.internal.services.impl.SimpleServiceContextFunction) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) DiagramService(org.osate.ge.internal.services.DiagramService) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) Collectors(java.util.stream.Collectors) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) Objects(java.util.Objects) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) BusinessObjectContext(org.osate.ge.BusinessObjectContext) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) GraphicalEditor(org.osate.ge.GraphicalEditor) GraphicalEditorService(org.osate.ge.services.GraphicalEditorService) Optional(java.util.Optional) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 9 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class MatchSizeHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
    final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
    if (diagram == null) {
        throw new RuntimeException("Unable to get diagram");
    }
    diagram.modify("Match Size", m -> {
        final Dimension newSize = AgeHandlerUtil.getPrimaryDiagramElement(selectedDiagramElements).getSize();
        for (final DiagramElement tmpElement : selectedDiagramElements) {
            m.setSize(tmpElement, newSize);
        }
    });
    return null;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Dimension(org.osate.ge.graphics.Dimension)

Example 10 with AgeDiagram

use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.

the class RemoveBendpointsHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
    final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
    if (diagram == null) {
        throw new RuntimeException("Unable to get diagram");
    }
    diagram.modify("Remove Bendpoints", m -> {
        for (final DiagramElement de : selectedDiagramElements) {
            if (DiagramElementPredicates.isConnection(de)) {
                m.setBendpoints(de, Collections.emptyList());
            }
        }
    });
    return null;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram)

Aggregations

AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)46 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)35 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)20 IEditorPart (org.eclipse.ui.IEditorPart)18 List (java.util.List)16 Objects (java.util.Objects)16 Collectors (java.util.stream.Collectors)12 BusinessObjectContext (org.osate.ge.BusinessObjectContext)12 ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)11 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)10 Collections (java.util.Collections)9 Adapters (org.eclipse.core.runtime.Adapters)9 DiagramUpdater (org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater)9 Collection (java.util.Collection)8 LinkedList (java.util.LinkedList)8 Optional (java.util.Optional)8 Stream (java.util.stream.Stream)8 Point (org.osate.ge.graphics.Point)8 ArrayList (java.util.ArrayList)7 UiUtil (org.osate.ge.internal.ui.util.UiUtil)7