Search in sources :

Example 1 with LabelFilteringListSelectorModel

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);
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) NamedElementCollectionSingleSelectorModel(org.osate.ge.aadl2.ui.NamedElementCollectionSingleSelectorModel) URI(org.eclipse.emf.common.util.URI) StepResult(org.osate.ge.operations.StepResult) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) BranchValue(org.osate.xtext.aadl2.errormodel.errorModel.BranchValue) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) Operation(org.osate.ge.operations.Operation) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) EObject(org.eclipse.emf.ecore.EObject) Display(org.eclipse.swt.widgets.Display) ErrorModelNamingUtil(org.osate.ge.errormodel.util.ErrorModelNamingUtil) FilteringSelectorDialog(org.osate.ge.swt.selectors.FilteringSelectorDialog) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) LabelFilteringListSelectorModel(org.osate.ge.swt.selectors.LabelFilteringListSelectorModel) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) Optional(java.util.Optional) ErrorModelPackage(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelPackage) QualifiedErrorEventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorEventOrPropagation) EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) QualifiedErrorEventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorEventOrPropagation) TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) NamedElementCollectionSingleSelectorModel(org.osate.ge.aadl2.ui.NamedElementCollectionSingleSelectorModel) BranchValue(org.osate.xtext.aadl2.errormodel.errorModel.BranchValue) URI(org.eclipse.emf.common.util.URI) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) EObject(org.eclipse.emf.ecore.EObject) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk)

Example 2 with LabelFilteringListSelectorModel

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();
    });
}
Also used : LabelFilteringListSelectorModel(org.osate.ge.swt.selectors.LabelFilteringListSelectorModel) AadlPackage(org.osate.aadl2.AadlPackage) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) IProject(org.eclipse.core.resources.IProject) ErrorModelObjectDescriptionCollectionSingleSelectorModel(org.osate.ge.errormodel.ui.viewmodels.ErrorModelObjectDescriptionCollectionSingleSelectorModel)

Example 3 with LabelFilteringListSelectorModel

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();
    });
}
Also used : LabelFilteringListSelectorModel(org.osate.ge.swt.selectors.LabelFilteringListSelectorModel) AadlPackage(org.osate.aadl2.AadlPackage) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) IProject(org.eclipse.core.resources.IProject) ErrorModelObjectDescriptionCollectionSingleSelectorModel(org.osate.ge.errormodel.ui.viewmodels.ErrorModelObjectDescriptionCollectionSingleSelectorModel)

Example 4 with LabelFilteringListSelectorModel

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());
}
Also used : FormData(org.eclipse.swt.layout.FormData) LabelFilteringListSelectorModel(org.osate.ge.swt.selectors.LabelFilteringListSelectorModel) Composite(org.eclipse.swt.widgets.Composite) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

LabelFilteringListSelectorModel (org.osate.ge.swt.selectors.LabelFilteringListSelectorModel)4 IProject (org.eclipse.core.resources.IProject)2 AadlPackage (org.osate.aadl2.AadlPackage)2 ErrorModelObjectDescriptionCollectionSingleSelectorModel (org.osate.ge.errormodel.ui.viewmodels.ErrorModelObjectDescriptionCollectionSingleSelectorModel)2 Optional (java.util.Optional)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 Composite (org.eclipse.swt.widgets.Composite)1 Display (org.eclipse.swt.widgets.Display)1 BusinessObjectContext (org.osate.ge.BusinessObjectContext)1 AadlGraphicalEditorException (org.osate.ge.aadl2.AadlGraphicalEditorException)1 NamedElementCollectionSingleSelectorModel (org.osate.ge.aadl2.ui.NamedElementCollectionSingleSelectorModel)1 BehaviorTransitionTrunk (org.osate.ge.errormodel.model.BehaviorTransitionTrunk)1 ErrorModelNamingUtil (org.osate.ge.errormodel.util.ErrorModelNamingUtil)1 Operation (org.osate.ge.operations.Operation)1 StepResult (org.osate.ge.operations.StepResult)1 StepResultBuilder (org.osate.ge.operations.StepResultBuilder)1