use of org.osate.ba.aadlba.BehaviorState in project osate2 by osate.
the class CreateTransitionPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
if (!ctx.getDestination().getBusinessObject(BehaviorState.class).isPresent()) {
return Optional.empty();
}
final BusinessObjectContext srcContainer = getOwnerBoc(ctx.getSource(), ctx.getQueryService());
if (srcContainer == null) {
return Optional.empty();
}
final BusinessObjectContext dstContainer = getOwnerBoc(ctx.getDestination(), ctx.getQueryService());
if (dstContainer != srcContainer) {
return Optional.empty();
}
final BehaviorState srcState = ctx.getSource().getBusinessObject(BehaviorState.class).orElseThrow();
final BehaviorState dstState = ctx.getDestination().getBusinessObject(BehaviorState.class).orElseThrow();
return srcContainer.getBusinessObject(BehaviorAnnex.class).map(ba -> Operation.createSimple(srcContainer, BehaviorAnnex.class, boToModify -> {
final BehaviorTransition baTransition = (BehaviorTransition) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorTransition());
final String srcName = srcState.getName();
final String dstName = dstState.getName();
if (srcName == null || dstName == null) {
return StepResultBuilder.create().abort().build();
}
// Set source and destination for transition
for (final BehaviorState behaviorState : boToModify.getStates()) {
final String name = behaviorState.getName();
if (srcName.equalsIgnoreCase(name)) {
// Source
baTransition.setSourceState(behaviorState);
}
if (dstName.equalsIgnoreCase(name)) {
// Destination
baTransition.setDestinationState(behaviorState);
}
}
// Add new transition
boToModify.getTransitions().add(baTransition);
final String name = getTransitionName(baTransition);
baTransition.setName(name);
// Show
return StepResultBuilder.create().showNewBusinessObject(srcContainer, baTransition).build();
})).orElse(Optional.empty());
}
use of org.osate.ba.aadlba.BehaviorState 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.BehaviorState in project osate2 by osate.
the class BehaviorStateItemProvider method getImage.
/**
* This returns BehaviorState.gif.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*/
@Override
public Object getImage(Object object) {
BehaviorState state = (BehaviorState) object;
byte code = 0;
String imgFile = null;
if (state.isInitial())
code = 1;
if (state.isComplete())
code += 10;
if (state.isFinal())
code += 100;
switch(code) {
case 0:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "e_state_16";
break;
}
case 1:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "i_state_16";
break;
}
case 10:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "c_state_16";
break;
}
case 11:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "ic_state_16";
break;
}
case 100:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "f_state_16";
break;
}
case 101:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "if_state_16";
break;
}
case 110:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "cf_state_16";
break;
}
case 111:
{
imgFile = BehaviorElementItemProvider.IMG_PATH + "icf_state_16";
break;
}
}
return overlayImage(object, getResourceLocator().getImage(imgFile));
}
use of org.osate.ba.aadlba.BehaviorState in project osate2 by osate.
the class BehaviorTransitionImpl method basicSetSourceState.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetSourceState(BehaviorState newSourceState, NotificationChain msgs) {
BehaviorState oldSourceState = sourceState;
sourceState = newSourceState;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AadlBaPackage.BEHAVIOR_TRANSITION__SOURCE_STATE, oldSourceState, newSourceState);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.osate.ba.aadlba.BehaviorState in project osate2 by osate.
the class AadlBaNameResolver method parentComponentIdentifiersUniquenessCheck.
/**
* Check behavior annex's sub component uniqueness within behavior annex's
* parent component scope. Conflicts are reported.
*/
private boolean parentComponentIdentifiersUniquenessCheck() {
boolean result = true;
EList<org.osate.aadl2.NamedElement> lcc = new BasicEList<org.osate.aadl2.NamedElement>(0);
// Merges parent component' subcomponents lists.
lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Data.class));
lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Mode.class));
lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Feature.class));
EList<BehaviorVariable> lvars = _ba.getVariables();
EList<BehaviorState> lstates = _ba.getStates();
EList<BehaviorTransition> ltrans = _ba.getTransitions();
// Check uniqueness within the parent component.
for (org.osate.aadl2.NamedElement ne : lcc) {
for (BehaviorVariable v : lvars) {
String bvName = v.getName();
String neName = ne.getName();
if (bvName.equalsIgnoreCase(neName)) {
reportDuplicateNameError(v, ne);
result = false;
}
}
for (BehaviorState s : lstates) {
String bsName = s.getName();
if (bsName.equalsIgnoreCase(ne.getName())) {
// Links the identifier with the mode.
if (ne instanceof Mode) {
if (s.isComplete() == false) {
_errManager.error(s, "Behavior state " + bsName + " must be declared complete in order to represent " + "mode " + ne.getName() + " located at line " + Aadl2Utils.getLocationReference(ne).getLine());
result = false;
} else {
s.setBindedMode((Mode) ne);
}
} else {
reportDuplicateNameError(s, ne);
result = false;
}
}
}
for (BehaviorTransition t : ltrans) {
String btName = t.getName();
if (btName != null && btName.equalsIgnoreCase(ne.getName())) {
reportDuplicateNameError(t, ne);
result = false;
}
}
}
return result;
}
Aggregations