Search in sources :

Example 1 with Graphic

use of org.osate.ge.graphics.Graphic in project osate2 by osate.

the class GefAgeDiagram method ensureSceneNodeExists.

/**
 * Ensures that a scene node exists for the specified GEF diagram element.
 * Creates or recreates scene nodes and adds to the scene graph as necessary. Updates the specified GEF diagram element.
 * @param gefDiagramElement the GEF diagram element for which to ensure that the scene node exists.
 * @param parentDiagramElementSceneNode the scene node for the parent of the GEF diagram element. This is specified instead of using
 * the value contained in the GEF diagram element because it may not be up to date.
 * @return the scene node for the diagram element. This specified GEF diagram element will be updated to hold this value.
 */
private Node ensureSceneNodeExists(GefDiagramElement gefDiagramElement, final Node parentDiagramElementSceneNode) {
    Objects.requireNonNull(parentDiagramElementSceneNode, "parentDiagramElementScenenNode must not be null");
    final Graphic graphic = Objects.requireNonNull(gefDiagramElement.diagramElement.getGraphic(), "graphic must not be null");
    final DiagramElement childDiagramElement = gefDiagramElement.diagramElement;
    // 
    // The following final variables determine the operations that needs to be performed by the remainder of the function.
    // They are set by comparing the previous state with the current state of the diagram element.
    // 
    final boolean docked = childDiagramElement.getDockArea() != null;
    final boolean parentIsConnection = parentDiagramElementSceneNode instanceof BaseConnectionNode;
    final boolean create = !Objects.equals(graphic, gefDiagramElement.sourceGraphic) || docked != gefDiagramElement.sceneNode instanceof DockedShape || parentIsConnection != gefDiagramElement.parentDiagramNodeSceneNode instanceof BaseConnectionNode;
    final boolean addToScene = create || gefDiagramElement.parentDiagramNodeSceneNode != parentDiagramElementSceneNode;
    final boolean removeFromScene = addToScene && gefDiagramElement.sceneNode != null;
    // Update other fields
    gefDiagramElement.sourceGraphic = graphic;
    // Remove the node for the scene graph
    if (removeFromScene) {
        removeNode(gefDiagramElement.sceneNode);
    }
    // 
    if (create) {
        // Remove mapping to old scene node
        if (gefDiagramElement.sceneNode != null) {
            sceneNodeToGefDiagramElementMap.remove(gefDiagramElement.sceneNode);
        }
        // Create the new node. Create a graphic and then a wrapper as appropriate
        final Node graphicNode = GraphicToFx.createNode(graphic);
        if (graphicNode instanceof BaseConnectionNode) {
            final BaseConnectionNode newConnectionNode = (BaseConnectionNode) graphicNode;
            gefDiagramElement.sceneNode = graphicNode;
            // Create the primary label node
            final LabelNode primaryLabel = new LabelNode();
            newConnectionNode.getPrimaryLabels().add(primaryLabel);
            gefDiagramElement.primaryLabel = primaryLabel;
        } else if (graphicNode instanceof LabelNode) {
            gefDiagramElement.sceneNode = graphicNode;
        } else if (parentIsConnection) {
            // NOTE: This should only occur for fixed sized graphics
            // Rotate midpoint decorations 180.0 degrees because our connection not expects midpoint decorations to be oriented as if
            // the connection was left to right and that is not how graphics are specified in the graphical editor.
            final Group rotationWrapper = new Group();
            rotationWrapper.getChildren().add(graphicNode);
            rotationWrapper.setRotate(180.0);
            gefDiagramElement.sceneNode = rotationWrapper;
        } else {
            if (docked) {
                final DockedShape newDockedShape = new DockedShape();
                newDockedShape.setGraphic(graphicNode);
                gefDiagramElement.sceneNode = newDockedShape;
                // Create the primary label node
                final LabelNode primaryLabel = new LabelNode();
                newDockedShape.getPrimaryLabels().add(primaryLabel);
                gefDiagramElement.primaryLabel = primaryLabel;
                // Create annotation node
                final LabelNode annotationLabel = new LabelNode();
                newDockedShape.getSecondaryLabels().add(annotationLabel);
                gefDiagramElement.annotationLabel = annotationLabel;
            } else {
                final ContainerShape newContainerShape = new ContainerShape();
                newContainerShape.setGraphic(graphicNode);
                gefDiagramElement.sceneNode = newContainerShape;
                // Create the primary label node
                final LabelNode primaryLabel = new LabelNode();
                newContainerShape.getPrimaryLabels().add(primaryLabel);
                gefDiagramElement.primaryLabel = primaryLabel;
            }
        }
        // Add mapping to scene node
        if (gefDiagramElement.sceneNode != null) {
            sceneNodeToGefDiagramElementMap.put(gefDiagramElement.sceneNode, gefDiagramElement);
        }
        StyleRoot.set(gefDiagramElement.sceneNode, true);
    }
    // 
    if (addToScene) {
        if (gefDiagramElement.sceneNode instanceof BaseConnectionNode) {
            diagramNode.getChildren().add(gefDiagramElement.sceneNode);
            // Flow indicators are positioned relative to the scene node of the parent diagram element
            if (gefDiagramElement.sceneNode instanceof FlowIndicatorNode) {
                if (parentDiagramElementSceneNode instanceof ContainerShape) {
                    ((FlowIndicatorNode) gefDiagramElement.sceneNode).setPositioningReference(parentDiagramElementSceneNode);
                } else {
                    throw new AgeGefRuntimeException("Unexpected parent diagram element scene node for flow indicator: " + parentDiagramElementSceneNode);
                }
            }
        } else if (gefDiagramElement.sceneNode instanceof LabelNode) {
            // Add label to parent
            if (parentDiagramElementSceneNode instanceof ContainerShape) {
                ((ContainerShape) parentDiagramElementSceneNode).getSecondaryLabels().add(gefDiagramElement.sceneNode);
            } else if (parentDiagramElementSceneNode instanceof DockedShape) {
                ((DockedShape) parentDiagramElementSceneNode).getSecondaryLabels().add(gefDiagramElement.sceneNode);
            } else if (parentDiagramElementSceneNode instanceof BaseConnectionNode) {
                ((BaseConnectionNode) parentDiagramElementSceneNode).getSecondaryLabels().add(gefDiagramElement.sceneNode);
            } else {
                throw new AgeGefRuntimeException("Unexpected parent node for label: " + parentDiagramElementSceneNode);
            }
        } else if (parentIsConnection) {
            ((BaseConnectionNode) parentDiagramElementSceneNode).getMidpointDecorations().add(gefDiagramElement.sceneNode);
        } else {
            final DockArea dockArea = childDiagramElement.getDockArea();
            if (gefDiagramElement.sceneNode instanceof DockedShape) {
                final DockedShape dockedShape = (DockedShape) gefDiagramElement.sceneNode;
                // Add the docked shape to the appropriate list
                if (parentDiagramElementSceneNode instanceof ContainerShape) {
                    final ContainerShape containerShapeParent = (ContainerShape) parentDiagramElementSceneNode;
                    containerShapeParent.addOrUpdateDockedChild(dockedShape, GefAgeDiagramUtil.toDockSide(dockArea));
                } else if (parentDiagramElementSceneNode instanceof DockedShape) {
                    final DockedShape dockedShapeParent = (DockedShape) parentDiagramElementSceneNode;
                    dockedShapeParent.getNestedChildren().add(dockedShape);
                } else {
                    throw new AgeGefRuntimeException("Unexpected parent for docked shape: " + parentDiagramElementSceneNode);
                }
            } else {
                if (parentDiagramElementSceneNode instanceof ContainerShape) {
                    final ContainerShape containerShapeParent = (ContainerShape) parentDiagramElementSceneNode;
                    containerShapeParent.getFreeChildren().add(gefDiagramElement.sceneNode);
                } else if (parentDiagramElementSceneNode instanceof Group) {
                    ((Group) parentDiagramElementSceneNode).getChildren().add(gefDiagramElement.sceneNode);
                } else {
                    throw new AgeGefRuntimeException("Unexpected parent node for container shape: " + parentDiagramElementSceneNode);
                }
            }
        }
        gefDiagramElement.parentDiagramNodeSceneNode = parentDiagramElementSceneNode;
    }
    return gefDiagramElement.sceneNode;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) LabelNode(org.osate.ge.gef.LabelNode) Group(javafx.scene.Group) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) Graphic(org.osate.ge.graphics.Graphic) FeatureGraphic(org.osate.ge.graphics.internal.FeatureGraphic) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) DockedShape(org.osate.ge.gef.DockedShape) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) DiagramRootNode(org.osate.ge.gef.DiagramRootNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) FeatureGroupNode(org.osate.ge.gef.FeatureGroupNode) LabelNode(org.osate.ge.gef.LabelNode) Node(javafx.scene.Node) ConnectionNode(org.osate.ge.gef.ConnectionNode) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) ContainerShape(org.osate.ge.gef.ContainerShape) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException)

Example 2 with Graphic

use of org.osate.ge.graphics.Graphic in project osate2 by osate.

the class ErrorFlowHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final ErrorFlow bo = ctx.getBusinessObjectContext().getBusinessObject(ErrorFlow.class).get();
    final BusinessObjectContext classifierBoc = ctx.getBusinessObjectContext().getParent();
    if (classifierBoc == null) {
        return Optional.empty();
    }
    // Determine the type of graphic and the source and destination of the connection
    final ErrorFlowEnd src;
    final ErrorFlowEnd dst;
    final Graphic graphic;
    if (bo instanceof ErrorSource) {
        graphic = SOURCE_GRAPHIC;
        final ErrorSource es = (ErrorSource) bo;
        src = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, es.isAll(), es.getSourceModelElement()).orElse(null);
        dst = null;
    } else if (bo instanceof ErrorSink) {
        graphic = SINK_GRAPHIC;
        final ErrorSink es = (ErrorSink) bo;
        src = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, es.isAllIncoming(), es.getIncoming()).orElse(null);
        dst = null;
    } else if (bo instanceof ErrorPath) {
        graphic = PATH_GRAPHIC;
        final ErrorPath ep = (ErrorPath) bo;
        src = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, ep.isAllIncoming(), ep.getIncoming()).orElse(null);
        dst = getErrorFlowEnd(ctx.getQueryService(), classifierBoc, ep.isAllOutgoing(), ep.getOutgoing()).orElse(null);
    } else {
        return Optional.empty();
    }
    // Determine style
    final StyleBuilder sb = StyleBuilder.create(GraphicalExtensionUtil.isInherited(ctx.getBusinessObjectContext()) ? GraphicalExtensionUtil.STYLE_INHERITED_ELEMENT : Style.EMPTY).lineWidth(4.0);
    final boolean partial = (src != null && src.partial) || (dst != null && dst.partial);
    if (partial) {
        sb.dotted();
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).style(sb.build()).defaultDockingPosition(DockingPosition.ANY).source(src == null ? null : src.boc).destination(dst == null ? null : dst.boc).build());
}
Also used : ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) Graphic(org.osate.ge.graphics.Graphic) StyleBuilder(org.osate.ge.graphics.StyleBuilder) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink)

Example 3 with Graphic

use of org.osate.ge.graphics.Graphic in project osate2 by osate.

the class AgeFxTest method start.

@Override
public void start(final Stage primaryStage) throws Exception {
    container = new GridPane();
    container.setHgap(10.0);
    container.setVgap(10.0);
    container.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, CornerRadii.EMPTY, Insets.EMPTY)));
    final Graphic[] graphics = new Graphic[] { RectangleBuilder.create().build(), RectangleBuilder.create().rounded().build(), EllipseBuilder.create().build(), FolderGraphicBuilder.create().build(), DeviceGraphicBuilder.create().build(), ParallelogramBuilder.create().horizontalOffset(20).build(), BusGraphicBuilder.create().build(), PolyBuilder.create().polygon().points(new Point(0.0, 1.0), new Point(1.0, 1.0), new Point(0.5, 0.0)).build(), PolyBuilder.create().polyline().points(new Point(0.0, 0.0), new Point(1.0, 0.5), new Point(0.0, 1.0)).build(), ProcessorGraphicBuilder.create().build(), MemoryGraphicBuilder.create().build(), FeatureGroupTypeGraphicBuilder.create().build(), ModeGraphicBuilder.create().build(), ModeGraphicBuilder.create().initialMode().build(), NoteGraphicBuilder.create().build(), LabelBuilder.create().build(), FeatureGraphicBuilder.create().abstractFeature().bidirectional().build(), FeatureGraphicBuilder.create().abstractFeature().input().build(), FeatureGraphicBuilder.create().abstractFeature().output().build(), FeatureGraphicBuilder.create().eventPort().bidirectional().build(), FeatureGraphicBuilder.create().eventPort().input().build(), FeatureGraphicBuilder.create().eventPort().output().build(), FeatureGraphicBuilder.create().dataPort().bidirectional().build(), FeatureGraphicBuilder.create().dataPort().input().build(), FeatureGraphicBuilder.create().dataPort().output().build(), FeatureGraphicBuilder.create().eventDataPort().bidirectional().build(), FeatureGraphicBuilder.create().eventDataPort().input().build(), FeatureGraphicBuilder.create().eventDataPort().output().build(), FeatureGraphicBuilder.create().subprogramAccess().input().build(), FeatureGraphicBuilder.create().subprogramAccess().output().build(), FeatureGraphicBuilder.create().subprogramGroupAccess().input().build(), FeatureGraphicBuilder.create().subprogramGroupAccess().output().build(), FeatureGraphicBuilder.create().dataAccess().input().build(), FeatureGraphicBuilder.create().dataAccess().output().build(), FeatureGraphicBuilder.create().featureGroup().build(), ConnectionBuilder.create().build(), ConnectionBuilder.create().sourceTerminator(OrthogonalLineBuilder.create().build()).build(), ConnectionBuilder.create().sourceTerminator(ArrowBuilder.create().filled().build()).destinationTerminator(ArrowBuilder.create().filled().small().build()).build(), ConnectionBuilder.create().destinationTerminator(ArrowBuilder.create().line().build()).build(), FlowIndicatorBuilder.create().build(), FlowIndicatorBuilder.create().sourceTerminator(ArrowBuilder.create().small().reverse().build()).destinationTerminator(OrthogonalLineBuilder.create().build()).build() };
    final List<Node> nodes = Arrays.stream(graphics).map(GraphicToFx::createNode).collect(Collectors.toList());
    // Create a container shape. This is useful for ensuring image in style is applied,.
    final ContainerShape cs = new ContainerShape();
    cs.setGraphic(new EllipseNode());
    nodes.add(cs);
    final CheckBox dashedCheckBox = new CheckBox("Dashed");
    nodes.add(dashedCheckBox);
    dashedCheckBox.selectedProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> {
        dashed = newValue;
        refreshStyle();
    });
    // Finish additional configuraton for labels and connections
    for (final Node n : nodes) {
        if (n instanceof LabelNode) {
            ((LabelNode) n).setText("This is a test");
        } else if (n instanceof ConnectionNode) {
            final ConnectionNode cn = (ConnectionNode) n;
            final StaticAnchor start = new StaticAnchor(new org.eclipse.gef.geometry.planar.Point(0, 5));
            final StaticAnchor end = new StaticAnchor(new org.eclipse.gef.geometry.planar.Point(100, 5));
            cn.setStartAnchor(start);
            cn.setEndAnchor(end);
        } else if (n instanceof FlowIndicatorNode) {
            final FlowIndicatorNode fi = (FlowIndicatorNode) n;
            final StaticAnchor startAnchor = new StaticAnchor(new org.eclipse.gef.geometry.planar.Point(0, 5));
            fi.setTranslateX(100.0);
            fi.setTranslateY(5.0);
            fi.setStartAnchor(startAnchor);
        }
    }
    final List<String> args = getParameters().getRaw();
    final IPath imagePath = args.size() > 0 ? new Path(args.get(0)) : null;
    baseStyle = StyleBuilder.create(Style.DEFAULT).fontSize(20.0).outlineColor(org.osate.ge.graphics.Color.BLUE).backgroundColor(org.osate.ge.graphics.Color.CYAN).imagePath(imagePath).build();
    // Add Nodes and Assign them to Rows and Columns
    final int numberOfColumns = 4;
    int row = 0, col = -1;
    for (final Node node : nodes) {
        // Increment the row and column first so that the final values will be the indices of the last node
        col++;
        if (col > (numberOfColumns - 1)) {
            col = 0;
            row++;
        }
        container.add(node, col, row);
    }
    // Create Row and Column Constraints
    for (int i = 0; i < numberOfColumns; i++) {
        ColumnConstraints c = new ColumnConstraints(100, 100, Double.MAX_VALUE);
        c.setHgrow(Priority.SOMETIMES);
        container.getColumnConstraints().add(c);
    }
    for (int i = 0; i <= row; i++) {
        RowConstraints rc = new RowConstraints(20, 20, Double.MAX_VALUE);
        rc.setVgrow(Priority.SOMETIMES);
        container.getRowConstraints().add(rc);
    }
    // Style the nodes
    refreshStyle();
    primaryStage.setScene(new Scene(container));
    // Setup the stage
    primaryStage.setResizable(true);
    primaryStage.setWidth(1920);
    primaryStage.setHeight(1080);
    primaryStage.setTitle("GEF Graphics");
    primaryStage.show();
}
Also used : Arrays(java.util.Arrays) PolyBuilder(org.osate.ge.graphics.PolyBuilder) StaticAnchor(org.eclipse.gef.fx.anchors.StaticAnchor) FxStyleApplier(org.osate.ge.gef.FxStyleApplier) NoteGraphicBuilder(org.osate.ge.graphics.internal.NoteGraphicBuilder) Application(javafx.application.Application) IPath(org.eclipse.core.runtime.IPath) Graphic(org.osate.ge.graphics.Graphic) ConnectionBuilder(org.osate.ge.graphics.ConnectionBuilder) LineStyle(org.osate.ge.graphics.LineStyle) ContainerShape(org.osate.ge.gef.ContainerShape) Point(org.osate.ge.graphics.Point) ModeGraphicBuilder(org.osate.ge.graphics.internal.ModeGraphicBuilder) Collectors(java.util.stream.Collectors) ArrowBuilder(org.osate.ge.graphics.ArrowBuilder) ParallelogramBuilder(org.osate.ge.graphics.internal.ParallelogramBuilder) StyleBuilder(org.osate.ge.graphics.StyleBuilder) EllipseNode(org.osate.ge.gef.EllipseNode) Priority(javafx.scene.layout.Priority) List(java.util.List) Path(org.eclipse.core.runtime.Path) BusGraphicBuilder(org.osate.ge.graphics.internal.BusGraphicBuilder) DeviceGraphicBuilder(org.osate.ge.graphics.internal.DeviceGraphicBuilder) ProcessorGraphicBuilder(org.osate.ge.graphics.internal.ProcessorGraphicBuilder) FxStyle(org.osate.ge.gef.FxStyle) OrthogonalLineBuilder(org.osate.ge.graphics.internal.OrthogonalLineBuilder) CornerRadii(javafx.scene.layout.CornerRadii) Scene(javafx.scene.Scene) ColumnConstraints(javafx.scene.layout.ColumnConstraints) RowConstraints(javafx.scene.layout.RowConstraints) LabelNode(org.osate.ge.gef.LabelNode) FeatureGraphicBuilder(org.osate.ge.graphics.internal.FeatureGraphicBuilder) FeatureGroupTypeGraphicBuilder(org.osate.ge.graphics.internal.FeatureGroupTypeGraphicBuilder) Style(org.osate.ge.graphics.Style) Insets(javafx.geometry.Insets) BackgroundFill(javafx.scene.layout.BackgroundFill) GridPane(javafx.scene.layout.GridPane) LabelBuilder(org.osate.ge.graphics.LabelBuilder) Color(javafx.scene.paint.Color) FolderGraphicBuilder(org.osate.ge.graphics.internal.FolderGraphicBuilder) EllipseBuilder(org.osate.ge.graphics.EllipseBuilder) FlowIndicatorBuilder(org.osate.ge.graphics.FlowIndicatorBuilder) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) ConnectionNode(org.osate.ge.gef.ConnectionNode) MemoryGraphicBuilder(org.osate.ge.graphics.internal.MemoryGraphicBuilder) RectangleBuilder(org.osate.ge.graphics.RectangleBuilder) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) Background(javafx.scene.layout.Background) Stage(javafx.stage.Stage) ImageManager(org.osate.ge.gef.ImageManager) ChangeListener(javafx.beans.value.ChangeListener) LabelNode(org.osate.ge.gef.LabelNode) ColumnConstraints(javafx.scene.layout.ColumnConstraints) EllipseNode(org.osate.ge.gef.EllipseNode) LabelNode(org.osate.ge.gef.LabelNode) Node(javafx.scene.Node) ConnectionNode(org.osate.ge.gef.ConnectionNode) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) RowConstraints(javafx.scene.layout.RowConstraints) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) ContainerShape(org.osate.ge.gef.ContainerShape) ConnectionNode(org.osate.ge.gef.ConnectionNode) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) GridPane(javafx.scene.layout.GridPane) Background(javafx.scene.layout.Background) IPath(org.eclipse.core.runtime.IPath) EllipseNode(org.osate.ge.gef.EllipseNode) Graphic(org.osate.ge.graphics.Graphic) BackgroundFill(javafx.scene.layout.BackgroundFill) Point(org.osate.ge.graphics.Point) Scene(javafx.scene.Scene) Point(org.osate.ge.graphics.Point) CheckBox(javafx.scene.control.CheckBox) StaticAnchor(org.eclipse.gef.fx.anchors.StaticAnchor)

Example 4 with Graphic

use of org.osate.ge.graphics.Graphic in project osate2 by osate.

the class TagHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final Tag tv = boc.getBusinessObject(Tag.class).orElseThrow();
    final Graphic graphic;
    switch(tv.key) {
        case Tag.KEY_UNIDIRECTIONAL:
            // Don't show the directional indicator if there is a timing property value which is immediate
            for (final BusinessObjectContext sibling : boc.getParent().getChildren()) {
                if (TimingPropertyValueHandler.isImmediateTimingProperty(sibling.getBusinessObject())) {
                    return Optional.empty();
                }
            }
            graphic = directionIndicator;
            break;
        default:
            graphic = defaultGraphic;
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).build());
}
Also used : Graphic(org.osate.ge.graphics.Graphic) Tag(org.osate.ge.aadl2.internal.model.Tag) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 5 with Graphic

use of org.osate.ge.graphics.Graphic in project osate2 by osate.

the class TimingPropertyValueHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final PropertyValueGroup pvg = boc.getBusinessObject(PropertyValueGroup.class).orElseThrow();
    final Object parentBo = boc.getParent() == null ? null : boc.getParent().getBusinessObject();
    // Use default property handler if the BO isn't a connection or connection reference.
    if (!(parentBo instanceof Connection || parentBo instanceof ConnectionReference)) {
        return pvgBoh.getGraphicalConfiguration(ctx);
    }
    final NamedValue namedValue = (NamedValue) pvg.getFirstValueBasedOnCompletelyProcessedAssociation().getValue();
    Graphic graphic = null;
    if (namedValue.getNamedValue() instanceof NamedElement) {
        final NamedElement ne = (NamedElement) namedValue.getNamedValue();
        if (CommunicationProperties.IMMEDIATE.equalsIgnoreCase(ne.getName())) {
            graphic = IMMEDIATE_GRAPHIC;
        } else if (CommunicationProperties.DELAYED.equalsIgnoreCase(ne.getName())) {
            graphic = DELAYED_GRAPHIC;
        }
    }
    if (graphic == null) {
        return Optional.empty();
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).build());
}
Also used : PropertyValueGroup(org.osate.ge.aadl2.internal.model.PropertyValueGroup) Graphic(org.osate.ge.graphics.Graphic) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) Connection(org.osate.aadl2.Connection) NamedValue(org.osate.aadl2.NamedValue) BusinessObjectContext(org.osate.ge.BusinessObjectContext) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

Graphic (org.osate.ge.graphics.Graphic)8 BusinessObjectContext (org.osate.ge.BusinessObjectContext)5 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Point (org.osate.ge.graphics.Point)3 Style (org.osate.ge.graphics.Style)3 AgeShape (org.osate.ge.graphics.internal.AgeShape)3 Label (org.osate.ge.graphics.internal.Label)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 EnumSet (java.util.EnumSet)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2