Search in sources :

Example 1 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project AGREE by loonwerks.

the class ShowInSimulationVariablesViewHandler method getBusinessObjectContexts.

private static List<BusinessObjectContext> getBusinessObjectContexts(final ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) {
        return Collections.emptyList();
    }
    final IStructuredSelection ss = (IStructuredSelection) selection;
    final List<BusinessObjectContext> bocs = new ArrayList<>(ss.size());
    for (final Object sel : ss.toList()) {
        final BusinessObjectContext boc = Adapters.adapt(sel, BusinessObjectContext.class);
        if (boc == null) {
            return Collections.emptyList();
        }
        bocs.add(boc);
    }
    return bocs;
}
Also used : ArrayList(java.util.ArrayList) InstanceObject(org.osate.aadl2.instance.InstanceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 2 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project AGREE by loonwerks.

the class ShowInSimulationVariablesViewHandler method calculateEnabled.

private boolean calculateEnabled(final Object evaluationContext) {
    final SimulationUIService simulationUiService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationUIService.class);
    if (simulationUiService == null) {
        return false;
    }
    final List<BusinessObjectContext> selectedBocs = getSelectedDiagramElementsFromContext(evaluationContext);
    if (simulationUiService.getCurrentState().getEngineState() == null || selectedBocs.size() != 1) {
        return false;
    }
    final Object bo = selectedBocs.get(0).getBusinessObject();
    // Make the command available if there is only one business object selected and it is not the root System instance
    if ((bo instanceof FeatureInstance || bo instanceof ComponentInstance) && bo != ((InstanceObject) bo).getSystemInstance()) {
        final InstanceObject io = (InstanceObject) bo;
        // Compare the references from the diagram and simulation system instances. Only show the command if they match
        final URI diagramSystemInstanceUri = EcoreUtil.getURI(io.getSystemInstance());
        final URI simulationSystemInstanceUri = EcoreUtil.getURI(simulationUiService.getCurrentState().getSimulationEngine().getSystemInstance());
        return diagramSystemInstanceUri != null && diagramSystemInstanceUri.equals(simulationSystemInstanceUri);
    }
    return false;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectContext(org.osate.ge.BusinessObjectContext) URI(org.eclipse.emf.common.util.URI)

Example 3 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project osate2 by osate.

the class CreateAadlConnectionPaletteCommand method getOwnerBoc.

private static BusinessObjectContext getOwnerBoc(final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
    // Search for an appropriate owner. To be appropriate the owner BOC must be a component implementation or a subcomponent which is reachable from both
    // the source and destination BOC.
    int subcomponentsChecked1 = 0;
    BusinessObjectContext temp1 = srcBoc.getParent();
    while (temp1 != null) {
        final Object bo1 = temp1.getBusinessObject();
        if (bo1 instanceof Subcomponent || bo1 instanceof ComponentImplementation) {
            BusinessObjectContext temp2 = dstBoc.getParent();
            int subcomponentsChecked2 = 0;
            while (temp2 != null) {
                final Object bo2 = temp2.getBusinessObject();
                if (bo2 instanceof Subcomponent || bo2 instanceof ComponentImplementation) {
                    if (temp1 == temp2) {
                        return temp1;
                    }
                    if (bo2 instanceof Subcomponent) {
                        subcomponentsChecked2++;
                        // Stop checking at second subcomponent
                        if (subcomponentsChecked2 >= 2) {
                            break;
                        }
                    } else if (bo2 instanceof ComponentImplementation) {
                        // Stop checking at component implementations
                        break;
                    }
                }
                temp2 = temp2.getParent();
            }
            if (temp1.getBusinessObject() instanceof Subcomponent) {
                subcomponentsChecked1++;
                // Stop checking at second subcomponent
                if (subcomponentsChecked1 >= 2) {
                    break;
                }
            } else if (bo1 instanceof ComponentImplementation) {
                // Stop checking at component implementations
                break;
            }
        }
        temp1 = temp1.getParent();
    }
    return null;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 4 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project osate2 by osate.

the class CreateClassifierPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(EObject.class).map(targetBo -> {
        if (!(targetBo instanceof AadlPackage || isValidBaseClassifier(targetBo))) {
            return null;
        }
        final BusinessObjectContext pkgBoc = getPackageBoc(ctx.getTarget(), ctx.getQueryService());
        if (pkgBoc == null) {
            return null;
        }
        final AadlPackage pkg = (AadlPackage) pkgBoc.getBusinessObject();
        final IProject project = ProjectUtil.getProjectForBoOrThrow(pkg);
        final ResourceSet rs = targetBo.eResource().getResourceSet();
        return Operation.createWithBuilder(builder -> {
            builder.supply(() -> {
                final ClassifierOperation args = buildCreateOperations(pkg, targetBo, project, rs);
                if (args == null) {
                    return StepResult.abort();
                }
                return StepResult.forValue(args);
            }).executeOperation(classifierOp -> Operation.createWithBuilder(innerBuilder -> {
                final ClassifierOperationExecutor opExec = new ClassifierOperationExecutor(rs, project);
                opExec.execute(innerBuilder, classifierOp, pkgBoc);
            }));
        });
    });
}
Also used : DefaultCreateSelectClassifierDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultCreateSelectClassifierDialogModel) StepResult(org.osate.ge.operations.StepResult) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ClassifierOperationDialog(org.osate.ge.aadl2.ui.internal.dialogs.ClassifierOperationDialog) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) IProject(org.eclipse.core.resources.IProject) EClass(org.eclipse.emf.ecore.EClass) Classifier(org.osate.aadl2.Classifier) ImmutableList(com.google.common.collect.ImmutableList) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) Aadl2Package(org.osate.aadl2.Aadl2Package) EnumSet(java.util.EnumSet) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation) ClassifierOperationPartType(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPartType) GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) Operation(org.osate.ge.operations.Operation) Collection(java.util.Collection) ClassifierOperationExecutor(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationExecutor) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) Display(org.eclipse.swt.widgets.Display) ProjectUtil(org.osate.ge.ProjectUtil) QueryService(org.osate.ge.services.QueryService) ComponentCategory(org.osate.aadl2.ComponentCategory) StringUtil(org.osate.ge.StringUtil) AadlCategories(org.osate.ge.aadl2.AadlCategories) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) ClassifierOperationPart(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPart) ExecutableQuery(org.osate.ge.query.ExecutableQuery) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) AadlPackage(org.osate.aadl2.AadlPackage) ClassifierOperationExecutor(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationExecutor) EObject(org.eclipse.emf.ecore.EObject) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) BusinessObjectContext(org.osate.ge.BusinessObjectContext) IProject(org.eclipse.core.resources.IProject)

Example 5 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project osate2 by osate.

the class CreateFlowSourceSinkSpecificationPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(Feature.class).map(feature -> {
        final DirectionType requiredDirection;
        if (flowKind == FlowKind.SOURCE) {
            requiredDirection = DirectionType.OUT;
        } else if (flowKind == FlowKind.SINK) {
            requiredDirection = DirectionType.IN;
        } else {
            return null;
        }
        final List<ComponentType> potentialOwners = FlowSpecificationCreationUtil.getPotentialOwnersByFeature(ctx.getTarget(), ctx.getQueryService());
        if (potentialOwners.isEmpty() || !FlowSpecificationCreationUtil.isValidFlowEnd(feature, ctx.getTarget(), requiredDirection, ctx.getQueryService())) {
            return null;
        }
        final BusinessObjectContext container = FlowSpecificationCreationUtil.getFlowSpecificationOwnerBoc(ctx.getTarget(), ctx.getQueryService());
        if (container == null) {
            return null;
        }
        return Operation.createWithBuilder(createOp -> {
            AadlUiUtil.selectClassifier(createOp, potentialOwners).modifyPreviousResult(ct -> {
                final FlowSpecification fs = ct.createOwnedFlowSpecification();
                fs.setKind(flowKind);
                fs.setName(FlowSpecificationCreationUtil.getNewFlowSpecificationName(ct));
                // Create the appropriate flow end depending on the type being created
                final FlowEnd flowEnd;
                if (flowKind == FlowKind.SOURCE) {
                    flowEnd = fs.createOutEnd();
                } else if (flowKind == FlowKind.SINK) {
                    flowEnd = fs.createInEnd();
                } else {
                    throw new RuntimeException("Unexpected flow kind: " + flowKind);
                }
                flowEnd.setFeature(feature);
                flowEnd.setContext(FlowSpecificationCreationUtil.getContext(ctx.getTarget(), ctx.getQueryService()));
                // Clear the no flows flag
                ct.setNoFlows(false);
                return StepResultBuilder.create().showNewBusinessObject(container, fs).build();
            });
        });
    });
}
Also used : DirectionType(org.osate.aadl2.DirectionType) ComponentType(org.osate.aadl2.ComponentType) FlowSpecification(org.osate.aadl2.FlowSpecification) Feature(org.osate.aadl2.Feature) BusinessObjectContext(org.osate.ge.BusinessObjectContext) FlowEnd(org.osate.aadl2.FlowEnd)

Aggregations

BusinessObjectContext (org.osate.ge.BusinessObjectContext)104 List (java.util.List)26 Optional (java.util.Optional)22 NamedElement (org.osate.aadl2.NamedElement)20 Subcomponent (org.osate.aadl2.Subcomponent)20 QueryService (org.osate.ge.services.QueryService)19 Collectors (java.util.stream.Collectors)18 Objects (java.util.Objects)17 EObject (org.eclipse.emf.ecore.EObject)17 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)16 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)16 Collections (java.util.Collections)15 ComponentImplementation (org.osate.aadl2.ComponentImplementation)15 ArrayList (java.util.ArrayList)14 IEditorPart (org.eclipse.ui.IEditorPart)14 ComponentClassifier (org.osate.aadl2.ComponentClassifier)12 InstanceObject (org.osate.aadl2.instance.InstanceObject)12 Adapters (org.eclipse.core.runtime.Adapters)11 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)10 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)8