Search in sources :

Example 1 with GetCreateConnectionOperationContext

use of org.osate.ge.palette.GetCreateConnectionOperationContext in project osate2 by osate.

the class CreateModeTransitionPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
    if (!ctx.getDestination().getBusinessObject(Mode.class).isPresent()) {
        return Optional.empty();
    }
    final List<ComponentClassifier> potentialOwners = getPotentialOwners(ctx.getSource(), ctx.getDestination(), ctx.getQueryService());
    if (potentialOwners.size() == 0) {
        return Optional.empty();
    }
    final BusinessObjectContext container = getOwnerBoc(ctx.getSource(), ctx.getQueryService());
    if (container == null) {
        return Optional.empty();
    }
    final Mode srcMode = ctx.getSource().getBusinessObject(Mode.class).get();
    final Mode dstMode = ctx.getDestination().getBusinessObject(Mode.class).get();
    return Optional.of(Operation.createPromptAndModifyWithExtra(() -> {
        // Determine which classifier should own the new element
        final ComponentClassifier selectedClassifier = AadlUiUtil.getBusinessObjectToModify(potentialOwners);
        if (selectedClassifier == null) {
            return Optional.empty();
        }
        // Prompt for transition triggers
        final ModeTransitionTriggerInfo[] selectedTriggers = ModeTransitionTriggerSelectionDialog.promptForTriggers(selectedClassifier, null);
        if (selectedTriggers == null) {
            return Optional.empty();
        }
        return Optional.of(new BusinessObjectAndExtra<>(selectedClassifier, selectedTriggers));
    }, args -> {
        final ComponentClassifier cc = args.getBusinessObject();
        // Determine the name for the new mode transition
        final String newElementName = AadlNamingUtil.buildUniqueIdentifier(cc, "new_transition");
        // Create the new mode transition
        final ModeTransition newModeTransition = cc.createOwnedModeTransition();
        // Clear the no modes flag
        cc.setNoModes(false);
        // Set the name
        newModeTransition.setName(newElementName);
        // Set the source and destination
        newModeTransition.setSource(srcMode);
        newModeTransition.setDestination(dstMode);
        // Create Triggers
        for (ModeTransitionTriggerInfo selectedPort : args.getExtra()) {
            final ModeTransitionTrigger mtt = newModeTransition.createOwnedTrigger();
            mtt.setTriggerPort(selectedPort.port);
            mtt.setContext(selectedPort.context);
        }
        return StepResultBuilder.create().showNewBusinessObject(container, newModeTransition).build();
    }));
}
Also used : Element(org.osate.aadl2.Element) BusinessObjectAndExtra(org.osate.ge.operations.BusinessObjectAndExtra) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger) ComponentClassifier(org.osate.aadl2.ComponentClassifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) ModeTransition(org.osate.aadl2.ModeTransition) Aadl2Package(org.osate.aadl2.Aadl2Package) Subcomponent(org.osate.aadl2.Subcomponent) ModeTransitionTriggerSelectionDialog(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog) Operation(org.osate.ge.operations.Operation) Collectors(java.util.stream.Collectors) Mode(org.osate.aadl2.Mode) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) QueryService(org.osate.ge.services.QueryService) AadlCategories(org.osate.ge.aadl2.AadlCategories) ModeTransitionTriggerInfo(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog.ModeTransitionTriggerInfo) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) ExecutableQuery(org.osate.ge.query.ExecutableQuery) Collections(java.util.Collections) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Mode(org.osate.aadl2.Mode) BusinessObjectAndExtra(org.osate.ge.operations.BusinessObjectAndExtra) ModeTransition(org.osate.aadl2.ModeTransition) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ModeTransitionTriggerInfo(org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog.ModeTransitionTriggerInfo) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Example 2 with GetCreateConnectionOperationContext

use of org.osate.ge.palette.GetCreateConnectionOperationContext in project osate2 by osate.

the class CreateTransitionPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
    if (!ctx.getDestination().getBusinessObject(BehaviorState.class).isPresent()) {
        return Optional.empty();
    }
    final BusinessObjectContext srcContainer = getOwnerBoc(ctx.getSource(), ctx.getQueryService());
    if (srcContainer == null) {
        return Optional.empty();
    }
    final BusinessObjectContext dstContainer = getOwnerBoc(ctx.getDestination(), ctx.getQueryService());
    if (dstContainer != srcContainer) {
        return Optional.empty();
    }
    final BehaviorState srcState = ctx.getSource().getBusinessObject(BehaviorState.class).orElseThrow();
    final BehaviorState dstState = ctx.getDestination().getBusinessObject(BehaviorState.class).orElseThrow();
    return srcContainer.getBusinessObject(BehaviorAnnex.class).map(ba -> Operation.createSimple(srcContainer, BehaviorAnnex.class, boToModify -> {
        final BehaviorTransition baTransition = (BehaviorTransition) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorTransition());
        final String srcName = srcState.getName();
        final String dstName = dstState.getName();
        if (srcName == null || dstName == null) {
            return StepResultBuilder.create().abort().build();
        }
        // Set source and destination for transition
        for (final BehaviorState behaviorState : boToModify.getStates()) {
            final String name = behaviorState.getName();
            if (srcName.equalsIgnoreCase(name)) {
                // Source
                baTransition.setSourceState(behaviorState);
            }
            if (dstName.equalsIgnoreCase(name)) {
                // Destination
                baTransition.setDestinationState(behaviorState);
            }
        }
        // Add new transition
        boToModify.getTransitions().add(baTransition);
        final String name = getTransitionName(baTransition);
        baTransition.setName(name);
        // Show
        return StepResultBuilder.create().showNewBusinessObject(srcContainer, baTransition).build();
    })).orElse(Optional.empty());
}
Also used : BehaviorAnnexNamingUtil(org.osate.ge.ba.util.BehaviorAnnexNamingUtil) Operation(org.osate.ge.operations.Operation) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) BehaviorState(org.osate.ba.aadlba.BehaviorState) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) QueryService(org.osate.ge.services.QueryService) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) Optional(java.util.Optional) ExecutableQuery(org.osate.ge.query.ExecutableQuery) AadlBaPackage(org.osate.ba.aadlba.AadlBaPackage) BehaviorState(org.osate.ba.aadlba.BehaviorState) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition)

Example 3 with GetCreateConnectionOperationContext

use of org.osate.ge.palette.GetCreateConnectionOperationContext in project osate2 by osate.

the class CreatePropagatonPathPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
    // Check the type of the destination business object
    if (!isValidEndpoint(ctx.getDestination())) {
        return Optional.empty();
    }
    // Find the common ancestor which is a source for the classifier to update
    final BusinessObjectContext classifierSourceBoc = BusinessObjectContext.getFirstCommonAncestor(ctx.getSource().getParent(), ctx.getDestination().getParent()).flatMap(ancestor -> ErrorModelGeUtil.getClassifierSourceBoc(ancestor)).orElse(null);
    if (classifierSourceBoc == null) {
        return Optional.empty();
    }
    return ErrorModelGeUtil.createErrorModelSubclauseModifyOperation(classifierSourceBoc, subclause -> {
        final PropagationPath newPath = ErrorModelFactory.eINSTANCE.createPropagationPath();
        final String newName = ErrorModelNamingUtil.buildUniqueIdentifier(subclause.getContainingClassifier(), "new_propagation_path");
        newPath.setName(newName);
        newPath.setSource(createQualifiedPropagationPoint(subclause, ctx.getSource(), classifierSourceBoc));
        newPath.setTarget(createQualifiedPropagationPoint(subclause, ctx.getDestination(), classifierSourceBoc));
        subclause.getPaths().add(newPath);
        return StepResultBuilder.create().showNewBusinessObject(classifierSourceBoc, newPath).build();
    });
}
Also used : URI(org.eclipse.emf.common.util.URI) Feature(org.osate.aadl2.Feature) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) Subcomponent(org.osate.aadl2.Subcomponent) FeatureGroup(org.osate.aadl2.FeatureGroup) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) SubcomponentElement(org.osate.xtext.aadl2.errormodel.errorModel.SubcomponentElement) QualifiedPropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedPropagationPoint) Operation(org.osate.ge.operations.Operation) EObject(org.eclipse.emf.ecore.EObject) PropagationPath(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPath) ErrorModelNamingUtil(org.osate.ge.errormodel.util.ErrorModelNamingUtil) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) ErrorModelSubclause(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelSubclause) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) PropagationPath(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPath) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 4 with GetCreateConnectionOperationContext

use of org.osate.ge.palette.GetCreateConnectionOperationContext in project osate2 by osate.

the class CreateErrorPathPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
    // Check if the destination is a potential end
    if (!ErrorFlowPaletteCommandUtil.isPotentialEnd(ctx.getDestination())) {
        return Optional.empty();
    }
    // Find the common ancestor which is a source for the classifier to update
    final BusinessObjectContext classifierSourceBoc = BusinessObjectContext.getFirstCommonAncestor(ctx.getSource().getParent(), ctx.getDestination().getParent()).flatMap(ancestor -> ErrorModelGeUtil.getClassifierSourceBoc(ancestor)).orElse(null);
    if (classifierSourceBoc == null) {
        return Optional.empty();
    }
    return ErrorModelGeUtil.createErrorModelSubclausePromptAndModifyOperation(classifierSourceBoc, () -> {
        final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(ErrorModelGeUtil.getClassifier(classifierSourceBoc).get());
        // Validate both the source and the destination
        return (ErrorFlowPaletteCommandUtil.validateAndShowError(combined, ctx.getSource(), DirectionType.IN) && ErrorFlowPaletteCommandUtil.validateAndShowError(combined, ctx.getDestination(), DirectionType.OUT)) ? Optional.of(true) : Optional.empty();
    }, (subclause, unused) -> {
        final ErrorPath newFlow = ErrorModelFactory.eINSTANCE.createErrorPath();
        // Set name
        final String newName = ErrorModelNamingUtil.buildUniqueIdentifier(subclause.getContainingClassifier(), "new_error_flow");
        newFlow.setName(newName);
        // Set the incoming and outgoing fields of the flow
        final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(subclause.getContainingClassifier());
        final boolean allSrc = ErrorFlowPaletteCommandUtil.isAll(ctx.getSource());
        if (allSrc) {
            newFlow.setAllIncoming(allSrc);
        } else {
            newFlow.setIncoming(ErrorFlowPaletteCommandUtil.findErrorPropagationOrThrow(combined, ctx.getSource(), DirectionType.IN));
        }
        final boolean allDst = ErrorFlowPaletteCommandUtil.isAll(ctx.getDestination());
        if (allDst) {
            newFlow.setAllOutgoing(allDst);
        } else {
            newFlow.setOutgoing(ErrorFlowPaletteCommandUtil.findErrorPropagationOrThrow(combined, ctx.getDestination(), DirectionType.OUT));
        }
        // Add the flow to the subclause
        subclause.getFlows().add(newFlow);
        return StepResultBuilder.create().showNewBusinessObject(classifierSourceBoc, newFlow).build();
    });
}
Also used : Operation(org.osate.ge.operations.Operation) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) ErrorModelNamingUtil(org.osate.ge.errormodel.util.ErrorModelNamingUtil) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) ErrorModelGeUtil(org.osate.ge.errormodel.util.ErrorModelGeUtil) Optional(java.util.Optional) DirectionType(org.osate.aadl2.DirectionType) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) CombinedErrorModelSubclause(org.osate.ge.errormodel.combined.CombinedErrorModelSubclause) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 5 with GetCreateConnectionOperationContext

use of org.osate.ge.palette.GetCreateConnectionOperationContext in project osate2 by osate.

the class CreateFlowPathSpecificationPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
    final BusinessObjectContext srcBoc = ctx.getSource();
    final Feature srcFeature = srcBoc.getBusinessObject(Feature.class).orElse(null);
    final BusinessObjectContext dstBoc = ctx.getDestination();
    final Feature dstFeature = dstBoc.getBusinessObject(Feature.class).orElse(null);
    if (srcFeature == null || dstFeature == null) {
        return Optional.empty();
    }
    final List<ComponentType> potentialOwners = getPotentialOwners(srcBoc, dstBoc, ctx.getQueryService());
    if (potentialOwners.size() == 0 || !FlowSpecificationCreationUtil.isValidFlowEnd(dstFeature, dstBoc, DirectionType.OUT, ctx.getQueryService())) {
        return Optional.empty();
    }
    final BusinessObjectContext container = FlowSpecificationCreationUtil.getFlowSpecificationOwnerBoc(srcBoc, ctx.getQueryService());
    if (container == null) {
        return Optional.empty();
    }
    return Optional.of(Operation.createWithBuilder(createOp -> {
        AadlUiUtil.selectClassifier(createOp, potentialOwners).modifyPreviousResult(ct -> {
            final FlowSpecification fs = ct.createOwnedFlowSpecification();
            fs.setKind(FlowKind.PATH);
            fs.setName(FlowSpecificationCreationUtil.getNewFlowSpecificationName(ct));
            // Create the flow ends
            final FlowEnd inFlowEnd = fs.createInEnd();
            inFlowEnd.setFeature(srcFeature);
            inFlowEnd.setContext(FlowSpecificationCreationUtil.getContext(srcBoc, ctx.getQueryService()));
            final FlowEnd outFlowEnd = fs.createOutEnd();
            outFlowEnd.setFeature(dstFeature);
            outFlowEnd.setContext(FlowSpecificationCreationUtil.getContext(dstBoc, ctx.getQueryService()));
            ct.setNoFlows(false);
            return StepResultBuilder.create().showNewBusinessObject(container, fs).build();
        });
    }));
}
Also used : FlowSpecification(org.osate.aadl2.FlowSpecification) Feature(org.osate.aadl2.Feature) Operation(org.osate.ge.operations.Operation) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) FlowKind(org.osate.aadl2.FlowKind) List(java.util.List) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) QueryService(org.osate.ge.services.QueryService) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) AadlCategories(org.osate.ge.aadl2.AadlCategories) ComponentType(org.osate.aadl2.ComponentType) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) Optional(java.util.Optional) DirectionType(org.osate.aadl2.DirectionType) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) FlowEnd(org.osate.aadl2.FlowEnd) ComponentType(org.osate.aadl2.ComponentType) FlowSpecification(org.osate.aadl2.FlowSpecification) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Feature(org.osate.aadl2.Feature) FlowEnd(org.osate.aadl2.FlowEnd)

Aggregations

Optional (java.util.Optional)5 BusinessObjectContext (org.osate.ge.BusinessObjectContext)5 Operation (org.osate.ge.operations.Operation)5 StepResultBuilder (org.osate.ge.operations.StepResultBuilder)5 BasePaletteCommand (org.osate.ge.palette.BasePaletteCommand)5 CanStartConnectionContext (org.osate.ge.palette.CanStartConnectionContext)5 CreateConnectionPaletteCommand (org.osate.ge.palette.CreateConnectionPaletteCommand)5 GetCreateConnectionOperationContext (org.osate.ge.palette.GetCreateConnectionOperationContext)5 List (java.util.List)3 QueryService (org.osate.ge.services.QueryService)3 DirectionType (org.osate.aadl2.DirectionType)2 Feature (org.osate.aadl2.Feature)2 Subcomponent (org.osate.aadl2.Subcomponent)2 AadlCategories (org.osate.ge.aadl2.AadlCategories)2 AadlImages (org.osate.ge.aadl2.internal.AadlImages)2 ErrorModelGeUtil (org.osate.ge.errormodel.util.ErrorModelGeUtil)2 ErrorModelNamingUtil (org.osate.ge.errormodel.util.ErrorModelNamingUtil)2 ExecutableQuery (org.osate.ge.query.ExecutableQuery)2 ErrorModelFactory (org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory)2 ArrayList (java.util.ArrayList)1