Search in sources :

Example 1 with BusinessObjectHandler

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

the class DefaultReferenceService method getRelativeReference.

@Override
public RelativeBusinessObjectReference getRelativeReference(final Object bo) {
    Objects.requireNonNull(bo, "bo must not be null");
    final BusinessObjectHandler boh = bohProvider.getApplicableBusinessObjectHandler(bo);
    if (boh == null) {
        return null;
    }
    try {
        return Objects.requireNonNull(boh.getRelativeReference(new ReferenceContext(bo, this)), () -> "Business object handlers must not return a null relative reference. Null reference returned by '" + boh.getClass().getCanonicalName() + "'");
    } catch (RuntimeException ex) {
        StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error retrieving relative reference for " + bo.getClass().getCanonicalName() + ".", ex), StatusManager.LOG | StatusManager.SHOW);
        return null;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ReferenceContext(org.osate.ge.businessobjecthandling.ReferenceContext) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler)

Example 2 with BusinessObjectHandler

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

the class EditorRenameUtil method canRename.

public static boolean canRename(final DiagramElement de) {
    final Object bo = de.getBusinessObject();
    // Only EObjects are supported at this time
    if (!(bo instanceof EObject)) {
        return false;
    }
    final BusinessObjectHandler handler = de.getBusinessObjectHandler();
    if (!handler.canRename(new CanRenameContext(bo))) {
        return false;
    }
    if (!RenameUtil.supportsNonLtkRename(handler) && RenameUtil.getRenameRefactoring(bo) == null) {
        return false;
    }
    return true;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) CanRenameContext(org.osate.ge.businessobjecthandling.CanRenameContext)

Example 3 with BusinessObjectHandler

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

the class DeleteHandler method canDelete.

private boolean canDelete(final DiagramElement de) {
    final Object bo = de.getBusinessObject();
    final BusinessObjectHandler boHandler = de.getBusinessObjectHandler();
    if (boHandler == null) {
        return false;
    }
    // Don't allow proxies.
    if (bo instanceof EObject) {
        final EObject eobj = ((EObject) bo);
        if (eobj.eIsProxy()) {
            return false;
        }
        // Prevent deletion of resources which are part of plugins
        final Resource res = eobj.eResource();
        if (res != null && res.getURI().isPlatformPlugin()) {
            return false;
        }
    }
    return boHandler.canDelete(new CanDeleteContext(bo));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EObject(org.eclipse.emf.ecore.EObject) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) CanDeleteContext(org.osate.ge.businessobjecthandling.CanDeleteContext)

Example 4 with BusinessObjectHandler

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

the class DiagramUpdater method updateStructure.

/**
 * Updates the structure of the diagram based on the business object tree.
 * Creates/Unghosts elements to match the business object tree. Ghosts diagram elements which are not in the diagram element tree.
 * @param m
 * @param container
 * @param bos
 */
private void updateStructure(final DiagramModification m, final DiagramNode container, final Collection<BusinessObjectNode> bos) {
    for (final BusinessObjectNode n : bos) {
        // Get existing element if it exists.
        DiagramElement element = container.getChildByRelativeReference(n.getRelativeReference());
        // Create the element if it does not exist
        if (element == null) {
            final DiagramElement removedGhost = removeGhost(container, n.getRelativeReference());
            if (removedGhost == null) {
                final BusinessObjectHandler boh = infoProvider.getApplicableBusinessObjectHandler(n.getBusinessObject());
                if (boh == null) {
                    // Ignore the object
                    continue;
                }
                element = new DiagramElement(container, n.getBusinessObject(), boh, n.getRelativeReference(), n.getId());
            } else {
                element = removedGhost;
                m.updateBusinessObject(element, n.getBusinessObject(), n.getRelativeReference());
            }
            m.addElement(element);
        } else {
            // Update the business object and relative reference. Although the reference matches. The business object may be new and the
            // relative reference may have case differences.
            m.updateBusinessObject(element, n.getBusinessObject(), n.getRelativeReference());
        }
        // Set the business object handler if it is null
        if (element.getBusinessObjectHandler() == null) {
            final BusinessObjectHandler boh = infoProvider.getApplicableBusinessObjectHandler(n.getBusinessObject());
            if (boh == null) {
                ghostAndRemove(m, element);
                continue;
            } else {
                m.setBusinessObjectHandler(element, boh);
            }
        }
        // Update the element's children
        updateStructure(m, element, n.getChildren());
    }
    // If the collections are the same size, there is nothing to remove
    if (bos.size() != container.getChildren().size()) {
        // Build Set of Relative References of All the Objects in the Business Object Tree
        final Set<RelativeBusinessObjectReference> boTreeRelativeReferenceSet = bos.stream().map((n) -> n.getRelativeReference()).collect(Collectors.toCollection(HashSet::new));
        Iterator<DiagramElement> childrenIt = container.getChildren().iterator();
        while (childrenIt.hasNext()) {
            final DiagramElement child = childrenIt.next();
            if (!boTreeRelativeReferenceSet.contains(child.getRelativeReference())) {
                ghostAndRemove(m, child);
            }
        }
    }
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) HashMap(java.util.HashMap) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) GraphicalConfiguration(org.osate.ge.GraphicalConfiguration) HashSet(java.util.HashSet) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) Map(java.util.Map) ReferenceResolutionService(org.osate.ge.services.ReferenceResolutionService) LinkedList(java.util.LinkedList) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) ActionExecutor(org.osate.ge.internal.services.ActionExecutor) Iterator(java.util.Iterator) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Collection(java.util.Collection) Set(java.util.Set) Point(org.osate.ge.graphics.Point) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) PropertyValueGroup(org.osate.ge.aadl2.internal.model.PropertyValueGroup) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) AgeAction(org.osate.ge.internal.services.AgeAction) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) Collections(java.util.Collections) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler)

Example 5 with BusinessObjectHandler

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

the class DefaultReferenceService method getCanonicalReference.

@Override
public CanonicalBusinessObjectReference getCanonicalReference(final Object bo) {
    Objects.requireNonNull(bo, "bo must not be null");
    final BusinessObjectHandler boh = bohProvider.getApplicableBusinessObjectHandler(bo);
    if (boh == null) {
        return null;
    }
    try {
        return boh.getCanonicalReference(new ReferenceContext(bo, this));
    } catch (RuntimeException ex) {
        StatusManager.getManager().handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error retrieving canonical reference for " + bo.getClass().getCanonicalName() + ".", ex), StatusManager.LOG | StatusManager.SHOW);
        return null;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ReferenceContext(org.osate.ge.businessobjecthandling.ReferenceContext) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler)

Aggregations

BusinessObjectHandler (org.osate.ge.businessobjecthandling.BusinessObjectHandler)8 EObject (org.eclipse.emf.ecore.EObject)5 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 CanonicalBusinessObjectReference (org.osate.ge.CanonicalBusinessObjectReference)2 GetNameContext (org.osate.ge.businessobjecthandling.GetNameContext)2 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)2 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)2 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)2 BusinessObjectProxy (org.osate.ge.internal.model.BusinessObjectProxy)2 EmbeddedBusinessObject (org.osate.ge.internal.model.EmbeddedBusinessObject)2 ActionExecutor (org.osate.ge.internal.services.ActionExecutor)2 ProjectProvider (org.osate.ge.internal.services.ProjectProvider)2