use of org.osate.aadl2.Subcomponent in project osate2 by osate.
the class CreateAadlConnectionPaletteCommand method buildCreateOperation.
public Operation buildCreateOperation(final BusinessObjectContext ownerBoc, final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
return Operation.createWithBuilder(createOp -> {
// Create the subcomponent
getClassifierOpBuilder().buildOperation(createOp, ownerBoc.getBusinessObject()).modifyPreviousResult(owner -> {
// Create the appropriate type of connection object
final org.osate.aadl2.Connection newAadlConnection = AadlConnectionUtil.createConnection(owner, connectionType);
if (newAadlConnection == null) {
return null;
}
// Reset the no connections flag
owner.setNoConnections(false);
// Set the source and destination
final ConnectedElement src = getConnectedElementForBusinessObjectContext(srcBoc, connectionType, false, ownerBoc);
newAadlConnection.setSource(src);
final ConnectedElement dst = getConnectedElementForBusinessObjectContext(dstBoc, connectionType, !(src.getContext() instanceof Subcomponent), ownerBoc);
newAadlConnection.setDestination(dst);
// Determine the name for the new connection
final String newConnectionName = AadlNamingUtil.buildUniqueIdentifier(owner, "new_connection");
newAadlConnection.setName(newConnectionName);
// Set type of access connection
if (newAadlConnection instanceof AccessConnection) {
final AccessConnection ac = (AccessConnection) newAadlConnection;
if (src.getConnectionEnd() instanceof SubprogramAccess || dst.getConnectionEnd() instanceof SubprogramAccess) {
ac.setAccessCategory(AccessCategory.SUBPROGRAM);
} else if (src.getConnectionEnd() instanceof SubprogramGroupAccess || dst.getConnectionEnd() instanceof SubprogramGroupAccess) {
ac.setAccessCategory(AccessCategory.SUBPROGRAM_GROUP);
} else if (src.getConnectionEnd() instanceof BusAccess || dst.getConnectionEnd() instanceof BusAccess) {
ac.setAccessCategory(AccessCategory.BUS);
} else if (src.getConnectionEnd() instanceof DataAccess || dst.getConnectionEnd() instanceof DataAccess) {
ac.setAccessCategory(AccessCategory.DATA);
}
}
return StepResultBuilder.create().showNewBusinessObject(ownerBoc, newAadlConnection).build();
});
});
}
use of org.osate.aadl2.Subcomponent in project osate2 by osate.
the class CreateAadlConnectionPaletteCommand method getOwnerBoc.
private static BusinessObjectContext getOwnerBoc(final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
// Search for an appropriate owner. To be appropriate the owner BOC must be a component implementation or a subcomponent which is reachable from both
// the source and destination BOC.
int subcomponentsChecked1 = 0;
BusinessObjectContext temp1 = srcBoc.getParent();
while (temp1 != null) {
final Object bo1 = temp1.getBusinessObject();
if (bo1 instanceof Subcomponent || bo1 instanceof ComponentImplementation) {
BusinessObjectContext temp2 = dstBoc.getParent();
int subcomponentsChecked2 = 0;
while (temp2 != null) {
final Object bo2 = temp2.getBusinessObject();
if (bo2 instanceof Subcomponent || bo2 instanceof ComponentImplementation) {
if (temp1 == temp2) {
return temp1;
}
if (bo2 instanceof Subcomponent) {
subcomponentsChecked2++;
// Stop checking at second subcomponent
if (subcomponentsChecked2 >= 2) {
break;
}
} else if (bo2 instanceof ComponentImplementation) {
// Stop checking at component implementations
break;
}
}
temp2 = temp2.getParent();
}
if (temp1.getBusinessObject() instanceof Subcomponent) {
subcomponentsChecked1++;
// Stop checking at second subcomponent
if (subcomponentsChecked1 >= 2) {
break;
}
} else if (bo1 instanceof ComponentImplementation) {
// Stop checking at component implementations
break;
}
}
temp1 = temp1.getParent();
}
return null;
}
use of org.osate.aadl2.Subcomponent in project osate2 by osate.
the class OpenAssociatedDiagramHandler method setEnabled.
@Override
public void setEnabled(final Object evaluationContext) {
boolean enabled = false;
final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
if (selectedBusinessObjectContexts.size() == 1) {
final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
final Object bo = selectedBusinessObjectContext.getBusinessObject();
enabled = (bo instanceof AadlPackage || bo instanceof Classifier || (bo instanceof Subcomponent && AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo) != null)) && ProjectUtil.getProjectForBo(bo).isPresent();
}
setBaseEnabled(enabled);
}
use of org.osate.aadl2.Subcomponent 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.osate.aadl2.Subcomponent 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;
}
Aggregations