From 7dd9579f2b8e3eabdad63c8cce46d5c7ff2e42fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Sun, 29 Oct 2017 01:11:15 +0300 Subject: [PATCH] Means to handle connection selections without configuration component refs #7583 Change-Id: I7e8f77aaf54156bdb187f3220d0191db0a77f7e8 --- .../DiagramViewerSelectionProvider.java | 28 +++++++++++++++++++ .../AbstractVariableTabContribution.java | 2 +- .../ui/selection/ParentVariable.java | 14 ++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 bundles/org.simantics.ui/src/org/simantics/ui/selection/ParentVariable.java diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java index 4ef86b753..154d8d4c7 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java @@ -31,6 +31,7 @@ import org.simantics.modeling.ModelingResources; import org.simantics.ui.SimanticsUI; import org.simantics.ui.selection.AnyResource; import org.simantics.ui.selection.AnyVariable; +import org.simantics.ui.selection.ParentVariable; import org.simantics.ui.selection.WorkbenchSelectionContentType; import org.simantics.utils.DataContainer; import org.simantics.utils.threads.IThreadWorkQueue; @@ -109,7 +110,34 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider { } catch (DatabaseException e) { Logger.defaultLogError(e); } + } + else if(contentType instanceof ParentVariable) { + ParentVariable type = (ParentVariable)contentType; + try { + return (T) type.processor.sync(new ResourceRead2(runtime, element) { + @Override + public Variable perform(ReadGraph graph) throws DatabaseException { + + DiagramResource DIA = DiagramResource.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + + String uri = graph.getPossibleRelatedValue(resource, DIA.RuntimeDiagram_HasVariable); + if (uri == null) + return null; + + Variable var = Variables.getPossibleVariable(graph, uri); + if (var == null) + return null; + + return var; + } + }); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + } } + return null; } diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractVariableTabContribution.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractVariableTabContribution.java index 8063eb3c1..76f49af30 100644 --- a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractVariableTabContribution.java +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractVariableTabContribution.java @@ -69,7 +69,7 @@ abstract public class AbstractVariableTabContribution implements TabContribution } @Override - final public void contribute(ReadGraph graph, final Object selection, Collection result) throws DatabaseException { + public void contribute(ReadGraph graph, final Object selection, Collection result) throws DatabaseException { Variable variable = getPossibleVariable(graph, selection); if(variable == null) return; diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/selection/ParentVariable.java b/bundles/org.simantics.ui/src/org/simantics/ui/selection/ParentVariable.java new file mode 100644 index 000000000..39c919798 --- /dev/null +++ b/bundles/org.simantics.ui/src/org/simantics/ui/selection/ParentVariable.java @@ -0,0 +1,14 @@ +package org.simantics.ui.selection; + +import org.simantics.db.RequestProcessor; +import org.simantics.db.layer0.variable.Variable; + +public class ParentVariable implements WorkbenchSelectionContentType { + + public RequestProcessor processor; + + public ParentVariable(RequestProcessor processor) { + this.processor = processor; + } + +} -- 2.47.1