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