use of org.osate.aadl2.ModeFeature in project osate2 by osate.
the class ConfigureInModesSection method addLocalMode.
private void addLocalMode(final Composite container, final Map.Entry<ModeFeature, ButtonState> entry, final Set<ModeFeature> derivedModesAvailable, final Map<ModeFeature, ModeFeature> localToDerivedModeMap, final Set<URI> urisOfElementsWhichRequireModes) {
final ModeFeature mf = entry.getKey();
final Button modeBtn = getWidgetFactory().createButton(container, mf.getName(), SWT.CHECK);
// Create derived mode drop down
final ComboViewer derivedModeFld;
final Label mappedLabel;
if (derivedModesAvailable == null) {
derivedModeFld = null;
mappedLabel = null;
} else {
mappedLabel = getWidgetFactory().createLabel(container, "->", SWT.CENTER);
mappedLabel.setText("->");
// Create mapped derived mode combo
derivedModeFld = new ComboViewer(container, SWT.DROP_DOWN | SWT.READ_ONLY);
derivedModeFld.setContentProvider(ArrayContentProvider.getInstance());
derivedModeFld.setLabelProvider(new LabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof ModeFeature) {
final ModeFeature modalFeature = (ModeFeature) element;
return modalFeature.getName();
}
return element.toString();
}
});
derivedModeFld.add(" ");
derivedModeFld.add(derivedModesAvailable.toArray());
final ModeFeature mappedDerivedMode = localToDerivedModeMap.get(mf);
// If child mode is contained in intersection of derived modes
if (derivedModesAvailable.contains(mappedDerivedMode)) {
derivedModeFld.setSelection(new StructuredSelection(mappedDerivedMode));
}
}
// Set button state
final ButtonState modeFeatureState = entry.getValue();
if (modeFeatureState == ButtonState.SELECTED) {
modeBtn.setSelection(true);
} else if (modeFeatureState == ButtonState.PARTIAL) {
modeBtn.setSelection(true);
modeBtn.setGrayed(true);
} else if (modeFeatureState == ButtonState.DISABLED_AND_PARTIAL || modeFeatureState == ButtonState.DISABLED) {
modeBtn.setEnabled(false);
boolean partialDisabled = modeFeatureState == ButtonState.DISABLED_AND_PARTIAL;
modeBtn.setGrayed(partialDisabled);
modeBtn.setSelection(partialDisabled);
if (derivedModeFld != null) {
derivedModeFld.getCombo().setEnabled(false);
mappedLabel.setEnabled(false);
}
}
final SelectionListener selectionListener = new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
// No changes if combo selection changes without enabled button
if (e.widget instanceof Combo && !modeBtn.getSelection()) {
return;
}
// Modify selected modal elements
final boolean modeBtnIsSelected = modeBtn.getSelection();
selectedBos.modify("Set In Modes", boc -> boc.getBusinessObject(NamedElement.class).isPresent(), boc -> {
final NamedElement ne = boc.getBusinessObject(NamedElement.class).get();
if (ne instanceof AnnexSubclause && ne.eContainer() instanceof DefaultAnnexSubclause) {
return (NamedElement) ne.eContainer();
}
return ne;
}, (ne, boc) -> {
final ModeFeature modeFeature = (ModeFeature) EcoreUtil.resolve(mf, ne.eResource());
if (ne instanceof Subcomponent && modeFeature instanceof Mode) {
final Subcomponent sc = (Subcomponent) ne;
// Remove mode binding always
for (final ModeBinding mb : sc.getOwnedModeBindings()) {
if (modeFeature.getName().equalsIgnoreCase(mb.getParentMode().getName())) {
sc.getOwnedModeBindings().remove(mb);
break;
}
}
// Add mode binding on button selection
if (modeBtnIsSelected) {
final ModeBinding newModeBinding = sc.createOwnedModeBinding();
newModeBinding.setParentMode((Mode) modeFeature);
final boolean isDerived = urisOfElementsWhichRequireModes.contains(EcoreUtil.getURI(ne));
// If modal element is derived, set derived mode
if (isDerived) {
final Object selection = ((StructuredSelection) derivedModeFld.getSelection()).getFirstElement();
final ModeFeature childMode = selection instanceof ModeFeature ? (ModeFeature) selection : null;
newModeBinding.setDerivedMode((Mode) childMode);
}
}
} else if (ne instanceof ModalPath) {
final ModalPath mp = (ModalPath) ne;
if (modeBtnIsSelected) {
mp.getInModeOrTransitions().add(modeFeature);
} else {
for (final ModeFeature mf : mp.getInModeOrTransitions()) {
if (modeFeature.getName().equalsIgnoreCase(mf.getName())) {
mp.getInModeOrTransitions().remove(mf);
break;
}
}
}
} else if (ne instanceof ModalElement && modeFeature instanceof Mode) {
final ModalElement modalElement = (ModalElement) ne;
if (modeBtnIsSelected) {
modalElement.getAllInModes().add((Mode) modeFeature);
} else {
for (final ModeFeature mf : modalElement.getInModes()) {
if (modeFeature.getName().equalsIgnoreCase(mf.getName())) {
modalElement.getAllInModes().remove(modeFeature);
break;
}
}
}
}
});
}
};
// Register selection listeners
modeBtn.addSelectionListener(selectionListener);
if (derivedModeFld != null) {
derivedModeFld.getCombo().addSelectionListener(selectionListener);
}
}
use of org.osate.aadl2.ModeFeature 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.ModeFeature in project osate2 by osate.
the class ShowElementsInModeHandler method enableChildren.
private void enableChildren(final BusinessObjectProviderHelper bopHelper, final Object selectedMode, final BusinessObjectNode node) {
for (final Object childBo : bopHelper.getChildBusinessObjects(node)) {
final RelativeBusinessObjectReference ref = getRelativeBusinessObjectReference(childBo);
final BusinessObjectNode childNode = node.getChild(ref);
if (childNode == null) {
if (childBo instanceof ModalElement) {
final ModalElement modalElement = (ModalElement) childBo;
final List<ModeFeature> inModeFeatures = AadlModalElementUtil.getAllInModesOrTransitions(modalElement);
if (inModeFeatures.isEmpty() || inModeFeatures.contains(selectedMode)) {
enableChild(bopHelper, selectedMode, childBo, node);
}
} else {
enableChild(bopHelper, selectedMode, childBo, node);
}
enableChildren(bopHelper, selectedMode, node.getChild(ref));
}
}
}
use of org.osate.aadl2.ModeFeature in project osate2 by osate.
the class SetInModeFeaturesDialog method createDialogArea.
@Override
protected Control createDialogArea(final Composite parent) {
final Composite area = (Composite) super.createDialogArea(parent);
ScrolledComposite scrolled = new ScrolledComposite(area, SWT.H_SCROLL | SWT.V_SCROLL);
scrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrolled.setLayout(new GridLayout());
scrolled.setExpandVertical(true);
scrolled.setExpandHorizontal(true);
final Composite container = new Composite(scrolled, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final GridLayout layout = new GridLayout();
container.setLayout(layout);
// All modes checkbox
final Button allModesBtn = new Button(container, SWT.CHECK);
allModesBtn.setText("All Modes");
final GridData allModesGridData = new GridData();
allModesGridData.horizontalSpan = layout.numColumns;
allModesBtn.setLayoutData(allModesGridData);
allModesBtn.setSelection(inAllModes);
final Label modeSeparator = new Label(container, SWT.HORIZONTAL | SWT.SEPARATOR);
final GridData modeSeparatorLayoutData = new GridData(GridData.FILL_HORIZONTAL);
modeSeparatorLayoutData.horizontalSpan = layout.numColumns;
modeSeparator.setLayoutData(modeSeparatorLayoutData);
// Add controls for each of the local modes
for (final ModeFeature mf : localModes) {
addLocalMode(container, mf);
}
scrolled.setContent(container);
scrolled.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));
// If mode transitions are available
if (!localModeTransitions.isEmpty()) {
final GridData modeTransitionSeparatorLayoutData = new GridData(GridData.FILL_HORIZONTAL);
final Label modeTransitionSeparator = new Label(container, SWT.HORIZONTAL | SWT.SEPARATOR);
modeTransitionSeparatorLayoutData.horizontalSpan = layout.numColumns;
modeTransitionSeparator.setLayoutData(modeTransitionSeparatorLayoutData);
for (final ModeFeature mf : localModeTransitions) {
addLocalMode(container, mf);
}
}
// Update all check boxes when all modes is selected
updateEnabledStateOfModeControls(!allModesBtn.getSelection());
allModesBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
updateEnabledStateOfModeControls(!allModesBtn.getSelection());
inAllModes = allModesBtn.getSelection();
}
});
return area;
}
use of org.osate.aadl2.ModeFeature in project osate2 by osate.
the class CreateEndToEndFlowSpecificationTool method update.
/**
* Update the diagram and tool dialog
* @param selectedBocs - the selected bocs
*/
private void update(final List<BusinessObjectContext> selectedBocs) {
if (createFlowDialog != null) {
if (createFlowDialog.getShell() != null && !createFlowDialog.getShell().isDisposed() && createFlowDialog.elementSelectionDlg == null) {
// If the selection is qualified, add it
if (selectedBocs.size() > 1) {
createFlowDialog.setErrorMessage("Multiple elements selected. Select a single element. " + " " + getDialogMessage());
} else if (selectedBocs.size() == 1) {
// Get the selected boc
final BusinessObjectContext selectedBoc = (BusinessObjectContext) selectedBocs.get(0);
if (!modeFeatureSelections.contains(selectedBoc) && createFlowDialog.addSelectedElement(selectedBoc)) {
// Insert flow segments before first mode feature
final Color color;
if (selectedBoc.getBusinessObject() instanceof ModeFeature) {
modeFeatureSelections.add(selectedBoc);
color = Color.MAGENTA.brighter();
} else {
segmentSelections.add(new SegmentData(selectedBoc, new ArrayList<>()));
if (segmentSelections.size() == 1) {
// Set default name on first selection if one does not exist
createFlowDialog.getOwnerComponentImplementation().ifPresent(ci -> {
createFlowDialog.setTitle("Creating End To End Flow in: " + ci.getQualifiedName());
if (createFlowDialog.endToEndFlowName.isEmpty()) {
createFlowDialog.setEndToEndFlowName(ci);
}
});
color = Color.ORANGE.darker();
} else {
color = Color.MAGENTA.darker();
}
}
setColor(selectedBoc, color);
}
createFlowDialog.updateSegments();
final boolean isValid = createFlowDialog.isEndToEndFlowValid(createEndToEndFlow());
createFlowDialog.updateWidgets(isValid);
createFlowDialog.setErrorMessage(null);
createFlowDialog.setMessage(getDialogMessage());
} else {
createFlowDialog.updateSegments();
}
} else if (createFlowDialog.elementSelectionDlg != null && createFlowDialog.elementSelectionDlg.getShell() != null && !createFlowDialog.elementSelectionDlg.getShell().isDisposed() && createFlowDialog.elementSelectionDlg.getShell().isVisible()) {
final CreateFlowsToolsDialog.ElementSelectionDialog elementSelectionDlg = createFlowDialog.elementSelectionDlg;
// Selecting an element for editing end to end flows
if (selectedBocs.size() > 1) {
elementSelectionDlg.setErrorMessage("Multiple elements are selected.\n " + elementSelectionDlg.getMessage());
elementSelectionDlg.setSelection(null);
} else if (selectedBocs.size() == 1) {
elementSelectionDlg.setErrorMessage(null);
final BusinessObjectContext selectedBoc = selectedBocs.get(0);
elementSelectionDlg.setSelection(selectedBoc);
}
}
}
}
Aggregations