- try {
- SelectionResult result = Simantics.getSession().syncRequest(new Read<SelectionResult>() {
- @Override
- public SelectionResult perform(ReadGraph graph) throws DatabaseException {
- model = ActiveModels.getPossibleActiveModel(graph, Simantics.getProjectResource());
- if (model == null) {
- LOGGER.warn("No active model");
- return new SelectionResult(Collections.emptyList(), 0, 0);
- }
-
- return query.selectElementsFrom(graph, model);
- }
- });
-
- if (query.getGenerator() instanceof DiagramGenerator || query.getGenerator() instanceof ExplicitGenerator) {
- DistrictNetworkUIUtil.openDNDiagramWithSelection(event.getViewer().getControl().getDisplay(), new ArrayList<>(result.elements));
- }
- else {
- selectionService.setPostSelection(new StructuredSelection(result.elements.stream()
- .map(p0 -> {
- AdaptableHintContext selectionElement = new SelectionElement(SelectionHints.STD_KEYS);
- selectionElement.setHint(SelectionHints.KEY_MAIN, p0);
- selectionElement.setHint(SelectionHints.KEY_MODEL, model);
- return selectionElement;
- })
- .toArray()));
- }
-
- if (result.tailCount != result.tailSize) {
- String name = query.getSelector() != null && query.getSelector() instanceof PropertySelector ? ((PropertySelector)query.getSelector()).propertyName : null;
- String msg = "Last " + result.tailCount + " of the " + result.elements.size() + " selected elements are an arbitraty subset of " + result.tailSize + " elements with equal values" +
- (name != null ? " for " + name : "");
- MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Note", msg);
- }
- } catch (DatabaseException e) {
- LOGGER.error("Element selection query failed", e);
- }