]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Expose helpContextId resolving to other implementations 99/2299/3
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 11 Oct 2018 11:13:14 +0000 (14:13 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 11 Oct 2018 11:48:26 +0000 (11:48 +0000)
gitlab #147

Change-Id: I34fd73a223a8ca00b89397f59870b6442411d4c6

bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/ContextualHelp.java

index 9a1ea8360a751fe67aa294523be125f10a3f5150..0d0ec7ce64d5554b46e1913ebb3cd33a21f3ddde 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2017 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,7 @@
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
  *     Semantum Oy - #7116 regression fix
+ *     Semantum Oy - gitlab #147 - expose getPossibleId implementation
  *******************************************************************************/
 package org.simantics.modeling.ui.modelBrowser.handlers;
 
@@ -46,33 +47,7 @@ public class ContextualHelp extends AbstractHandler {
             return Simantics.getSession().syncRequest(new UniqueRead<String>() {
                 @Override
                 public String perform(ReadGraph graph) throws DatabaseException {
-                    ModelingResources MOD = ModelingResources.getInstance(graph);
-                    if (resource != null) {
-                        Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
-                        String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
-                        if (id != null)
-                            return id;
-                        id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
-                        if (id != null)
-                            return id;
-                    }
-
-                    if (variable != null) {
-                        String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
-                        if (id != null)
-                            return id;
-                    }
-
-                    // TODO: consider removing this block
-                    if (sel != null) {
-                        PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
-                        Variable var = vars != null ? vars.getConfiguration() : null;
-                        String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
-                        if (id != null)
-                            return id;
-                    }
-
-                    return null;
+                    return getPossibleId(graph, resource, variable, sel);
                 }
             });
         } catch (DatabaseException e) {
@@ -89,4 +64,34 @@ public class ContextualHelp extends AbstractHandler {
         return null;
     }
 
+    public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, ISelection sel) throws DatabaseException {
+        ModelingResources MOD = ModelingResources.getInstance(graph);
+        if (resource != null) {
+            Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
+            String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
+            if (id != null)
+                return id;
+            id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
+            if (id != null)
+                return id;
+        }
+
+        if (variable != null) {
+            String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
+            if (id != null)
+                return id;
+        }
+
+        // TODO: consider removing this block
+        if (sel != null) {
+            PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
+            Variable var = vars != null ? vars.getConfiguration() : null;
+            String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
+            if (id != null)
+                return id;
+        }
+
+        return null;
+    }
+
 }