Search in sources :

Example 1 with CanCopyContext

use of org.osate.ge.businessobjecthandling.CanCopyContext in project osate2 by osate.

the class CopyAction method allBusinessObjectsAreCopyable.

/**
 * Returns true if all business object are copyable. A business object is copyable if it is an embedded business object or
 * if it is an EObject contained in a many feature.
 * @param diagramElements
 * @return
 */
private static boolean allBusinessObjectsAreCopyable(final Collection<DiagramElement> diagramElements) {
    return diagramElements.stream().allMatch(de -> {
        if (!de.getBusinessObjectHandler().canCopy(new CanCopyContext(de.getBusinessObject()))) {
            return false;
        }
        final Object bo = de.getBusinessObject();
        if (bo instanceof EmbeddedBusinessObject) {
            return true;
        }
        if (!(bo instanceof EObject)) {
            return false;
        }
        final EObject eObj = (EObject) bo;
        final EStructuralFeature containgFeature = eObj.eContainingFeature();
        return containgFeature != null && containgFeature.isMany();
    });
}
Also used : EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EObject(org.eclipse.emf.ecore.EObject) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) CanCopyContext(org.osate.ge.businessobjecthandling.CanCopyContext)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 CanCopyContext (org.osate.ge.businessobjecthandling.CanCopyContext)1 EmbeddedBusinessObject (org.osate.ge.internal.model.EmbeddedBusinessObject)1