]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Means to handle connection selections without configuration component 55/1155/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Sat, 28 Oct 2017 22:11:15 +0000 (01:11 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Sat, 28 Oct 2017 22:11:15 +0000 (01:11 +0300)
refs #7583

Change-Id: I7e8f77aaf54156bdb187f3220d0191db0a77f7e8

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java
bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractVariableTabContribution.java
bundles/org.simantics.ui/src/org/simantics/ui/selection/ParentVariable.java [new file with mode: 0644]

index 4ef86b753b4c54a8eea8b17ee1eb788a7e0acb60..154d8d4c73cfed685ba560060899bfd9c80e7991 100644 (file)
@@ -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<Variable>(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;
         }
 
index 8063eb3c1489d206d3f21650ba3a2e10ec95fc31..76f49af30a18ee8860c6d0739c8126001f8a0815 100644 (file)
@@ -69,7 +69,7 @@ abstract public class AbstractVariableTabContribution implements TabContribution
        } 
        
        @Override
-       final public void contribute(ReadGraph graph, final Object selection, Collection<ComparableTabContributor> result) throws DatabaseException {
+       public void contribute(ReadGraph graph, final Object selection, Collection<ComparableTabContributor> 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 (file)
index 0000000..39c9197
--- /dev/null
@@ -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<Variable>  {
+
+       public RequestProcessor processor;
+       
+       public ParentVariable(RequestProcessor processor) {
+               this.processor = processor;
+       }
+       
+}