use of org.osate.ge.services.QueryService in project osate2 by osate.
the class FlowContributionItem method refresh.
void refresh() {
final ComboViewer comboViewer = getComboViewer();
final Map<String, HighlightableFlowInfo> highlightableFlowElements = new TreeMap<>((o1, o2) -> o1.toLowerCase().compareTo(o2.toLowerCase()));
if (comboViewer != null) {
final Map.Entry<String, HighlightableFlowInfo> nullMapEntry = new AbstractMap.SimpleEntry<>(getNullValueString(), new HighlightableFlowInfo(null, FlowSegmentState.COMPLETE));
highlightableFlowElements.put(nullMapEntry.getKey(), nullMapEntry.getValue());
Map.Entry<String, HighlightableFlowInfo> selectedValue = nullMapEntry;
final String selectedFlowName = editor == null ? null : editor.getPartProperty(SELECTED_FLOW_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) {
// Determine which flows have elements contained in the diagram and whether the flow is partial.
queryService.getResults(FLOW_CONTAINER_QUERY, diagram, null).stream().flatMap(flowContainerQueryable -> {
if (flowContainerQueryable.getBusinessObject() instanceof ComponentInstance) {
return AadlInstanceObjectUtil.getComponentInstance(flowContainerQueryable.getBusinessObjectContext()).map(ci -> createFlowSegmentReferences(flowContainerQueryable.getBusinessObjectContext(), ci)).orElse(Stream.empty());
} else {
return AadlClassifierUtil.getComponentImplementation(flowContainerQueryable.getBusinessObjectContext()).map(ci -> createFlowSegmentReferences(flowContainerQueryable.getBusinessObjectContext(), ci)).orElse(Stream.empty());
}
}).map(HighlightableFlowInfo::create).filter(Predicates.notNull()).forEachOrdered(highlightableFlowElement -> {
highlightableFlowElements.put(getName(highlightableFlowElement.highlightableFlowElement), highlightableFlowElement);
});
// Determine which value should be selected
final Optional<Entry<String, HighlightableFlowInfo>> tmpSelectedValue = highlightableFlowElements.entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(selectedFlowName)).findAny();
if (tmpSelectedValue.isPresent()) {
selectedValue = tmpSelectedValue.get();
}
comboViewer.setInput(highlightableFlowElements.entrySet());
}
}
showFlowContributionItem.updateShowFlowItem(selectedValue.getValue());
editFlowContributionItem.updateEditFlowItem(selectedValue.getValue());
deleteFlowContributionItem.updateDeleteFlowItem(selectedValue.getValue());
final StructuredSelection newSelection = new StructuredSelection(selectedValue);
if (!Objects.equal(newSelection, comboViewer.getSelection())) {
comboViewer.setSelection(newSelection);
onSelection(newSelection.getFirstElement());
}
}
}
use of org.osate.ge.services.QueryService in project osate2 by osate.
the class CreateModeTransitionPaletteCommand method getPotentialOwnersByMode.
private static List<ComponentClassifier> getPotentialOwnersByMode(final BusinessObjectContext modeBoc, final QueryService queryService) {
final Mode mode = (Mode) modeBoc.getBusinessObject();
final String modeName = mode.getName();
if (modeName == null) {
return Collections.emptyList();
}
final BusinessObjectContext containerBoc = getOwnerBoc(modeBoc, queryService);
if (containerBoc == null) {
return Collections.emptyList();
}
final Element bo = (Element) containerBoc.getBusinessObject();
return AadlUiUtil.getPotentialComponentClassifiers(bo).stream().filter(tmpBo -> tmpBo instanceof ComponentClassifier && !(tmpBo.isDerivedModes())).filter(cc -> hasModeWithName(cc, modeName)).collect(Collectors.toList());
}
use of org.osate.ge.services.QueryService in project osate2 by osate.
the class FlowSpecificationCreationUtil method getPotentialOwnersByFeature.
public static List<ComponentType> getPotentialOwnersByFeature(BusinessObjectContext featureBoc, final QueryService queryService) {
final Context context = getContext(featureBoc, queryService);
final Feature feature = (Feature) featureBoc.getBusinessObject();
final String childName = context == null ? feature.getName() : context.getName();
if (childName == null) {
return Collections.emptyList();
}
final BusinessObjectContext containerBoc = getFlowSpecificationOwnerBoc(featureBoc, queryService);
if (containerBoc == null) {
return Collections.emptyList();
}
final Element bo = (Element) containerBoc.getBusinessObject();
return AadlUiUtil.getPotentialClassifierTypesForEditing(bo).stream().filter(tmpBo -> canOwnFlowSpecification(tmpBo)).map(ComponentType.class::cast).filter(ct -> hasFeatureWithName(ct, childName)).collect(Collectors.toList());
}
Aggregations