Search in sources :

Example 11 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext 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 12 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project osate2 by osate.

the class CreateSubprogramCallSequencePaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    final BusinessObjectContext targetBoc = ctx.getTarget();
    final Object targetBo = targetBoc.getBusinessObject();
    if (!getClassifierOpBuilder().canBuildOperation(targetBo)) {
        return Optional.empty();
    }
    // Used to pass arguments between steps
    class CreateArgs {

        final BehavioredImplementation bi;

        final CallContext callContext;

        final CalledSubprogram calledSubprogram;

        public CreateArgs(final BehavioredImplementation bi, final CallContext callContext, final CalledSubprogram calledSubprogram) {
            this.bi = bi;
            this.callContext = callContext;
            this.calledSubprogram = calledSubprogram;
        }
    }
    return Optional.of(Operation.createWithBuilder(createOp -> {
        getClassifierOpBuilder().buildOperation(createOp, targetBo).map(ci -> {
            final BehavioredImplementation bi = (BehavioredImplementation) ci;
            final DefaultSelectSubprogramDialogModel subprogramSelectionModel = new DefaultSelectSubprogramDialogModel(bi);
            final SelectSubprogramDialog dlg = new SelectSubprogramDialog(Display.getCurrent().getActiveShell(), subprogramSelectionModel);
            if (dlg.open() == Window.CANCEL) {
                return StepResult.abort();
            }
            // Get the CallContext and Called Subprogram
            final CallContext callContext = subprogramSelectionModel.getCallContext(dlg.getSelectedContext());
            final CalledSubprogram calledSubprogram = subprogramSelectionModel.getCalledSubprogram(dlg.getSelectedSubprogram());
            return StepResult.forValue(new CreateArgs(bi, callContext, calledSubprogram));
        }).modifyModel(null, (tag, createArgs) -> createArgs.bi, (tag, bi, createArgs) -> {
            final String newScsName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call_sequence");
            final String initialSubprogramCallName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call");
            final SubprogramCallSequence newScs = bi.createOwnedSubprogramCallSequence();
            newScs.setName(newScsName);
            // Create an initial call. Needed because call sequences must have at least one call
            final SubprogramCall initialSubprogramCall = newScs.createOwnedSubprogramCall();
            initialSubprogramCall.setName(initialSubprogramCallName);
            initialSubprogramCall.setContext(createArgs.callContext);
            initialSubprogramCall.setCalledSubprogram(createArgs.calledSubprogram);
            AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.callContext);
            AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.calledSubprogram);
            return StepResultBuilder.create().showNewBusinessObject(targetBoc, newScs).build();
        });
    }));
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) AadlOperationBuilder(org.osate.ge.aadl2.ui.AadlOperationBuilder) DefaultSelectSubprogramDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel) StepResult(org.osate.ge.operations.StepResult) Operation(org.osate.ge.operations.Operation) ComponentImplementation(org.osate.aadl2.ComponentImplementation) SelectSubprogramDialog(org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) Display(org.eclipse.swt.widgets.Display) CalledSubprogram(org.osate.aadl2.CalledSubprogram) Window(org.eclipse.jface.window.Window) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) AadlCategories(org.osate.ge.aadl2.AadlCategories) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) CallContext(org.osate.aadl2.CallContext) BehavioredImplementation(org.osate.aadl2.BehavioredImplementation) SubprogramCall(org.osate.aadl2.SubprogramCall) Aadl2Package(org.osate.aadl2.Aadl2Package) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) DefaultSelectSubprogramDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel) BehavioredImplementation(org.osate.aadl2.BehavioredImplementation) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) BusinessObjectContext(org.osate.ge.BusinessObjectContext) CallContext(org.osate.aadl2.CallContext) CalledSubprogram(org.osate.aadl2.CalledSubprogram) SubprogramCall(org.osate.aadl2.SubprogramCall) SelectSubprogramDialog(org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog)

Example 13 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project osate2 by osate.

the class FlowContributionItem method onSelection.

@Override
protected void onSelection(final Object value) {
    if (editor != null && !editor.isDisposed() && value != null) {
        @SuppressWarnings("unchecked") final Map.Entry<String, HighlightableFlowInfo> highlightableFlowsMapEntry = (Entry<String, HighlightableFlowInfo>) value;
        final FlowSegmentReference highlightableFlowElement = highlightableFlowsMapEntry.getValue().highlightableFlowElement;
        NamedElement flowSegmentElement = null;
        BusinessObjectContext container = null;
        if (highlightableFlowElement != null) {
            flowSegmentElement = highlightableFlowElement.flowSegmentElement;
            container = highlightableFlowElement.container;
        }
        ContributionUtil.getColoringService(editor).setHighlightedFlow(flowSegmentElement, container);
    }
}
Also used : Entry(java.util.Map.Entry) FlowSegmentReference(org.osate.ge.aadl2.internal.util.AadlFlowSpecificationUtil.FlowSegmentReference) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) NamedElement(org.osate.aadl2.NamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 14 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project osate2 by osate.

the class ConnectionHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    final QueryService queryService = ctx.getQueryService();
    final Connection c = boc.getBusinessObject(Connection.class).orElseThrow();
    final QueryResult src = queryService.getFirstResult(SRC_QUERY, boc, c).orElse(null);
    final QueryResult dst = queryService.getFirstResult(DST_QUERY, boc, c).orElse(null);
    final boolean partial = (src != null && src.isPartial()) || (dst != null && dst.isPartial());
    final StyleBuilder sb = StyleBuilder.create(AadlInheritanceUtil.isInherited(boc) ? Styles.INHERITED_ELEMENT : Style.EMPTY);
    if (partial) {
        sb.dotted();
    }
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(GRAPHIC).style(sb.build()).source(src == null ? null : src.getBusinessObjectContext()).destination(dst == null ? null : dst.getBusinessObjectContext()).build());
}
Also used : QueryResult(org.osate.ge.query.QueryResult) QueryService(org.osate.ge.services.QueryService) Connection(org.osate.aadl2.Connection) StyleBuilder(org.osate.ge.graphics.StyleBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 15 with BusinessObjectContext

use of org.osate.ge.BusinessObjectContext in project osate2 by osate.

the class FeatureHandler method getGraphicalConfiguration.

@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
    final BusinessObjectContext featureBoc = ctx.getBusinessObjectContext();
    final NamedElement feature = featureBoc.getBusinessObject(NamedElement.class).get();
    final FeatureGraphic graphic = getGraphicalRepresentation(feature, featureBoc);
    return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).annotation(AadlGraphics.getFeatureAnnotation(feature.eClass())).style(StyleBuilder.create(AadlInheritanceUtil.isInherited(featureBoc) ? Styles.INHERITED_ELEMENT : Style.EMPTY).backgroundColor(AadlGraphics.getDefaultBackgroundColor(graphic.featureType)).labelsAboveTop().labelsLeft().build()).defaultDockingPosition(getDefaultDockingPosition(feature, featureBoc)).build());
}
Also used : FeatureGraphic(org.osate.ge.graphics.internal.FeatureGraphic) BusinessObjectContext(org.osate.ge.BusinessObjectContext) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

BusinessObjectContext (org.osate.ge.BusinessObjectContext)104 List (java.util.List)26 Optional (java.util.Optional)22 NamedElement (org.osate.aadl2.NamedElement)20 Subcomponent (org.osate.aadl2.Subcomponent)20 QueryService (org.osate.ge.services.QueryService)19 Collectors (java.util.stream.Collectors)18 Objects (java.util.Objects)17 EObject (org.eclipse.emf.ecore.EObject)17 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)16 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)16 Collections (java.util.Collections)15 ComponentImplementation (org.osate.aadl2.ComponentImplementation)15 ArrayList (java.util.ArrayList)14 IEditorPart (org.eclipse.ui.IEditorPart)14 ComponentClassifier (org.osate.aadl2.ComponentClassifier)12 InstanceObject (org.osate.aadl2.instance.InstanceObject)12 Adapters (org.eclipse.core.runtime.Adapters)11 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)10 RelativeBusinessObjectReference (org.osate.ge.RelativeBusinessObjectReference)8