use of org.osate.ge.swt.selectors.LabelFilteringListSelectorModel in project osate2 by osate.
the class CreateTransitionPaletteCommand method buildCreateOperation.
private Operation buildCreateOperation(final BusinessObjectContext srcBoc, final ErrorBehaviorState targetStateReadonly) {
final Object srcBo = srcBoc.getBusinessObject();
final URI targetStateUri = EcoreUtil.getURI(targetStateReadonly);
if (srcBo instanceof ErrorBehaviorState) {
final ErrorBehaviorState srcStateReadonly = (ErrorBehaviorState) srcBo;
final URI srcStateUri = EcoreUtil.getURI(srcStateReadonly);
return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(getStateMachine(srcStateReadonly))).modifyPreviousResult(stateMachine -> {
final ErrorBehaviorState targetState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(targetStateUri, true);
final ErrorBehaviorState srcState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(srcStateUri, true);
final NamedElementCollectionSingleSelectorModel<ErrorBehaviorEvent> model = new NamedElementCollectionSingleSelectorModel<>(stateMachine.getEvents());
if (!FilteringSelectorDialog.open(Display.getCurrent().getActiveShell(), "Select Event", new LabelFilteringListSelectorModel<>(model))) {
return null;
}
final ErrorBehaviorEvent event = model.getSelectedElement();
// Create the transition
final ErrorBehaviorTransition newTransition = ErrorModelFactory.eINSTANCE.createErrorBehaviorTransition();
newTransition.setSource(srcState);
// Set the target
if (srcState == targetState) {
newTransition.setSteadyState(true);
} else {
newTransition.setTarget(targetState);
}
newTransition.setName(ErrorModelNamingUtil.buildUniqueIdentifier(stateMachine, "new_transition"));
final ConditionElement conditionElement = ErrorModelFactory.eINSTANCE.createConditionElement();
newTransition.setCondition(conditionElement);
final EMV2PathElement conditionPathElement = ErrorModelFactory.eINSTANCE.createEMV2PathElement();
conditionPathElement.setNamedElement(event);
final QualifiedErrorEventOrPropagation errorEventOrPropogation = ErrorModelFactory.eINSTANCE.createQualifiedErrorEventOrPropagation();
errorEventOrPropogation.setEmv2Target(conditionPathElement);
conditionElement.setQualifiedErrorPropagationReference(errorEventOrPropogation);
stateMachine.getTransitions().add(newTransition);
return StepResultBuilder.create().showNewBusinessObject(srcBoc.getParent(), newTransition).build();
}));
} else if (srcBo instanceof ErrorBehaviorTransition || srcBo instanceof BehaviorTransitionTrunk || srcBo instanceof TransitionBranch) {
// Get the transition to modify
final ErrorBehaviorTransition transitionReadonly;
if (srcBo instanceof ErrorBehaviorTransition) {
transitionReadonly = (ErrorBehaviorTransition) srcBo;
} else if (srcBo instanceof BehaviorTransitionTrunk) {
transitionReadonly = ((BehaviorTransitionTrunk) srcBo).getTransition();
} else if (srcBo instanceof TransitionBranch) {
transitionReadonly = (ErrorBehaviorTransition) ((TransitionBranch) srcBo).eContainer();
} else {
throw new AadlGraphicalEditorException("Unexpected case: " + srcBo);
}
return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(transitionReadonly)).modifyPreviousResult(transition -> {
final ErrorBehaviorState targetState = (ErrorBehaviorState) transition.eResource().getResourceSet().getEObject(targetStateUri, true);
// Convert from using steady state and target field to using branches.
if (transition.getDestinationBranches().isEmpty()) {
final TransitionBranch firstBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
final BranchValue firstBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
firstBranchValue.setRealvalue("1.0");
if (transition.isSteadyState()) {
firstBranch.setSteadyState(true);
} else {
firstBranch.setTarget(transition.getTarget());
}
firstBranch.setValue(firstBranchValue);
transition.getDestinationBranches().add(firstBranch);
transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_Target());
transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_TargetToken());
transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_SteadyState());
}
// Create the new branch
final TransitionBranch newBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
final BranchValue newBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
newBranchValue.setRealvalue("1.0");
// Set the target
if (transition.getSource() == targetState) {
newBranch.setSteadyState(true);
} else {
newBranch.setTarget(targetState);
}
newBranch.setValue(newBranchValue);
transition.getDestinationBranches().add(newBranch);
return StepResultBuilder.create().build();
}));
} else {
throw new AadlGraphicalEditorException("Unsupported case: " + srcBo);
}
}
use of org.osate.ge.swt.selectors.LabelFilteringListSelectorModel in project osate2 by osate.
the class CreateTypeAliasPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ErrorModelGeUtil.createErrorModelLibraryPromptAndModifyOperation(ctx.getTarget(), () -> {
// Prompt user to select an ErrorType
final AadlPackage pkg = ctx.getTarget().getBusinessObject(AadlPackage.class).get();
final IProject project = ProjectUtil.getProjectForBoOrThrow(pkg);
final ErrorModelObjectDescriptionCollectionSingleSelectorModel model = new ErrorModelObjectDescriptionCollectionSingleSelectorModel(AadlModelAccessUtil.getAllEObjectsByType(project, ErrorModelPackage.eINSTANCE.getErrorType()));
if (!FilteringSelectorDialog.open(Display.getCurrent().getActiveShell(), "Select Error Type to Alias", new LabelFilteringListSelectorModel<>(model))) {
return Optional.empty();
}
final ErrorType errorType = (ErrorType) model.getSelectedElement().getEObjectOrProxy();
return Optional.of(errorType);
}, (lib, aliasedType) -> {
// Type aliases are just error types with an alias set. Create a new type and set the aliased type
final ErrorType newErrorTypeAlias = ErrorModelFactory.eINSTANCE.createErrorType();
final String newErrorTypeName = ErrorModelNamingUtil.buildUniqueIdentifier(lib, "new_error_type_alias");
newErrorTypeAlias.setName(newErrorTypeName);
newErrorTypeAlias.setAliasedType(aliasedType);
// Add the new type to the error model library
lib.getTypes().add(newErrorTypeAlias);
return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newErrorTypeAlias).build();
});
}
use of org.osate.ge.swt.selectors.LabelFilteringListSelectorModel in project osate2 by osate.
the class CreateTypeSetAliasPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ErrorModelGeUtil.createErrorModelLibraryPromptAndModifyOperation(ctx.getTarget(), () -> {
// Prompt user to select an TypeSet
final AadlPackage pkg = ctx.getTarget().getBusinessObject(AadlPackage.class).get();
final IProject project = ProjectUtil.getProjectForBoOrThrow(pkg);
final ErrorModelObjectDescriptionCollectionSingleSelectorModel model = new ErrorModelObjectDescriptionCollectionSingleSelectorModel(AadlModelAccessUtil.getAllEObjectsByType(project, ErrorModelPackage.eINSTANCE.getTypeSet()));
if (!FilteringSelectorDialog.open(Display.getCurrent().getActiveShell(), "Select Type Set to Alias", new LabelFilteringListSelectorModel<>(model))) {
return Optional.empty();
}
final TypeSet typeSet = (TypeSet) model.getSelectedElement().getEObjectOrProxy();
return Optional.of(typeSet);
}, (lib, typeSetToAlias) -> {
final TypeSet newTypeSet = ErrorModelFactory.eINSTANCE.createTypeSet();
final String newTypeSetName = ErrorModelNamingUtil.buildUniqueIdentifier(lib, "new_error_type_set_alias");
newTypeSet.setName(newTypeSetName);
newTypeSet.setAliasedType(typeSetToAlias);
lib.getTypesets().add(newTypeSet);
return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newTypeSet).build();
});
}
use of org.osate.ge.swt.selectors.LabelFilteringListSelectorModel in project osate2 by osate.
the class AbstractFeaturePrototypePropertySection method createControls.
@Override
public void createControls(final Composite parent, final TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
FormData fd;
final Composite container = getWidgetFactory().createFlatFormComposite(parent);
PropertySectionUtil.createSectionLabel(container, getWidgetFactory(), "Prototype:");
currentPrototype = new FilteringListSelectorField<>(container, "Select Feature Prototype", new LabelFilteringListSelectorModel<>(model));
currentPrototype.setModifyButtonTestingId(WIDGET_ID_CHOOSE_BUTTON);
fd = new FormData();
fd.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
fd.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE);
currentPrototype.setLayoutData(fd);
InternalPropertySectionUtil.setPropertiesHelp(aTabbedPropertySheetPage.getControl());
}
Aggregations