use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.
the class CreateSpecificationPaletteCommand method createBehaviorAnnex.
private static BehaviorAnnex createBehaviorAnnex(final Classifier c) {
final String name = BehaviorAnnexReferenceUtil.ANNEX_NAME;
final BehaviorAnnex ba = GraphicalAnnexUtil.createParsedAnnexSubclause(c, name, AadlBaPackage.eINSTANCE.getBehaviorAnnex(), BehaviorAnnex.class);
ba.setName(name);
return ba;
}
use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.
the class CreateVariablePaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ctx.getTarget().getBusinessObject(BehaviorAnnex.class).map(behaviorAnnex -> {
final PublicPackageSection section = getPackage(behaviorAnnex).map(AadlPackage::getPublicSection).orElse(null);
if (section == null) {
return null;
}
return Operation.createWithBuilder(builder -> {
final OperationBuilder<DataClassifier> prompt = builder.supply(() -> BehaviorAnnexUtil.promptForDataClassifier(behaviorAnnex.eResource()).filter(c -> BehaviorAnnexUtil.getPackage(c).isPresent()).map(StepResult::forValue).orElseGet(StepResult::abort));
final OperationBuilder<DataClassifier> addImportIfNeeded = prompt.modifyModel(null, (tag, prevResult) -> section, (tag, sectionToModify, dataClassifier) -> {
BehaviorAnnexUtil.getPackage(dataClassifier).ifPresent(classifierPkg -> AadlImportsUtil.addImportIfNeeded(sectionToModify, classifierPkg));
return StepResult.forValue(dataClassifier);
});
addImportIfNeeded.modifyModel(null, (tag, dataClassifier) -> behaviorAnnex, (tag, behaviorAnnexToModify, prevResult) -> {
final BehaviorVariable newVariable = (BehaviorVariable) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorVariable());
final String newName = BehaviorAnnexNamingUtil.buildUniqueIdentifier(behaviorAnnexToModify, "new_behavior_variable");
newVariable.setName(newName);
newVariable.setDataClassifier(prevResult);
behaviorAnnexToModify.getVariables().add(newVariable);
return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newVariable).build();
});
});
});
}
use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.
the class BehaviorStateHandler method rename.
@Override
public void rename(final RenameContext ctx) {
final BehaviorState behaviorState = ctx.getBusinessObject(BehaviorState.class).orElseThrow();
final BehaviorAnnex behaviorAnnex = (BehaviorAnnex) behaviorState.getOwner();
final String originalName = behaviorState.getName();
final String newName = ctx.getNewName();
// Handle DeclarativeBehaviorTransitions
// Set the ID for source and destination states because they do not update if an invalid state name change occurs
behaviorAnnex.getTransitions().stream().filter(DeclarativeBehaviorTransition.class::isInstance).forEach(transition -> {
final DeclarativeBehaviorTransition dt = (DeclarativeBehaviorTransition) transition;
final EList<Identifier> srcStates = dt.getSrcStates();
if (!srcStates.isEmpty() && dt.getDestState() != null) {
// Set id for source and destination
setId(srcStates.get(0), originalName, newName);
setId(dt.getDestState(), originalName, newName);
}
});
behaviorState.setName(newName);
}
use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.
the class BehaviorTransitionHandler method delete.
@Override
public void delete(final CustomDeleteContext ctx) {
final BehaviorAnnex behaviorAnnex = ctx.getContainerBusinessObject(BehaviorAnnex.class).orElseThrow();
// Find transition by URI.
final BehaviorTransition behaviorTransition = (BehaviorTransition) behaviorAnnex.eResource().getResourceSet().getEObject(EcoreUtil.getURI(ctx.getReadonlyBoToDelete(BehaviorTransition.class).orElseThrow()), true);
EcoreUtil.remove(behaviorTransition);
if (behaviorAnnex.getTransitions().isEmpty()) {
behaviorAnnex.unsetTransitions();
}
}
use of org.osate.ba.aadlba.BehaviorAnnex in project osate2 by osate.
the class BehaviorTransitionHandler method getCanonicalReference.
@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
final BehaviorTransition behaviorTransition = ctx.getBusinessObject(BehaviorTransition.class).orElseThrow();
final BehaviorAnnex behaviorAnnex = (BehaviorAnnex) behaviorTransition.getOwner();
final int index = behaviorAnnex.getTransitions().indexOf(behaviorTransition);
return new CanonicalBusinessObjectReference(BehaviorAnnexReferenceUtil.TRANSITION_TYPE, Integer.toString(index), ctx.getReferenceBuilder().getCanonicalReference(behaviorAnnex).encode());
}
Aggregations