From: Reino Ruusu Date: Fri, 22 Feb 2019 11:58:32 +0000 (+0200) Subject: Opening of diagram element query result in diagram view. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F73%2F2673%2F1;p=simantics%2Fdistrict.git Opening of diagram element query result in diagram view. gitlab #28 Change-Id: Ibdecf9acc683bad6cd11161b50c99409581d4f46 --- diff --git a/org.simantics.district.selection.ui/META-INF/MANIFEST.MF b/org.simantics.district.selection.ui/META-INF/MANIFEST.MF index ee821144..91f61246 100644 --- a/org.simantics.district.selection.ui/META-INF/MANIFEST.MF +++ b/org.simantics.district.selection.ui/META-INF/MANIFEST.MF @@ -4,16 +4,29 @@ Bundle-SymbolicName: org.simantics.district.selection.ui;singleton:=tr ue Bundle-Name: Diagram element selection UI Bundle-Version: 1.0.0.qualifier -Require-Bundle: javax.inject,org.eclipse.osgi,org.eclipse.jface,org.ec - lipse.e4.ui.model.workbench,org.eclipse.e4.ui.di,org.eclipse.e4.ui.se - rvices,org.eclipse.e4.core.di.annotations,org.eclipse.e4.ui.workbench - ,org.slf4j.api,org.simantics,org.simantics.district.region,org.simant - ics.district.selection,org.simantics.db.common,org.simantics.ui,com.f - amfamfam.silk;bundle-version="1.3.0",org.simantics.browsing.ui.common - ,org.eclipse.e4.core.contexts,org.eclipse.e4.core.di;bundle-version=" - 1.6.100",org.simantics.district.region.ontology,org.simantics.distric - t.route.ontology,org.simantics.modeling.ontology,org.simantics.silk.o - ntology;bundle-version=1.1.0 +Require-Bundle: javax.inject, + org.eclipse.osgi, + org.eclipse.jface, + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.ui.di, + org.eclipse.e4.ui.services, + org.eclipse.e4.core.di.annotations, + org.eclipse.e4.ui.workbench, + org.slf4j.api, + org.simantics, + org.simantics.district.region, + org.simantics.district.selection, + org.simantics.db.common, + org.simantics.ui, + com.famfamfam.silk;bundle-version="1.3.0", + org.simantics.browsing.ui.common, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di;bundle-version="1.6.100", + org.simantics.district.region.ontology, + org.simantics.district.route.ontology, + org.simantics.modeling.ontology, + org.simantics.silk.ontology;bundle-version="1.1.0", + org.simantics.district.network.ui Bundle-ManifestVersion: 2 Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: Semantum oy diff --git a/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectorTableUI.java b/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectorTableUI.java index 0786ce53..8ed8d3e1 100644 --- a/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectorTableUI.java +++ b/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectorTableUI.java @@ -10,10 +10,8 @@ import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.viewers.TreeViewer; @@ -29,15 +27,17 @@ import org.simantics.browsing.ui.common.AdaptableHintContext; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.SyncListenerAdapter; +import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.RuntimeDatabaseException; import org.simantics.db.layer0.QueryIndexUtils; import org.simantics.db.layer0.SelectionHints; import org.simantics.db.layer0.request.ActiveModels; +import org.simantics.db.layer0.variable.Variable; import org.simantics.db.request.Read; +import org.simantics.district.network.ui.DistrictNetworkUIUtil; import org.simantics.district.selection.ElementSelectionResource; -import org.simantics.district.selection.ElementSelectionUtils; import org.simantics.district.selection.ElementSelector; +import org.simantics.district.selection.ElementSelector.DiagramGenerator; import org.simantics.layer0.Layer0; import org.simantics.scl.runtime.Lists; import org.simantics.scl.runtime.function.FunctionImpl1; @@ -63,40 +63,7 @@ public class ElementSelectorTableUI extends Composite { this.setLayout(new FillLayout()); 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 elements = Simantics.getSession().syncRequest(new Read>() { - @SuppressWarnings("unchecked") - @Override - public List perform(ReadGraph graph) throws DatabaseException { - Resource model = ActiveModels.getPossibleActiveModel(graph, Simantics.getProjectResource()); - if (model == null) { - LOGGER.warn("No active model"); - return Collections.emptyList(); - } - - List result = query.selectElementsFrom(graph, model); - return Lists.map(new FunctionImpl1() { - 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.addDoubleClickListener(new DoubleClickListener(selectionService)); viewer.setContentProvider(new ITreeContentProvider() { @Override @@ -196,12 +163,9 @@ public class ElementSelectorTableUI extends Composite { return selection != null ? (ElementSelector) selection.getFirstElement() : null; } - private final class SelectionElement extends AdaptableHintContext { - private final ReadGraph graph; - - private SelectionElement(Key[] keys, ReadGraph graph) { + private static final class SelectionElement extends AdaptableHintContext { + private SelectionElement(Key[] keys) { super(keys); - this.graph = graph; } @SuppressWarnings("unchecked") @@ -212,7 +176,11 @@ public class ElementSelectorTableUI extends Composite { } else if (contentType instanceof AnyVariable) { try { - return (T)ElementSelector.getVariableForElement(graph, element); + return (T) Simantics.getSession().syncRequest(new ResourceRead(element) { + public Variable perform(ReadGraph graph) throws DatabaseException { + return ElementSelector.getVariableForElement(graph, resource); + } + }); } catch (DatabaseException e) { return null; } @@ -222,7 +190,7 @@ public class ElementSelectorTableUI extends Composite { } } - public static class SelectionsRequest implements Read> { + public static final class SelectionsRequest implements Read> { @Override public Collection perform(ReadGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); @@ -250,4 +218,49 @@ public class ElementSelectorTableUI extends Composite { return result; } } + + private static final class DoubleClickListener implements IDoubleClickListener { + private final ESelectionService selectionService; + private Resource model; + + private DoubleClickListener(ESelectionService selectionService) { + this.selectionService = selectionService; + } + + @Override + public void doubleClick(DoubleClickEvent event) { + TreeSelection selection = (TreeSelection) event.getViewer().getSelection(); + ElementSelector query = (ElementSelector) selection.getFirstElement(); + try { + List result = Simantics.getSession().syncRequest(new Read>() { + @Override + public List perform(ReadGraph graph) throws DatabaseException { + model = ActiveModels.getPossibleActiveModel(graph, Simantics.getProjectResource()); + if (model == null) { + LOGGER.warn("No active model"); + return Collections.emptyList(); + } + + return query.selectElementsFrom(graph, model); + } + }); + + if (query.getGenerator() instanceof DiagramGenerator) { + DistrictNetworkUIUtil.openDNDiagramWithSelection(event.getViewer().getControl().getDisplay(), result); + } + else { + selectionService.setPostSelection(new StructuredSelection(Lists.map(new FunctionImpl1() { + public AdaptableHintContext apply(Resource p0) { + AdaptableHintContext selectionElement = new SelectionElement(SelectionHints.STD_KEYS); + selectionElement.setHint(SelectionHints.KEY_MAIN, p0); + selectionElement.setHint(SelectionHints.KEY_MODEL, model); + return selectionElement; + } + }, result))); + } + } catch (DatabaseException e) { + LOGGER.error("Element selection query failed", e); + } + } + } }