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);
}
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;
}
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();
});
}
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;
}
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");
}
}
}
Aggregations