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);
}
}
}));
}
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);
}
Aggregations