use of org.osate.ge.operations.Operation 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();
});
}
use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateTransitionPaletteCommand method buildCreateOperation.
private Operation buildCreateOperation(final BusinessObjectContext srcBoc, final ErrorBehaviorState targetStateReadonly) {
final Object srcBo = srcBoc.getBusinessObject();
final URI targetStateUri = EcoreUtil.getURI(targetStateReadonly);
if (srcBo instanceof ErrorBehaviorState) {
final ErrorBehaviorState srcStateReadonly = (ErrorBehaviorState) srcBo;
final URI srcStateUri = EcoreUtil.getURI(srcStateReadonly);
return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(getStateMachine(srcStateReadonly))).modifyPreviousResult(stateMachine -> {
final ErrorBehaviorState targetState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(targetStateUri, true);
final ErrorBehaviorState srcState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(srcStateUri, true);
final NamedElementCollectionSingleSelectorModel<ErrorBehaviorEvent> model = new NamedElementCollectionSingleSelectorModel<>(stateMachine.getEvents());
if (!FilteringSelectorDialog.open(Display.getCurrent().getActiveShell(), "Select Event", new LabelFilteringListSelectorModel<>(model))) {
return null;
}
final ErrorBehaviorEvent event = model.getSelectedElement();
// Create the transition
final ErrorBehaviorTransition newTransition = ErrorModelFactory.eINSTANCE.createErrorBehaviorTransition();
newTransition.setSource(srcState);
// Set the target
if (srcState == targetState) {
newTransition.setSteadyState(true);
} else {
newTransition.setTarget(targetState);
}
newTransition.setName(ErrorModelNamingUtil.buildUniqueIdentifier(stateMachine, "new_transition"));
final ConditionElement conditionElement = ErrorModelFactory.eINSTANCE.createConditionElement();
newTransition.setCondition(conditionElement);
final EMV2PathElement conditionPathElement = ErrorModelFactory.eINSTANCE.createEMV2PathElement();
conditionPathElement.setNamedElement(event);
final QualifiedErrorEventOrPropagation errorEventOrPropogation = ErrorModelFactory.eINSTANCE.createQualifiedErrorEventOrPropagation();
errorEventOrPropogation.setEmv2Target(conditionPathElement);
conditionElement.setQualifiedErrorPropagationReference(errorEventOrPropogation);
stateMachine.getTransitions().add(newTransition);
return StepResultBuilder.create().showNewBusinessObject(srcBoc.getParent(), newTransition).build();
}));
} else if (srcBo instanceof ErrorBehaviorTransition || srcBo instanceof BehaviorTransitionTrunk || srcBo instanceof TransitionBranch) {
// Get the transition to modify
final ErrorBehaviorTransition transitionReadonly;
if (srcBo instanceof ErrorBehaviorTransition) {
transitionReadonly = (ErrorBehaviorTransition) srcBo;
} else if (srcBo instanceof BehaviorTransitionTrunk) {
transitionReadonly = ((BehaviorTransitionTrunk) srcBo).getTransition();
} else if (srcBo instanceof TransitionBranch) {
transitionReadonly = (ErrorBehaviorTransition) ((TransitionBranch) srcBo).eContainer();
} else {
throw new AadlGraphicalEditorException("Unexpected case: " + srcBo);
}
return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(transitionReadonly)).modifyPreviousResult(transition -> {
final ErrorBehaviorState targetState = (ErrorBehaviorState) transition.eResource().getResourceSet().getEObject(targetStateUri, true);
// Convert from using steady state and target field to using branches.
if (transition.getDestinationBranches().isEmpty()) {
final TransitionBranch firstBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
final BranchValue firstBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
firstBranchValue.setRealvalue("1.0");
if (transition.isSteadyState()) {
firstBranch.setSteadyState(true);
} else {
firstBranch.setTarget(transition.getTarget());
}
firstBranch.setValue(firstBranchValue);
transition.getDestinationBranches().add(firstBranch);
transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_Target());
transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_TargetToken());
transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_SteadyState());
}
// Create the new branch
final TransitionBranch newBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
final BranchValue newBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
newBranchValue.setRealvalue("1.0");
// Set the target
if (transition.getSource() == targetState) {
newBranch.setSteadyState(true);
} else {
newBranch.setTarget(targetState);
}
newBranch.setValue(newBranchValue);
transition.getDestinationBranches().add(newBranch);
return StepResultBuilder.create().build();
}));
} else {
throw new AadlGraphicalEditorException("Unsupported case: " + srcBo);
}
}
use of org.osate.ge.operations.Operation 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();
});
}
use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateErrorPropagationPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
final Object bo = ctx.getTarget().getBusinessObject();
if (bo instanceof Feature) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the feature in the context of the EMV subclause. This is needed for reliable serialization.
final List<URI> path = ErrorModelGeUtil.createQualifiedPropagationPointPath(ctx.getTarget(), ErrorModelGeUtil.getClassifierSourceBoc(ctx.getTarget()).get(), new ArrayList<>());
newPropagation.setFeatureorPPRef(buildFeatureReference(subclause.eResource().getResourceSet(), path));
});
} else if (bo instanceof KeywordPropagationPoint) {
final KeywordPropagationPoint kw = (KeywordPropagationPoint) bo;
if (kw.getType() != KeywordPropagationPointType.ALL) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> newPropagation.setKind(kw.getType().getKind()));
}
} else if (bo instanceof PropagationPoint) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the propagation in the context of the EMV subclause.
// Check inherited subclauses as well. This is needed for reliable serialization.
final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(subclause.getContainingClassifier());
final String boName = ((PropagationPoint) bo).getName();
final PropagationPoint pp = combined.getPoints().filter(p -> Objects.equal(p.getName(), boName)).findAny().orElseThrow(() -> new AadlGraphicalEditorException("Unable to find propagation point"));
final FeatureorPPReference ppRef = ErrorModelFactory.eINSTANCE.createFeatureorPPReference();
ppRef.setFeatureorPP(pp);
newPropagation.setFeatureorPPRef(ppRef);
});
}
return Optional.empty();
}
use of org.osate.ge.operations.Operation in project osate2 by osate.
the class CreateErrorPropagationPaletteCommand method createPropgationCreationOperation.
/**
* Creates an operation for creating a propagation for the target.
* @param target is the target of the propagation. It should be the context which will be the parent of the propagation
* @param init function called to finish initializing the propagation. It must set the kind or the feature or PP reference.
* @return the operation or an empty optional if a classifier could not be determined.
*/
private Optional<Operation> createPropgationCreationOperation(final BusinessObjectContext target, final BiConsumer<ErrorPropagation, ErrorModelSubclause> init) {
return ErrorModelGeUtil.getClassifierSourceBoc(target).flatMap(container -> {
final AadlPackage pkg = container.getBusinessObject(NamedElement.class).map(ne -> ne.getElementRoot()).map(root -> root instanceof AadlPackage ? ((AadlPackage) root) : null).orElseThrow(() -> new AadlGraphicalEditorException("Unable to find model"));
return ErrorModelGeUtil.createErrorModelSubclausePromptAndModifyOperation(container, () -> {
if (propagationAlreadyExists(target)) {
final String propagationOrContainmentLabel = (containment ? "containment" : "propagation");
final String inputOrOutputLabel = direction == DirectionType.IN ? "intput" : "output";
MessageDialog.openError(Display.getDefault().getActiveShell(), "Unable to create " + propagationOrContainmentLabel, "Propagation already exists. A propagation point may only have one " + inputOrOutputLabel + " error " + propagationOrContainmentLabel + " defined.");
return Optional.empty();
}
return ErrorModelUiUtil.promptForTypeSet(pkg);
}, (subclause, typeSet) -> {
final ErrorPropagation newPropagation = ErrorModelFactory.eINSTANCE.createErrorPropagation();
newPropagation.setTypeSet(typeSet);
newPropagation.setNot(containment);
newPropagation.setDirection(direction);
init.accept(newPropagation, subclause);
subclause.getPropagations().add(newPropagation);
return StepResultBuilder.create().showNewBusinessObject(target, newPropagation).build();
});
});
}
Aggregations