Search in sources :

Example 16 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class DefaultSelectSubprogramDialogModel method getSubprograms.

@Override
public List<Object> getSubprograms(final Object context) {
    // Build a list of subprograms
    final List<Object> subprograms = new ArrayList<Object>();
    // Data/Subprogram Group/Abstract Type
    if (context instanceof IEObjectDescription) {
        final IEObjectDescription desc = (IEObjectDescription) context;
        final Classifier contextClassifier = (Classifier) (desc.getEObjectOrProxy().eIsProxy() ? (Classifier) EcoreUtil.resolve(desc.getEObjectOrProxy(), bi.eResource()) : desc.getEObjectOrProxy());
        if (!contextClassifier.eIsProxy()) {
            for (final Feature tmpFeature : contextClassifier.getAllFeatures()) {
                if (tmpFeature instanceof SubprogramAccess) {
                    // Provides Subprogram Access
                    if (((SubprogramAccess) tmpFeature).getKind() == AccessType.PROVIDES) {
                        subprograms.add(tmpFeature);
                    }
                }
            }
        }
    } else if (context instanceof SubprogramGroupAccess) {
        // Requires Subprogram Group Access
        // Only subprogram group accesses with kind = Requires and which has a subprogram group classifier should be in the context list
        // Provides Subprogram Access
        final SubprogramGroupClassifier spgClassifier = (SubprogramGroupClassifier) ((SubprogramGroupAccess) context).getAllClassifier();
        addProvidesSubprogramAccessesForComponentClassifier(spgClassifier, subprograms);
    } else if (context instanceof FeatureGroup) {
        // Feature Group
        final FeatureGroup fg = (FeatureGroup) context;
        // Requires subprogram Access if not inverse and Provides subprogram access if is inverse
        final boolean inverted = fg.isInverse();
        for (final Feature tmpFeature : AadlFeatureUtil.getAllFeatures(fg.getAllFeatureGroupType())) {
            if (tmpFeature instanceof SubprogramAccess) {
                final AccessType accessKind = ((SubprogramAccess) tmpFeature).getKind();
                if ((!inverted && accessKind == AccessType.REQUIRES) || (inverted && accessKind == AccessType.PROVIDES)) {
                    subprograms.add(tmpFeature);
                }
            }
        }
    } else if (context instanceof SubprogramGroupSubcomponent) {
        // Subprogram Group Subcomponent
        // Provides Subprogram
        addProvidesSubprogramAccessesForComponentClassifier(((SubprogramGroupSubcomponent) context).getAllClassifier(), subprograms);
    } else if (context == processorContext) {
        // Subprogram Proxy
        for (final ProcessorFeature processorFeature : AgeAadlUtil.getAllProcessorFeatures(bi)) {
            if (processorFeature instanceof SubprogramProxy) {
                subprograms.add(processorFeature);
            }
        }
    } else if (context == nullContext) {
        // Null Context
        // Subprogram classifier reference
        final Aadl2Package aadl2Package = Aadl2Package.eINSTANCE;
        for (final IEObjectDescription desc : AadlModelAccessUtil.getAllEObjectsByType(bi.eResource(), aadl2Package.getComponentClassifier())) {
            // Add objects that have care either types or implementations of the same category as the classifier type
            final EClass classifierEClass = desc.getEClass();
            if (aadl2Package.getSubprogramClassifier().isSuperTypeOf(classifierEClass)) {
                subprograms.add(desc);
            }
        }
        // Requires Subprogram Access
        for (final Feature tmpFeature : bi.getAllFeatures()) {
            if (tmpFeature instanceof SubprogramAccess && ((SubprogramAccess) tmpFeature).getKind() == AccessType.REQUIRES) {
                subprograms.add(tmpFeature);
            }
        }
        // Subprogram Subcomponent
        for (final Subcomponent tmpSc : bi.getAllSubcomponents()) {
            if (tmpSc instanceof SubprogramSubcomponent) {
                subprograms.add(tmpSc);
            }
        }
        // Subprogram Prototype
        for (final Prototype prototype : bi.getAllPrototypes()) {
            if (prototype instanceof SubprogramPrototype) {
                subprograms.add(prototype);
            }
        }
    }
    return Collections.unmodifiableList(subprograms);
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) Prototype(org.osate.aadl2.Prototype) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) ArrayList(java.util.ArrayList) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) Feature(org.osate.aadl2.Feature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EClass(org.eclipse.emf.ecore.EClass) SubprogramProxy(org.osate.aadl2.SubprogramProxy) SubprogramAccess(org.osate.aadl2.SubprogramAccess) Aadl2Package(org.osate.aadl2.Aadl2Package) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) AccessType(org.osate.aadl2.AccessType)

Example 17 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class OpenAssociatedDiagramHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        throw new RuntimeException("Unexpected editor: " + activeEditor);
    }
    // Get diagram and selected BOCs
    final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
    if (selectedBusinessObjectContexts.size() == 0) {
        throw new RuntimeException("No element selected");
    }
    final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
    final Object bo = selectedBusinessObjectContext.getBusinessObject();
    final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
    if (bo instanceof AadlPackage || bo instanceof Classifier) {
        diagramService.openOrCreateDiagramForBusinessObject(bo);
    } else if (bo instanceof Subcomponent) {
        final ComponentClassifier cc = AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo);
        if (cc != null) {
            diagramService.openOrCreateDiagramForBusinessObject(cc);
        }
    }
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) IEditorPart(org.eclipse.ui.IEditorPart) DiagramService(org.osate.ge.internal.services.DiagramService) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 18 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class CreateGeneralizationPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
    final Object readonlySubtype = ctx.getSource().getBusinessObject();
    final Classifier supertype = ctx.getDestination().getBusinessObject(Classifier.class).orElse(null);
    // Ensure they are valid and are not the same
    if (readonlySubtype == null || supertype == null || readonlySubtype == supertype) {
        return Optional.empty();
    }
    // Rules:
    // Abstract types can be extended by any type.
    // Types can be extended by other types in their category
    // Implementations can extend other implementations with same category and abstract implementation in some cases.
    // Feature Group Types can extend other feature group types
    final boolean canCreate = (readonlySubtype instanceof ComponentType && (supertype instanceof AbstractType || supertype.getClass() == readonlySubtype.getClass())) || (readonlySubtype instanceof ComponentImplementation && (supertype instanceof AbstractImplementation || supertype.getClass() == readonlySubtype.getClass())) || (readonlySubtype instanceof FeatureGroupType && supertype instanceof FeatureGroupType);
    if (!canCreate) {
        return Optional.empty();
    }
    return Operation.createSimple(ctx.getSource(), Classifier.class, subtype -> {
        // Import the package if necessary
        if (subtype.getNamespace() instanceof PackageSection && subtype.getNamespace().getOwner() instanceof AadlPackage && supertype.getNamespace() instanceof PackageSection && supertype.getNamespace().getOwner() instanceof AadlPackage) {
            final PackageSection subtypeSection = (PackageSection) subtype.getNamespace();
            final AadlPackage supertypePackage = (AadlPackage) supertype.getNamespace().getOwner();
            AadlImportsUtil.addImportIfNeeded(subtypeSection, supertypePackage);
        }
        // Create the generalization
        final Object newBo;
        if (subtype instanceof ComponentType) {
            final ComponentType ct = (ComponentType) subtype;
            final TypeExtension te = ct.createOwnedExtension();
            te.setExtended((ComponentType) supertype);
            newBo = te;
        } else if (subtype instanceof ComponentImplementation) {
            final ComponentImplementation ci = (ComponentImplementation) subtype;
            final ImplementationExtension ie = ci.createOwnedExtension();
            ie.setExtended((ComponentImplementation) supertype);
            newBo = ie;
        } else if (subtype instanceof FeatureGroupType) {
            final FeatureGroupType fgt = (FeatureGroupType) subtype;
            final GroupExtension ge = fgt.createOwnedExtension();
            ge.setExtended((FeatureGroupType) supertype);
            newBo = ge;
        } else {
            return StepResult.abort();
        }
        return StepResultBuilder.create().showNewBusinessObject(ctx.getSource(), newBo).build();
    });
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) FeatureGroupType(org.osate.aadl2.FeatureGroupType) TypeExtension(org.osate.aadl2.TypeExtension) ImplementationExtension(org.osate.aadl2.ImplementationExtension) Classifier(org.osate.aadl2.Classifier) AbstractType(org.osate.aadl2.AbstractType) GroupExtension(org.osate.aadl2.GroupExtension) AbstractImplementation(org.osate.aadl2.AbstractImplementation)

Example 19 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class ClassifierOperationExecutor method resolveWithLiveResourceSetOrThrowIfProxy.

// Resolves the classifier using a new resource set. Using the ClassifierCreationHelper to resolve the base classifier does not
// work if the classifier was just created. Throws if the classifier is a proxy and cannot be resolved
private Classifier resolveWithLiveResourceSetOrThrowIfProxy(final Classifier c) {
    if (c == null || !c.eIsProxy()) {
        return c;
    }
    // Resolve the base classifier using a new resource set. Using the ClassifierCreationHelper to resolve the base classifier does not
    // work if the classifier was just created.
    final ResourceSet liveResourceSet = AadlModelAccessUtil.getLiveResourceSet(project);
    final Classifier resolvedClassifier = (Classifier) EcoreUtil.resolve(c, liveResourceSet);
    if (resolvedClassifier == null) {
        throw new RuntimeException("Unable to resolve classifier: " + c);
    }
    return resolvedClassifier;
}
Also used : ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Classifier(org.osate.aadl2.Classifier)

Example 20 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class ModeImpl method getPropertyValueInternal.

// Cannot make this final because I need to override in SystemOperationMode
public void getPropertyValueInternal(final Property prop, final PropertyAcc pas, final boolean fromInstanceSlaveCall, final boolean all) throws InvalidModelException {
    final Classifier owner = getContainingClassifier();
    final boolean inType = (owner instanceof ComponentType);
    // local contained value
    if (!inType && !fromInstanceSlaveCall) {
        // owner could be null if we are looking up a property on a SystemOperationMode, which does not have a containing classifier.
        if (owner != null && pas.addLocalContained(this, owner)) {
            if (!all) {
                return;
            }
        }
    }
    // local value
    if (pas.addLocal(this)) {
        if (!all) {
            return;
        }
    }
    // not an implementation
    if ((inType || !inType && !fromInstanceSlaveCall) && prop.isInherit()) {
        if (owner != null) {
            owner.getPropertyValueInternal(prop, pas, fromInstanceSlaveCall, all);
        } else {
            throw new InvalidModelException(this, "Mode is not contained in a component type or implementation");
        }
    }
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) ComponentType(org.osate.aadl2.ComponentType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier)

Aggregations

Classifier (org.osate.aadl2.Classifier)203 ComponentClassifier (org.osate.aadl2.ComponentClassifier)90 ComponentImplementation (org.osate.aadl2.ComponentImplementation)49 NamedElement (org.osate.aadl2.NamedElement)40 AadlPackage (org.osate.aadl2.AadlPackage)38 Subcomponent (org.osate.aadl2.Subcomponent)37 ComponentType (org.osate.aadl2.ComponentType)34 EObject (org.eclipse.emf.ecore.EObject)31 ArrayList (java.util.ArrayList)29 BasicEList (org.eclipse.emf.common.util.BasicEList)28 Feature (org.osate.aadl2.Feature)26 DataClassifier (org.osate.aadl2.DataClassifier)22 FeatureGroupType (org.osate.aadl2.FeatureGroupType)21 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)21 AnnexSubclause (org.osate.aadl2.AnnexSubclause)17 Element (org.osate.aadl2.Element)17 EList (org.eclipse.emf.common.util.EList)15 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)15 FeatureGroup (org.osate.aadl2.FeatureGroup)14 PropertyExpression (org.osate.aadl2.PropertyExpression)14