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();
}));
}
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());
}
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();
});
}
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();
});
}
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();
});
}));
}
Aggregations