Search in sources :

Example 1 with BusinessObjectAndExtra

use of org.osate.ge.operations.BusinessObjectAndExtra 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)

Aggregations

Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Aadl2Package (org.osate.aadl2.Aadl2Package)1 ComponentClassifier (org.osate.aadl2.ComponentClassifier)1 Element (org.osate.aadl2.Element)1 Mode (org.osate.aadl2.Mode)1 ModeTransition (org.osate.aadl2.ModeTransition)1 ModeTransitionTrigger (org.osate.aadl2.ModeTransitionTrigger)1 Subcomponent (org.osate.aadl2.Subcomponent)1 BusinessObjectContext (org.osate.ge.BusinessObjectContext)1 AadlCategories (org.osate.ge.aadl2.AadlCategories)1 AadlImages (org.osate.ge.aadl2.internal.AadlImages)1 AadlNamingUtil (org.osate.ge.aadl2.internal.AadlNamingUtil)1 AadlUiUtil (org.osate.ge.aadl2.ui.internal.AadlUiUtil)1 ModeTransitionTriggerSelectionDialog (org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog)1 ModeTransitionTriggerInfo (org.osate.ge.aadl2.ui.internal.dialogs.ModeTransitionTriggerSelectionDialog.ModeTransitionTriggerInfo)1 BusinessObjectAndExtra (org.osate.ge.operations.BusinessObjectAndExtra)1 Operation (org.osate.ge.operations.Operation)1