Search in sources :

Example 11 with Feature

use of org.osate.aadl2.Feature in project osate2 by osate.

the class ChangeFeatureTypePropertySection method refresh.

@Override
public void refresh() {
    final Set<NamedElement> selectedFeatures = selectedBos.boStream(NamedElement.class).collect(Collectors.toSet());
    final Set<EClass> featureTypeOptions = new HashSet<>();
    // Add to options
    final Consumer<EClass> addFeatureTypeOption = (type) -> featureTypeOptions.add(type);
    // Get comboviewer selected value and populate available type options for comboviewer
    selectedFeatureType = AadlPropertySectionUtil.getTypeOptionsInformation(selectedFeatures, AadlFeatureUtil.getFeatureTypes(), (feature, type) -> isValidFeatureType(feature, type), addFeatureTypeOption);
    comboViewer.setInput(featureTypeOptions);
    // Set comboviewer selection
    if (selectedFeatureType != null) {
        comboViewer.setSelection(new StructuredSelection(selectedFeatureType));
    }
    comboViewer.getCombo().setEnabled(selectedFeatures.size() == 1);
}
Also used : InternalPropertySectionUtil(org.osate.ge.internal.ui.util.InternalPropertySectionUtil) Feature(org.osate.aadl2.Feature) InternalFeature(org.osate.aadl2.InternalFeature) ComboViewer(org.eclipse.jface.viewers.ComboViewer) AbstractFeature(org.osate.aadl2.AbstractFeature) IFilter(org.eclipse.jface.viewers.IFilter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HashSet(java.util.HashSet) BusinessObjectSelection(org.osate.ge.BusinessObjectSelection) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) EClass(org.eclipse.emf.ecore.EClass) Classifier(org.osate.aadl2.Classifier) AgeEmfUtil(org.osate.ge.internal.util.AgeEmfUtil) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) DirectionType(org.osate.aadl2.DirectionType) FeatureGroup(org.osate.aadl2.FeatureGroup) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProcessorFeature(org.osate.aadl2.ProcessorFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) AbstractPropertySection(org.eclipse.ui.views.properties.tabbed.AbstractPropertySection) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Set(java.util.Set) Collectors(java.util.stream.Collectors) AadlFeatureUtil(org.osate.ge.aadl2.internal.util.AadlFeatureUtil) TabbedPropertySheetPage(org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) Consumer(java.util.function.Consumer) Adapters(org.eclipse.core.runtime.Adapters) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) StringUtil(org.osate.ge.StringUtil) PropertySectionUtil(org.osate.ge.ui.PropertySectionUtil) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NamedElement(org.osate.aadl2.NamedElement) LabelProvider(org.eclipse.jface.viewers.LabelProvider) EClass(org.eclipse.emf.ecore.EClass) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NamedElement(org.osate.aadl2.NamedElement) HashSet(java.util.HashSet)

Example 12 with Feature

use of org.osate.aadl2.Feature in project osate2 by osate.

the class ConfigureInModesSection method refresh.

@Override
public void refresh() {
    if (composite != null) {
        composite.dispose();
    }
    final Set<ModalElement> mes = selectedBos.boStream(ModalElement.class).collect(Collectors.toSet());
    // Selected Modal Elements and if element is derived
    final Set<URI> urisOfElementsWhichRequireModes = new HashSet<>();
    // Local modes and button state map
    Map<ModeFeature, ButtonState> localModes = null;
    // Mode transitions and button state map. Only used when a ModalPath is selected
    Map<ModeFeature, ButtonState> localModeTransitions = null;
    // In modes map for each selected modal element, child can be null
    final Map<ModeFeature, ModeFeature> localToDerivedModeMap = new TreeMap<ModeFeature, ModeFeature>(modeFeatureComparator);
    // Required mode features
    Set<ModeFeature> derivedModes = null;
    boolean nonModePathSelected = false;
    // Determine button states for mode features
    for (final ModalElement modalElement : mes) {
        if (modalElement.getContainingClassifier() instanceof ComponentClassifier) {
            final ComponentClassifier cc = (ComponentClassifier) modalElement.getContainingClassifier();
            // Use name for compatibility with flow implementations
            final Set<String> inModes = getInModes(modalElement);
            // Initial set
            if (localModes == null) {
                localModes = new TreeMap<ModeFeature, ButtonState>(modeFeatureComparator);
                for (final ModeFeature mf : cc.getAllModes()) {
                    localModes.put(mf, inModes.contains(mf.getName()) ? ButtonState.SELECTED : ButtonState.NOT_SELECTED);
                }
            } else {
                populateLocalModes(localModes, cc, inModes);
            }
            if (modalElement instanceof Subcomponent) {
                final URI scUri = EcoreUtil.getURI(modalElement);
                nonModePathSelected = true;
                final Subcomponent sc = (Subcomponent) modalElement;
                final ComponentClassifier scClassifier = sc.getAllClassifier();
                if (scClassifier != null) {
                    final List<Mode> scClassifierAllModes = scClassifier.getAllModes();
                    for (final Mode mb : scClassifierAllModes) {
                        if (mb.isDerived()) {
                            // Mark the modal element as derived
                            urisOfElementsWhichRequireModes.add(scUri);
                            if (derivedModes == null) {
                                derivedModes = new HashSet<>();
                                derivedModes.addAll(scClassifierAllModes);
                            } else {
                                // Keep intersection of owned modes between selections
                                derivedModes.retainAll(scClassifierAllModes);
                            }
                            break;
                        }
                    }
                }
                for (final ModeBinding modeBinding : sc.getOwnedModeBindings()) {
                    final ModeFeature localMode = modeBinding.getParentMode();
                    final ModeFeature derivedMode = modeBinding.getDerivedMode();
                    if (urisOfElementsWhichRequireModes.contains(scUri)) {
                        if (localToDerivedModeMap.containsKey(localMode)) {
                            if (localToDerivedModeMap.get(localMode) != derivedMode) {
                                localToDerivedModeMap.put(localMode, null);
                                localModes.replace(localMode, ButtonState.PARTIAL);
                            }
                        } else {
                            // Add mode if not already added and override derived value if not null
                            localToDerivedModeMap.put(localMode, derivedMode);
                        }
                    }
                }
            } else if (modalElement instanceof ModalPath) {
                final ModalPath modalPath = (ModalPath) modalElement;
                // Use name for compatibility with flow implementations
                final Set<String> inModeTransitions = getInModeTransitions(modalPath);
                // Set Initial
                if (localModeTransitions == null) {
                    localModeTransitions = new TreeMap<ModeFeature, ButtonState>(modeFeatureComparator);
                    for (final ModeFeature mf : cc.getAllModeTransitions()) {
                        localModeTransitions.put(mf, inModeTransitions.contains(mf.getName()) ? ButtonState.SELECTED : ButtonState.NOT_SELECTED);
                    }
                } else {
                    populateModeTransitions(localModeTransitions, cc, inModeTransitions);
                }
            } else {
                nonModePathSelected = true;
            }
        }
    }
    // Mode transitions are always partial if a modal path and any other type of modal element is selected
    if (localModeTransitions != null && nonModePathSelected) {
        for (final ModeFeature mf : localModeTransitions.keySet()) {
            if (localModeTransitions.get(mf) == ButtonState.SELECTED) {
                localModeTransitions.replace(mf, ButtonState.PARTIAL);
            }
        }
    }
    final int horizontalSpan = derivedModes == null ? 1 : 3;
    composite = getWidgetFactory().createComposite(container);
    FormData fd;
    fd = new FormData();
    fd.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
    composite.setLayoutData(fd);
    final GridLayout layout = new GridLayout(horizontalSpan, false);
    composite.setLayout(layout);
    // Determine if there is at least one mode feature is enabled. If no mode features are enabled then the selected elements do not have any
    // applicable mode features in common.
    final boolean hasEnabledModes = Stream.concat(localModes == null ? Stream.empty() : localModes.values().stream(), localModeTransitions == null ? Stream.empty() : localModeTransitions.values().stream()).anyMatch(ButtonState::isEnabled);
    final boolean hasModeSelections = Stream.concat(localModes == null ? Stream.empty() : localModes.values().stream(), localModeTransitions == null ? Stream.empty() : localModeTransitions.values().stream()).anyMatch(ButtonState::isAtleastPartiallySelected);
    final String inModesStatusTxt;
    if (!hasEnabledModes) {
        inModesStatusTxt = "<No Common Applicable Modes>";
    } else if (anyRefinedElementHasInheritedModeFeatures(mes)) {
        inModesStatusTxt = "<See Refined Element(s)>";
    } else if (hasModeSelections) {
        inModesStatusTxt = "Selected Modes";
    } else {
        inModesStatusTxt = "All";
    }
    final Label inModesStatus = getWidgetFactory().createLabel(composite, inModesStatusTxt);
    GridDataFactory.fillDefaults().span(horizontalSpan, 1).applyTo(inModesStatus);
    // Only show mode features if at least one mode feature is enabled.
    if (hasEnabledModes) {
        if (localModes != null && !localModes.isEmpty()) {
            GridDataFactory.fillDefaults().grab(true, false).span(horizontalSpan, 1).applyTo(new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR));
            for (final Map.Entry<ModeFeature, ButtonState> entry : localModes.entrySet()) {
                addLocalMode(composite, entry, derivedModes, localToDerivedModeMap, urisOfElementsWhichRequireModes);
            }
        }
        if (localModeTransitions != null && !localModeTransitions.isEmpty()) {
            GridDataFactory.fillDefaults().grab(true, false).span(horizontalSpan, 1).applyTo(new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR));
            for (final Map.Entry<ModeFeature, ButtonState> entry : localModeTransitions.entrySet()) {
                addLocalMode(composite, entry, derivedModes, localToDerivedModeMap, urisOfElementsWhichRequireModes);
            }
        }
    }
    container.layout(true);
    container.pack();
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) HashSet(java.util.HashSet) Set(java.util.Set) Label(org.eclipse.swt.widgets.Label) URI(org.eclipse.emf.common.util.URI) GridLayout(org.eclipse.swt.layout.GridLayout) ModalPath(org.osate.aadl2.ModalPath) Subcomponent(org.osate.aadl2.Subcomponent) FormAttachment(org.eclipse.swt.layout.FormAttachment) HashSet(java.util.HashSet) FormData(org.eclipse.swt.layout.FormData) Mode(org.osate.aadl2.Mode) TreeMap(java.util.TreeMap) ModeBinding(org.osate.aadl2.ModeBinding) ModeFeature(org.osate.aadl2.ModeFeature) Map(java.util.Map) TreeMap(java.util.TreeMap) ModalElement(org.osate.aadl2.ModalElement)

Example 13 with Feature

use of org.osate.aadl2.Feature in project osate2 by osate.

the class CreateAadlConnectionPaletteCommand method canCreate.

private boolean canCreate(final BusinessObjectContext ownerBoc, final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
    // Get the connection elements for the source and destination
    final ConnectedElement srcConnectedElement = getConnectedElementForBusinessObjectContext(srcBoc, connectionType, false, ownerBoc);
    if (srcConnectedElement == null) {
        return false;
    }
    final ConnectedElement dstConnectedElement = getConnectedElementForBusinessObjectContext(dstBoc, connectionType, !(srcConnectedElement.getContext() instanceof Subcomponent), ownerBoc);
    // Ensure they are valid and are not the same
    if (dstConnectedElement == null || EcoreUtil.equals(srcConnectedElement, dstConnectedElement)) {
        return false;
    }
    // Don't allow connecting two features owned by the same classifier
    if (!(srcConnectedElement.getContext() instanceof Subcomponent || srcConnectedElement.getContext() instanceof SubprogramCall) && srcConnectedElement.getConnectionEnd() instanceof Feature && !(dstConnectedElement.getContext() instanceof Subcomponent || dstConnectedElement.getContext() instanceof SubprogramCall) && dstConnectedElement.getConnectionEnd() instanceof Feature) {
        return false;
    }
    final Class<?> connectionEndType = getConnectionEndType(connectionType);
    if (connectionEndType == null || !connectionEndType.isInstance(dstConnectedElement.getConnectionEnd())) {
        return false;
    }
    return ownerBoc == null ? false : getClassifierOpBuilder().canBuildOperation(ownerBoc.getBusinessObject());
}
Also used : SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ConnectedElement(org.osate.aadl2.ConnectedElement) SubprogramCall(org.osate.aadl2.SubprogramCall) Feature(org.osate.aadl2.Feature)

Example 14 with Feature

use of org.osate.aadl2.Feature in project osate2 by osate.

the class CreateFeaturePaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(EObject.class).map(targetBo -> {
        final AadlOperationBuilder<Classifier> opBuilder = AadlOperationBuilder.classifiers().filter(c -> AadlFeatureUtil.canOwnFeatureType(c, featureType));
        if (!opBuilder.canBuildOperation(targetBo)) {
            return null;
        }
        return Operation.createWithBuilder(createOp -> {
            // Create the feature
            opBuilder.buildOperation(createOp, targetBo).modifyPreviousResult(owner -> {
                final String newFeatureName = AadlNamingUtil.buildUniqueIdentifier(owner, "new_feature");
                final NamedElement newFeature = AadlFeatureUtil.createFeature(owner, featureType);
                newFeature.setName(newFeatureName);
                // Set in or out based on target docking position
                final boolean isRight = ctx.getDockingPosition() == DockingPosition.RIGHT;
                if (newFeature instanceof DirectedFeature) {
                    if (!(newFeature instanceof FeatureGroup)) {
                        final DirectedFeature newDirectedFeature = (DirectedFeature) newFeature;
                        newDirectedFeature.setIn(!isRight);
                        newDirectedFeature.setOut(isRight);
                    }
                } else if (newFeature instanceof Access) {
                    final Access access = (Access) newFeature;
                    access.setKind(isRight ? AccessType.PROVIDES : AccessType.REQUIRES);
                }
                if (owner instanceof ComponentType) {
                    ((ComponentType) owner).setNoFeatures(false);
                }
                return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newFeature).build();
            });
        });
    });
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) ComponentType(org.osate.aadl2.ComponentType) EObject(org.eclipse.emf.ecore.EObject) Access(org.osate.aadl2.Access) DirectedFeature(org.osate.aadl2.DirectedFeature) Classifier(org.osate.aadl2.Classifier) NamedElement(org.osate.aadl2.NamedElement)

Example 15 with Feature

use of org.osate.aadl2.Feature in project osate2 by osate.

the class CreateFlowSourceSinkSpecificationPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(Feature.class).map(feature -> {
        final DirectionType requiredDirection;
        if (flowKind == FlowKind.SOURCE) {
            requiredDirection = DirectionType.OUT;
        } else if (flowKind == FlowKind.SINK) {
            requiredDirection = DirectionType.IN;
        } else {
            return null;
        }
        final List<ComponentType> potentialOwners = FlowSpecificationCreationUtil.getPotentialOwnersByFeature(ctx.getTarget(), ctx.getQueryService());
        if (potentialOwners.isEmpty() || !FlowSpecificationCreationUtil.isValidFlowEnd(feature, ctx.getTarget(), requiredDirection, ctx.getQueryService())) {
            return null;
        }
        final BusinessObjectContext container = FlowSpecificationCreationUtil.getFlowSpecificationOwnerBoc(ctx.getTarget(), ctx.getQueryService());
        if (container == null) {
            return null;
        }
        return Operation.createWithBuilder(createOp -> {
            AadlUiUtil.selectClassifier(createOp, potentialOwners).modifyPreviousResult(ct -> {
                final FlowSpecification fs = ct.createOwnedFlowSpecification();
                fs.setKind(flowKind);
                fs.setName(FlowSpecificationCreationUtil.getNewFlowSpecificationName(ct));
                // Create the appropriate flow end depending on the type being created
                final FlowEnd flowEnd;
                if (flowKind == FlowKind.SOURCE) {
                    flowEnd = fs.createOutEnd();
                } else if (flowKind == FlowKind.SINK) {
                    flowEnd = fs.createInEnd();
                } else {
                    throw new RuntimeException("Unexpected flow kind: " + flowKind);
                }
                flowEnd.setFeature(feature);
                flowEnd.setContext(FlowSpecificationCreationUtil.getContext(ctx.getTarget(), ctx.getQueryService()));
                // Clear the no flows flag
                ct.setNoFlows(false);
                return StepResultBuilder.create().showNewBusinessObject(container, fs).build();
            });
        });
    });
}
Also used : DirectionType(org.osate.aadl2.DirectionType) ComponentType(org.osate.aadl2.ComponentType) FlowSpecification(org.osate.aadl2.FlowSpecification) Feature(org.osate.aadl2.Feature) BusinessObjectContext(org.osate.ge.BusinessObjectContext) FlowEnd(org.osate.aadl2.FlowEnd)

Aggregations

ArrayList (java.util.ArrayList)100 Feature (org.osate.aadl2.Feature)86 Feature (com.google.cloud.vision.v1.Feature)74 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)71 Image (com.google.cloud.vision.v1.Image)71 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)68 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)68 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)65 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)59 ByteString (com.google.protobuf.ByteString)48 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)47 Classifier (org.osate.aadl2.Classifier)45 NamedElement (org.osate.aadl2.NamedElement)42 ImageSource (com.google.cloud.vision.v1.ImageSource)39 Subcomponent (org.osate.aadl2.Subcomponent)39 FeatureGroup (org.osate.aadl2.FeatureGroup)33 FeatureGroupType (org.osate.aadl2.FeatureGroupType)33 FileInputStream (java.io.FileInputStream)30 ComponentClassifier (org.osate.aadl2.ComponentClassifier)30 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)28