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