Search in sources :

Example 1 with EmbeddedBusinessObject

use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.

the class DeleteHandler method createBusinessObjectRemovalOrRemoveDiagramElement.

/**
 * Creates a BusinessObjectRemoval object which can be used to remove the business object for the diagram element.
 * If the diagram element's business object is an embedded business object, remove the element.
 * @param de
 * @return
 */
private static BusinessObjectRemoval createBusinessObjectRemovalOrRemoveDiagramElement(final DiagramElement de) {
    // Remove the EObject from the model
    final Object bo = de.getBusinessObject();
    final Object boHandler = de.getBusinessObjectHandler();
    if (bo instanceof EObject) {
        EObject boEObj = (EObject) bo;
        if (boHandler instanceof CustomDeleter) {
            final CustomDeleter deleter = (CustomDeleter) boHandler;
            final EObject ownerBo = boEObj.eContainer();
            return new BusinessObjectRemoval(ownerBo, (boToModify) -> {
                deleter.delete(new CustomDeleteContext(boToModify, bo));
            });
        }
        // When deleting AnnexSubclauses, the deletion must executed on the container DefaultAnnexSubclause
        if (boEObj instanceof AnnexSubclause && boEObj.eContainer() instanceof DefaultAnnexSubclause) {
            boEObj = boEObj.eContainer();
        }
        return new BusinessObjectRemoval(boEObj, (boToModify) -> EcoreUtil.remove(boToModify));
    } else if (bo instanceof EmfContainerProvider) {
        if (!(boHandler instanceof CustomDeleter)) {
            throw new RuntimeException("Business object handler '" + boHandler + "' for " + EmfContainerProvider.class.getName() + " based business object must implement " + CustomDeleter.class.getCanonicalName() + ".");
        }
        final CustomDeleter deleter = (CustomDeleter) boHandler;
        final EObject ownerBo = ((EmfContainerProvider) bo).getEmfContainer();
        return new BusinessObjectRemoval(ownerBo, (boToModify) -> {
            deleter.delete(new CustomDeleteContext(boToModify, bo));
        });
    } else if (bo instanceof EmbeddedBusinessObject) {
        // For embedded business objects, there isn't a model from which to remove the business object.
        // Instead, we remove the diagram element and return null.
        final AgeDiagram diagram = DiagramElementUtil.getDiagram(de);
        diagram.modify("Delete Element", m -> m.removeElement(de));
        return null;
    } else {
        // canDelete() should have returned false in this case
        throw new RuntimeException("Unhandled case: " + bo);
    }
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) URI(org.eclipse.emf.common.util.URI) ListMultimap(com.google.common.collect.ListMultimap) CanDeleteContext(org.osate.ge.businessobjecthandling.CanDeleteContext) Modification(org.osate.ge.internal.services.AadlModificationService.Modification) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) CustomDeleteContext(org.osate.ge.businessobjecthandling.CustomDeleteContext) Predicates(com.google.common.base.Predicates) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IEditorPart(org.eclipse.ui.IEditorPart) EmfContainerProvider(org.osate.ge.EmfContainerProvider) PlatformUI(org.eclipse.ui.PlatformUI) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Collection(java.util.Collection) CustomDeleter(org.osate.ge.businessobjecthandling.CustomDeleter) RawDeleter(org.osate.ge.businessobjecthandling.RawDeleter) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EObject(org.eclipse.emf.ecore.EObject) ExecutionException(org.eclipse.core.commands.ExecutionException) Display(org.eclipse.swt.widgets.Display) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) Objects(java.util.Objects) Consumer(java.util.function.Consumer) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) RawDeleteContext(org.osate.ge.businessobjecthandling.RawDeleteContext) Entry(java.util.Map.Entry) Resource(org.eclipse.emf.ecore.resource.Resource) AnnexSubclause(org.osate.aadl2.AnnexSubclause) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) AbstractHandler(org.eclipse.core.commands.AbstractHandler) NamedElement(org.osate.aadl2.NamedElement) AnnexLibrary(org.osate.aadl2.AnnexLibrary) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) EObject(org.eclipse.emf.ecore.EObject) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EObject(org.eclipse.emf.ecore.EObject) EmfContainerProvider(org.osate.ge.EmfContainerProvider) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) CustomDeleter(org.osate.ge.businessobjecthandling.CustomDeleter) CustomDeleteContext(org.osate.ge.businessobjecthandling.CustomDeleteContext) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 2 with EmbeddedBusinessObject

use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.

the class DiagramSerialization method convertElementToMetamodel.

private static void convertElementToMetamodel(final IProject project, final org.osate.ge.diagram.DiagramNode mmContainer, final DiagramElement e) {
    // Write BO Reference
    final org.osate.ge.diagram.DiagramElement newElement = new org.osate.ge.diagram.DiagramElement();
    mmContainer.getElement().add(newElement);
    newElement.setUuid(e.getId().toString());
    newElement.setBo(e.getRelativeReference().toMetamodel());
    // Store embedded business object data.
    if (e.getBusinessObject() instanceof EmbeddedBusinessObject) {
        final EmbeddedBusinessObject bo = (EmbeddedBusinessObject) e.getBusinessObject();
        newElement.setBoData(bo.getData());
    }
    newElement.setManual(true);
    if (e.hasPosition()) {
        newElement.setPosition(e.getPosition().toMetamodel());
    }
    if (e.hasSize() && DiagramElementPredicates.isResizeable(e)) {
        newElement.setSize(e.getSize().toMetamodel());
    }
    if (e.getDockArea() != null && e.getDockArea() != DockArea.GROUP) {
        // Don't serialize null or group dock areas
        newElement.setDockArea(e.getDockArea().id);
    }
    final Style currentStyle = e.getStyle();
    final org.osate.ge.graphics.Color backgroundColor = currentStyle.getBackgroundColor();
    if (backgroundColor != null) {
        newElement.setBackground(colorToHex(backgroundColor));
    }
    final IPath image = currentStyle.getImagePath();
    if (image != null) {
        // Get image path relative to the diagram's project
        final String portablePath = image.makeRelativeTo(project.getFullPath()).toPortableString();
        newElement.setImage(portablePath);
        newElement.setShowAsImage(currentStyle.getShowAsImage());
    }
    final org.osate.ge.graphics.Color fontColor = currentStyle.getFontColor();
    if (fontColor != null) {
        newElement.setFontColor(colorToHex(fontColor));
    }
    final org.osate.ge.graphics.Color outlineColor = currentStyle.getOutlineColor();
    if (outlineColor != null) {
        newElement.setOutline(colorToHex(outlineColor));
    }
    final Double fontSize = currentStyle.getFontSize();
    if (fontSize != null) {
        newElement.setFontSize(fontSize);
    }
    final Double lineWidth = currentStyle.getLineWidth();
    if (lineWidth != null) {
        newElement.setLineWidth(lineWidth);
    }
    if (currentStyle.getPrimaryLabelVisible() != null) {
        newElement.setPrimaryLabelVisible(currentStyle.getPrimaryLabelVisible());
    }
    // Connection Specific
    if (e.getBendpoints().size() > 0) {
        final org.osate.ge.diagram.BendpointList mmBendpoints = new org.osate.ge.diagram.BendpointList();
        newElement.setBendpoints(mmBendpoints);
        for (final Point bendpoint : e.getBendpoints()) {
            mmBendpoints.getPoint().add(bendpoint.toMetamodel());
        }
    }
    if (e.getConnectionPrimaryLabelPosition() != null) {
        newElement.setPrimaryLabelPosition(e.getConnectionPrimaryLabelPosition().toMetamodel());
    }
    convertElementsToMetamodel(project, newElement, e.getChildren());
}
Also used : Color(org.osate.ge.graphics.Color) IPath(org.eclipse.core.runtime.IPath) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) Point(org.osate.ge.graphics.Point) Style(org.osate.ge.graphics.Style)

Example 3 with EmbeddedBusinessObject

use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.

the class DiagramToBusinessObjectTreeConverter method createBusinessObjectNodesForElements.

private static void createBusinessObjectNodesForElements(final BusinessObjectNode parent, final DiagramElement e, final Map<DiagramNode, Map<RelativeBusinessObjectReference, FutureElementInfo>> futureElementInfoMap, final Map<DiagramNode, Map<RelativeBusinessObjectReference, DiagramElement>> containerToRelativeReferenceToGhostMap) {
    // For embedded business objects, store the object in the business object node.
    // Typically, the business object node isn't stored in the business object node to prevent retaining references
    // to old business objects.
    final Object bo = e.getBusinessObject() instanceof EmbeddedBusinessObject ? e.getBusinessObject() : null;
    // Don't keep the business object when building the business object tree. This will ensure that tree expander or other user of the tree updates
    // the business object based on the model.
    final BusinessObjectNode childNode = new BusinessObjectNode(parent, e.getId(), e.getRelativeReference(), bo, Completeness.UNKNOWN, true);
    createBusinessObjectNodesForElements(childNode, e.getChildren(), futureElementInfoMap, containerToRelativeReferenceToGhostMap);
    createBusinessObjectNodesForGhostedElements(childNode, e, futureElementInfoMap, containerToRelativeReferenceToGhostMap);
    createBusinessObjectNodesForFutureElements(childNode, e, futureElementInfoMap);
}
Also used : EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject)

Example 4 with EmbeddedBusinessObject

use of org.osate.ge.internal.model.EmbeddedBusinessObject 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 5 with EmbeddedBusinessObject

use of org.osate.ge.internal.model.EmbeddedBusinessObject in project osate2 by osate.

the class OperationResultsProcessor method processResults.

/**
 * @param editor the editor which is displaying the diagram for which the operation was executed
 * @param targetNode is the node to which the targetPosition is relative.
 * @param targetPosition the position at which the operation was executed. Relative to the target node. This is used to position
 * a newly created diagram element.
 * @param results the results to process
 */
public static void processResults(final InternalDiagramEditor editor, final DiagramNode targetNode, final Point targetPosition, final OperationResults results) {
    Objects.requireNonNull(editor, "diagram must not be null");
    boolean update = false;
    // Notify the diagram updater to add the element on the next update
    for (final Entry<BusinessObjectContext, OperationResults.BusinessObjectToShowDetails> containerToBoEntry : results.getContainerToBoToShowDetailsMap().entries()) {
        if (containerToBoEntry.getKey() instanceof DiagramNode) {
            final DiagramNode containerNode = (DiagramNode) containerToBoEntry.getKey();
            final OperationResults.BusinessObjectToShowDetails newValue = containerToBoEntry.getValue();
            // Don't set the position if multiple items are being added.
            // Don't set the position if the incremental layout mode is set to diagram.
            // This will ensure the shape is laid out even if it is a docked shape.
            final Point position;
            if (results.getContainerToBoToShowDetailsMap().size() == 1 && LayoutPreferences.getCurrentIncrementalLayoutMode() != IncrementalLayoutMode.LAYOUT_DIAGRAM && containerNode == targetNode) {
                position = targetPosition;
            } else {
                position = null;
            }
            // If the BO being added is an embedded business object, it must be provided to the diagram updater.
            final EmbeddedBusinessObject embeddedBo = (newValue.bo instanceof EmbeddedBusinessObject) ? (EmbeddedBusinessObject) newValue.bo : null;
            editor.getDiagramUpdater().addToNextUpdate(containerNode, newValue.ref, new FutureElementInfo(position, embeddedBo));
            if (embeddedBo != null) {
                update = true;
            }
        }
    }
    // If an embedded business object was added, then update the diagram to ensure it was updated.
    if (update) {
        editor.updateDiagram();
    }
}
Also used : DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) FutureElementInfo(org.osate.ge.internal.diagram.runtime.updating.FutureElementInfo) OperationResults(org.osate.ge.internal.operations.OperationResults) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) Point(org.osate.ge.graphics.Point) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

EmbeddedBusinessObject (org.osate.ge.internal.model.EmbeddedBusinessObject)9 EObject (org.eclipse.emf.ecore.EObject)5 Point (org.osate.ge.graphics.Point)4 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Objects (java.util.Objects)3 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)3 Predicates (com.google.common.base.Predicates)2 Collection (java.util.Collection)2 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)2 NamedElement (org.osate.aadl2.NamedElement)2 BusinessObjectContext (org.osate.ge.BusinessObjectContext)2 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)2 DiagramElementUtil (org.osate.ge.internal.util.DiagramElementUtil)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 MessageFormat (java.text.MessageFormat)1