Search in sources :

Example 1 with SimpleModifier

use of org.osate.ge.internal.services.AadlModificationService.SimpleModifier in project osate2 by osate.

the class SetBindingTool method createPropertyAssociations.

private void createPropertyAssociations(final AadlModificationService aadlModService) {
    final BusinessObjectContext ciBoc = currentWindow.getComponentImplementationBoc();
    final ComponentImplementation ci = (ComponentImplementation) ciBoc.getBusinessObject();
    aadlModService.modify(Modification.create(ci, new SimpleModifier<ComponentClassifier>() {

        @Override
        public void modify(final ComponentClassifier ci) {
            for (final BusinessObjectContext bocToBind : currentWindow.getBocsToBind()) {
                final PropertyAssociation newPa = AgeAadlUtil.getAadl2Factory().createPropertyAssociation();
                // Set property
                newPa.setProperty(currentWindow.getSelectedProperty());
                // Set applies to
                if (ciBoc != bocToBind) {
                    setContainedNamedElementPath(newPa.createAppliesTo(), ciBoc, bocToBind);
                }
                // Create owned values
                final ModalPropertyValue pv = newPa.createOwnedValue();
                final ListValue lv = (ListValue) pv.createOwnedValue(Aadl2Package.eINSTANCE.getListValue());
                for (final BusinessObjectContext targetBoc : currentWindow.getTargetBocs()) {
                    // Ignore diagram selections
                    final ReferenceValue rv = (ReferenceValue) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getReferenceValue());
                    setContainedNamedElementPath(rv, ciBoc, targetBoc);
                }
                removeOldPropertyAssociation(ci, newPa);
                // Add the property association
                ci.setNoProperties(false);
                ci.getOwnedPropertyAssociations().add(newPa);
            }
        }

        // Deletes any existing property associations/removes the bound element from any property associations that matches the property association
        // being created.
        private void removeOldPropertyAssociation(final ComponentClassifier cc, final PropertyAssociation newPa) {
            final List<PropertyAssociation> propertyAssociationsToDelete = new ArrayList<PropertyAssociation>();
            for (final PropertyAssociation existingPa : cc.getOwnedPropertyAssociations()) {
                // If Property matches
                if (newPa.getProperty().getFullName().equals(existingPa.getProperty().getFullName())) {
                    if (existingPa.getAppliesTos().size() == 0 || newPa.getAppliesTos().size() == 0) {
                        if (existingPa.getAppliesTos().size() == 0 && newPa.getAppliesTos().size() == 0) {
                            propertyAssociationsToDelete.add(existingPa);
                        }
                    } else {
                        final List<ContainedNamedElement> containedElementsToDelete = new ArrayList<ContainedNamedElement>();
                        for (final ContainedNamedElement existingContainedElement : existingPa.getAppliesTos()) {
                            if (containmentPathsMatch(existingContainedElement.getPath(), newPa.getAppliesTos().get(0).getPath())) {
                                // Add the contained element to the list of objects to delete
                                containedElementsToDelete.add(existingContainedElement);
                            }
                        }
                        // Delete objects
                        for (final EObject ce : containedElementsToDelete) {
                            EcoreUtil.delete(ce);
                        }
                        // Delete the property association if it was the last element in the applies to clause
                        if (existingPa.getAppliesTos().size() == 0) {
                            propertyAssociationsToDelete.add(existingPa);
                        }
                    }
                }
            }
            // Delete property association(s) that are being replaced
            for (final PropertyAssociation pa : propertyAssociationsToDelete) {
                EcoreUtil.delete(pa);
            }
        }
    }));
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) SimpleModifier(org.osate.ge.internal.services.AadlModificationService.SimpleModifier) EObject(org.eclipse.emf.ecore.EObject) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with SimpleModifier

use of org.osate.ge.internal.services.AadlModificationService.SimpleModifier in project osate2 by osate.

the class PasteAction method run.

@Override
public void run() {
    // Get services
    final Bundle bundle = FrameworkUtil.getBundle(getClass());
    final IEclipseContext context = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
    final AadlModificationService aadlModificationService = Objects.requireNonNull(context.getActive(AadlModificationService.class), "Unable to retrieve AADL modification service");
    final ReferenceBuilderService refBuilder = Objects.requireNonNull(context.getActive(ReferenceBuilderService.class), "Unable to retrieve reference builder service");
    // Perform modification
    final DiagramNode dstDiagramNode = getDestinationDiagramNode();
    final EObject dstBo = getDestinationEObject(dstDiagramNode);
    final AgeDiagram diagram = DiagramElementUtil.getDiagram(dstDiagramNode);
    final List<DiagramElement> newDiagramElements = new ArrayList<>();
    diagram.modify("Paste", m -> {
        // The modifier will do the actual copying to the diagram elements. It will also copy the business objects
        // if the copied element includes the business object.
        final SimpleModifier<EObject> modifier = dstBoToModify -> {
            newDiagramElements.addAll(copyClipboardContents(dstBoToModify, dstDiagramNode, m, refBuilder));
        };
        // If any non-embedded business objects have been copied, then modify the AADL model. Otherwise, just modify the diagram.
        final boolean anyHaveNonEmbeddedBo = getCopiedDiagramElements().stream().anyMatch(de -> de.getCopiedBusinessObject() instanceof EObject);
        if (anyHaveNonEmbeddedBo) {
            aadlModificationService.modify(dstBo, modifier);
        } else {
            modifier.modify(null);
        }
        // Update the diagram. This will set business objects and update the diagram to be consistent.
        editor.getDiagramUpdater().updateDiagram(diagram);
    });
    // Update selection to match created diagram elements
    editor.selectDiagramNodes(newDiagramElements);
}
Also used : Element(org.osate.aadl2.Element) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) RenameUtil(org.osate.ge.internal.ui.RenameUtil) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) ClipboardService(org.osate.ge.internal.services.ClipboardService) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) Classifier(org.osate.aadl2.Classifier) ComponentType(org.osate.aadl2.ComponentType) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Bundle(org.osgi.framework.Bundle) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Collection(java.util.Collection) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) Point(org.osate.ge.graphics.Point) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) Objects(java.util.Objects) List(java.util.List) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Feature(org.osate.aadl2.Feature) ComponentImplementation(org.osate.aadl2.ComponentImplementation) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) ArrayList(java.util.ArrayList) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) EClass(org.eclipse.emf.ecore.EClass) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Predicates(com.google.common.base.Predicates) GetNameContext(org.osate.ge.businessobjecthandling.GetNameContext) SimpleModifier(org.osate.ge.internal.services.AadlModificationService.SimpleModifier) Subcomponent(org.osate.aadl2.Subcomponent) XtextResource(org.eclipse.xtext.resource.XtextResource) AadlNameUtil(org.osate.ge.aadl2.internal.util.AadlNameUtil) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Action(org.eclipse.jface.action.Action) CanRenameContext(org.osate.ge.businessobjecthandling.CanRenameContext) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) ComponentTypeRename(org.osate.aadl2.ComponentTypeRename) ActionFactory(org.eclipse.ui.actions.ActionFactory) NamedElement(org.osate.aadl2.NamedElement) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) EObject(org.eclipse.emf.ecore.EObject) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Aggregations

ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 ComponentImplementation (org.osate.aadl2.ComponentImplementation)2 SimpleModifier (org.osate.ge.internal.services.AadlModificationService.SimpleModifier)2 Predicates (com.google.common.base.Predicates)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 EclipseContextFactory (org.eclipse.e4.core.contexts.EclipseContextFactory)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 EClass (org.eclipse.emf.ecore.EClass)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 Action (org.eclipse.jface.action.Action)1 ActionFactory (org.eclipse.ui.actions.ActionFactory)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 AadlPackage (org.osate.aadl2.AadlPackage)1 Classifier (org.osate.aadl2.Classifier)1 ComponentClassifier (org.osate.aadl2.ComponentClassifier)1