- viewer = new TreeViewer(this, SWT.FULL_SELECTION);
- viewer.addDoubleClickListener(new IDoubleClickListener() {
- @Override
- public void doubleClick(DoubleClickEvent event) {
- TreeSelection selection = (TreeSelection) viewer.getSelection();
- ElementSelector query = (ElementSelector) selection.getFirstElement();
- try {
- List<AdaptableHintContext> elements = Simantics.getSession().syncRequest(new Read<List<AdaptableHintContext>>() {
- @SuppressWarnings("unchecked")
- @Override
- public List<AdaptableHintContext> perform(ReadGraph graph) throws DatabaseException {
- Resource model = ActiveModels.getPossibleActiveModel(graph, Simantics.getProjectResource());
- if (model == null) {
- LOGGER.warn("No active model");
- return Collections.emptyList();
- }
-
- List<Resource> result = query.selectElementsFrom(graph, model);
- return Lists.map(new FunctionImpl1<Resource, AdaptableHintContext>() {
- public AdaptableHintContext apply(Resource p0) {
- AdaptableHintContext selectionElement = new SelectionElement(SelectionHints.STD_KEYS, graph);
- selectionElement.setHint(SelectionHints.KEY_MAIN, p0);
- selectionElement.setHint(SelectionHints.KEY_MODEL, model);
- return selectionElement;
- }
- }, result);
- }
- });
-
- selectionService.setPostSelection(new StructuredSelection(elements));
- } catch (DatabaseException e) {
- LOGGER.error("Element selection query failed", e);
- }
- }
- });
-
- viewer.setContentProvider(new ITreeContentProvider() {
- @Override
- public boolean hasChildren(Object element) {
- return false;
- }