Search in sources :

Example 21 with DiagramElement

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

the class SelectAllConnectionsHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        throw new RuntimeException("Unexpected editor: " + activeEditor);
    }
    final InternalDiagramEditor editor = (InternalDiagramEditor) activeEditor;
    final List<DiagramElement> connectionDiagramElements = editor.getDiagram().getAllDiagramNodes().filter(dn -> dn instanceof DiagramElement).map(DiagramElement.class::cast).filter(DiagramElementPredicates::isConnection).collect(Collectors.toList());
    editor.selectDiagramNodes(connectionDiagramElements);
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) List(java.util.List) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) AbstractHandler(org.eclipse.core.commands.AbstractHandler) ExecutionException(org.eclipse.core.commands.ExecutionException) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) Collectors(java.util.stream.Collectors) IEditorPart(org.eclipse.ui.IEditorPart) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IEditorPart(org.eclipse.ui.IEditorPart)

Example 22 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement 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 23 with DiagramElement

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

the class ImageErrorTooltipContributor method addTooltipContents.

@Override
public void addTooltipContents(final TooltipContributorContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    if (boc instanceof DiagramElement) {
        final DiagramElement de = (DiagramElement) boc;
        final Style style = de.getStyle();
        if (style != null && Boolean.TRUE.equals(style.getShowAsImage())) {
            final IPath imagePath = style.getImagePath();
            if (imagePath != null) {
                final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                final IResource imageResource = workspaceRoot.findMember(imagePath);
                if (imageResource == null) {
                    final Label lbl = new Label(ctx.getTooltip(), SWT.NONE);
                    lbl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                    lbl.setText("Unable to load image: " + imagePath.toPortableString());
                }
            }
        }
    }
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Label(org.eclipse.swt.widgets.Label) Style(org.osate.ge.graphics.Style) BusinessObjectContext(org.osate.ge.BusinessObjectContext) IResource(org.eclipse.core.resources.IResource)

Example 24 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement 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 25 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement 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

DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)131 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)45 List (java.util.List)31 Point (org.osate.ge.graphics.Point)29 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)29 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)26 Objects (java.util.Objects)25 IEditorPart (org.eclipse.ui.IEditorPart)23 ArrayList (java.util.ArrayList)22 Collectors (java.util.stream.Collectors)22 BusinessObjectContext (org.osate.ge.BusinessObjectContext)21 Collection (java.util.Collection)19 Collections (java.util.Collections)18 Dimension (org.osate.ge.graphics.Dimension)18 DockArea (org.osate.ge.internal.diagram.runtime.DockArea)18 Optional (java.util.Optional)16 AgeConnection (org.osate.ge.graphics.internal.AgeConnection)16 DiagramElementUtil (org.osate.ge.internal.util.DiagramElementUtil)16 ElkPort (org.eclipse.elk.graph.ElkPort)14 Node (javafx.scene.Node)13