use of org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog.ModeTransitionTriggerInfo 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();
}));
}
Aggregations