use of org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference in project osate2 by osate.
the class ModeContributionItem method refresh.
void refresh() {
final ComboViewer comboViewer = getComboViewer();
final SortedSet<ModeFeatureReference> modeFeatureReferences = new TreeSet<>((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
if (comboViewer != null) {
final ModeFeatureReference nullValue = AadlModalElementUtil.createModeFeatureReference(getNullValueString(), null, null);
modeFeatureReferences.add(nullValue);
Object selectedValue = nullValue;
final String selectedModeName = editor == null ? null : editor.getPartProperty(SELECTED_MODE_PROPERTY_KEY);
// Clear the combo box
comboViewer.setInput(null);
if (editor == null) {
return;
}
final AgeDiagram diagram = editor.getDiagram();
if (diagram != null) {
final QueryService queryService = ContributionUtil.getQueryService(editor);
if (queryService != null) {
queryService.getResults(MODE_CONTAINER_QUERY, diagram, null).stream().flatMap(modeContainer -> {
// If container contains a modal element
if (AadlModalElementUtil.getModalElement(modeContainer.getBusinessObjectContext()) != null) {
// Get qualified modes to add to the drop-down
return Stream.concat(getModeBindingFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()), getModeFeatureReferences((DiagramNode) modeContainer.getBusinessObjectContext()));
}
return Stream.empty();
}).forEach(modeFeatureRef -> {
modeFeatureReferences.add(modeFeatureRef);
});
// Find ComboViewer selection
final Optional<ModeFeatureReference> tmpSelectedValue = modeFeatureReferences.stream().filter(tmpKey -> tmpKey.getName().equalsIgnoreCase(selectedModeName)).findAny();
if (tmpSelectedValue.isPresent()) {
selectedValue = tmpSelectedValue.get();
}
comboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(final Object element) {
final ModeFeatureReference mf = (ModeFeatureReference) element;
return mf.getName();
}
});
comboViewer.setInput(modeFeatureReferences);
}
}
final StructuredSelection newSelection = new StructuredSelection(selectedValue);
if (!Objects.equal(newSelection, comboViewer.getSelection())) {
comboViewer.setSelection(newSelection);
onSelection(newSelection.getFirstElement());
}
}
}
use of org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference in project osate2 by osate.
the class ModeContributionItem method onSelection.
@Override
protected void onSelection(final Object value) {
if (editor != null && !editor.isDisposed() && value != null) {
final ModeFeatureReference mf = (ModeFeatureReference) value;
ContributionUtil.getColoringService(editor).setHighlightedMode(mf.getNamedElement(), mf.getContainer());
}
}
use of org.osate.ge.aadl2.internal.util.AadlModalElementUtil.ModeFeatureReference in project osate2 by osate.
the class ModeContributionItem method saveModeSelection.
private void saveModeSelection() {
// Save the current mode selection
final ComboViewer comboViewer = getComboViewer();
if (comboViewer != null && editor != null) {
final Object firstSelection = comboViewer.getStructuredSelection().getFirstElement();
final ModeFeatureReference mf = (ModeFeatureReference) firstSelection;
final String selectionStr = firstSelection != null ? (String) mf.getName() : null;
editor.setPartProperty(SELECTED_MODE_PROPERTY_KEY, selectionStr);
}
}
Aggregations