]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/function/PredefinedVariables.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / function / PredefinedVariables.java
index d3eafc2bd9c1f1f8d69c9dd44421c484316ca734..db47b99041daeff305e414149f8f57b21688f86f 100644 (file)
-package org.simantics.diagram.function;\r
-\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.simantics.annotation.ontology.AnnotationResource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.layer0.variable.Variables;\r
-import org.simantics.diagram.content.ConnectionUtil;\r
-import org.simantics.diagram.flag.FlagUtil;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.template2d.ontology.Template2dResource;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.ui.SimanticsUI;\r
-\r
-public class PredefinedVariables {\r
-       public static final String root = "root";\r
-       public static final String project = "project";\r
-       public static final String model = "model";\r
-       public static final String template = "template";\r
-       public static final String current = ".";\r
-       public static final String diagramComposite = "diagramComposite";\r
-       public static final String diagram = "diagram";\r
-       public static final String flagAnnotation = "annotation";\r
-       \r
-       /** \r
-        *  flagSourceObject    refers to a structural component which has an element on the flag's diagram  \r
-        */\r
-       public static final String flagSourceObject = "flagSourceObject";\r
-\r
-       /** \r
-        *  flagTargetObject    refers to a structural component which has an element on the counterpart flag's diagram  \r
-        */\r
-       public static final String flagTargetObject = "flagTargetObject";\r
-\r
-       /** \r
-        *  flagSourceComposite refers to a structural composite which corresponds the flag's diagram  \r
-        */\r
-       public static final String flagSourceComposite = "flagSourceComposite";\r
-\r
-       /** \r
-        *  flagTargetComposite refers to a structural composite which corresponds the counterpart flag's diagram  \r
-        */\r
-       public static final String flagTargetComposite = "flagTargetComposite";\r
-\r
-       /** \r
-        *  flagRouterComponent refers to a structural component which corresponds a graphical connection connected with the flag  \r
-        */\r
-       public static final String flagRouterComponent = "flagRouterComponent";\r
-\r
-       private static PredefinedVariables factory = new PredefinedVariables();\r
-       \r
-       public static PredefinedVariables getInstance(){\r
-               return factory;\r
-       }\r
-       \r
-       public static void setFactory(PredefinedVariables factory){\r
-               PredefinedVariables.factory = factory;\r
-       }\r
-       \r
-    Resource connectedComponent = null;\r
-    \r
-    private Resource getConnectedComponent(ReadGraph graph, Resource flag) throws DatabaseException {\r
-               StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
-               ModelingResources MOD = ModelingResources.getInstance(graph);\r
-               ConnectionUtil cu = new ConnectionUtil(graph);\r
-               Resource connectedComponent = null;\r
-               Set<Resource> connectors = new HashSet<Resource>();\r
-               for (Resource connector : graph.getObjects(flag, STR.IsConnectedTo)) {\r
-                   Resource diagramConnection = ConnectionUtil.tryGetConnection(graph, connector);\r
-                   if (diagramConnection != null) {\r
-                       connectors.clear();\r
-                       cu.getConnectors(diagramConnection, connectors);\r
-                       connectors.remove(connector);\r
-                       if (connectors.isEmpty()) {\r
-                           continue;\r
-                       } else {\r
-                           //connectedComponent = graph.getPossibleObject(diagramConnection, MOD.ElementToComponent);\r
-                           if (connectedComponent == null) {\r
-                               for (Resource conn : connectors) {\r
-                                   Resource element = cu.getConnectedComponent(diagramConnection, conn);\r
-                                   if (element == null)\r
-                                       continue;\r
-                                   connectedComponent = graph.getPossibleObject(element, MOD.ElementToComponent);\r
-                                   if (connectedComponent != null)\r
-                                       break;\r
-                               }\r
-                           }\r
-                       }\r
-                   }\r
-               }\r
-               return connectedComponent;\r
-    }\r
-\r
-    public Resource getFlagRouterComponent(ReadGraph graph, Variable variable) throws DatabaseException {\r
-        Resource flag = variable.getPossibleRepresents(graph);\r
-        return flag == null ? null : getFlagRouterComponent(graph, flag);\r
-    }\r
-\r
-    public Resource getFlagRouterComponent(ReadGraph graph, Resource flag) throws DatabaseException {\r
-\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        ModelingResources MOD = ModelingResources.getInstance(graph);\r
-\r
-        Resource container = graph.getSingleObject(flag, L0.PartOf);\r
-        Resource composite = graph.getSingleObject(container, MOD.DiagramToComposite);\r
-        Variable var = Variables.getVariable(graph, composite);\r
-\r
-//        System.err.println("var: " + var.getURI(graph));\r
-\r
-        Variable result = FlagUtil.getPossibleFlagSignal(graph, var, flag, L0.Entity);\r
-        if(result != null) return result.getRepresents(graph);\r
-        else return null;\r
-\r
-    }\r
-\r
-       private Resource getFlagTargetObject(ReadGraph graph, Variable variable){\r
-               try {\r
-                       Resource flag = variable.getRepresents(graph);\r
-                       Set<Resource> targetFlags = FlagUtil.getCounterparts(graph, flag);\r
-\r
-                       // if there are multiple targets\r
-                       if (targetFlags.size() != 1)\r
-                               return null;\r
-\r
-                       Resource targetFlag = targetFlags.toArray(new Resource[0])[0];\r
-                       if (targetFlag == null)\r
-                               return null;\r
-               Resource connectedComponent = getConnectedComponent(graph, targetFlag);\r
-                       if (connectedComponent == null)\r
-                               return null;\r
-                       return connectedComponent;\r
-               } catch (DatabaseException e) {\r
-               }\r
-               return null;\r
-       }\r
-\r
-       private Resource getFlagSourceObject(ReadGraph graph, Variable variable){\r
-               try {\r
-                       Resource flag = variable.getRepresents(graph);\r
-                       Resource connectedComponent = getConnectedComponent(graph, flag);\r
-                       if (connectedComponent == null)\r
-                               return null;\r
-                       return connectedComponent;\r
-               } catch (DatabaseException e) {\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       private Resource getFlagSourceComposite(ReadGraph graph, Variable variable){\r
-               try {\r
-                       Layer0 L0 = Layer0.getInstance(graph);\r
-                       ModelingResources MOD = ModelingResources.getInstance(graph);\r
-                       \r
-                       Resource flag = variable.getRepresents(graph);\r
-                       Resource diagram = graph.getPossibleObject(flag, L0.PartOf);\r
-                       if (diagram == null)\r
-                               return null;\r
-                       Resource composite = graph.getPossibleObject(diagram, MOD.DiagramToComposite);\r
-                       if (composite == null)\r
-                               return null;\r
-                       return composite;\r
-               } catch (DatabaseException e) {\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       private Resource getFlagTargetComposite(ReadGraph graph, Variable variable){\r
-               try {\r
-                       Layer0 L0 = Layer0.getInstance(graph);\r
-                       ModelingResources MOD = ModelingResources.getInstance(graph);\r
-                       \r
-                       Resource flag = variable.getRepresents(graph);\r
-                       Set<Resource> targetFlags = FlagUtil.getCounterparts(graph, flag);\r
-                       \r
-                       // if there are multiple targets\r
-                       if (targetFlags.size() != 1)\r
-                               return null;\r
-                       \r
-                       Resource targetFlag = targetFlags.toArray(new Resource[0])[0];\r
-                       if (targetFlag == null)\r
-                               return null;\r
-                       Resource diagram = graph.getPossibleObject(targetFlag, L0.PartOf);\r
-                       if (diagram == null)\r
-                               return null;\r
-                       Resource composite = graph.getPossibleObject(diagram, MOD.DiagramToComposite);\r
-                       if (composite == null)\r
-                               return null;\r
-                       return composite;\r
-               } catch (DatabaseException e) {\r
-               }\r
-               return null;\r
-       }\r
-\r
-       public static Resource getAnnotation(ReadGraph graph, Resource res) throws DatabaseException {\r
-               Layer0 L0 = Layer0.getInstance(graph);\r
-        Collection<Resource> children = graph.getObjects(res, L0.ConsistsOf);\r
-        Resource anno = null;\r
-        AnnotationResource ANNO = AnnotationResource.getInstance(graph);\r
-        for (Resource child:children){\r
-               if (graph.isInstanceOf(child, ANNO.Annotation)){\r
-                       anno = child;\r
-                       break;\r
-               }\r
-        }\r
-        return anno;\r
-       } \r
-\r
-       private Resource getDiagramComposite(ReadGraph graph, Variable variable){\r
-               try {\r
-                       Resource res = variable.getRepresents(graph);\r
-                       if (res == null)\r
-                               return null;\r
-                       DiagramResource DIA = DiagramResource.getInstance(graph);\r
-                       if (graph.isInstanceOf(res, DIA.Flag)){\r
-                               ModelingResources MOD = ModelingResources.getInstance(graph);\r
-                               Layer0 L0 = Layer0.getInstance(graph);\r
-                               Resource parent = graph.getPossibleObject(res, L0.PartOf);\r
-                               if (parent == null)\r
-                                       return null;\r
-                               if (!graph.isInstanceOf(parent, DIA.Diagram))\r
-                                       return null;\r
-                               return graph.getPossibleObject(parent, MOD.DiagramToComposite);\r
-                       }\r
-                       return res;\r
-               } catch (DatabaseException e) {\r
-               }\r
-               return null;\r
-       }\r
-\r
-       public Resource getPredefinedResource(ReadGraph graph, Variable selection, String id) throws DatabaseException {\r
-               Resource predefined = null;\r
-        if (id.equals(root))\r
-               predefined = graph.getRootLibrary();\r
-        else if (id.equals(project))\r
-               predefined = SimanticsUI.getProject().get();\r
-        else if (id.equals(model))\r
-               predefined = Variables.getPossibleModel(graph, selection);\r
-        else if (id.equals(template)){\r
-                       Resource composite = selection.getRepresents(graph);\r
-                       if (composite == null)\r
-                               return null;\r
-                       ModelingResources MOD = ModelingResources.getInstance(graph);\r
-            Template2dResource TEPLATE2D = Template2dResource.getInstance(graph);\r
-                       Resource diagram = graph.getPossibleObject(composite, MOD.CompositeToDiagram);\r
-                       if (diagram == null)\r
-                               return null;\r
-                       predefined = graph.getPossibleObject(diagram, TEPLATE2D.HasDrawingTemplate);\r
-        }\r
-        else if (id.equals(current))\r
-               predefined =  selection.getPossibleRepresents(graph);\r
-        else if (id.equals(flagAnnotation)){\r
-               Resource flag = selection.getPossibleRepresents(graph);\r
-               if (flag != null)\r
-                       predefined = getAnnotation(graph, flag);\r
-        }\r
-        else if (id.equals(diagram)){\r
-                       Resource composite = selection.getPossibleRepresents(graph);\r
-                       if (composite == null)\r
-                               return null;\r
-                       ModelingResources MOD = ModelingResources.getInstance(graph);\r
-                       predefined = graph.getPossibleObject(composite, MOD.CompositeToDiagram);\r
-        }\r
-        else if (id.equals(diagramComposite))\r
-               predefined = getDiagramComposite(graph, selection);\r
-        else if (id.equals(flagSourceObject))\r
-               predefined = getFlagSourceObject(graph, selection);\r
-        else if (id.equals(flagTargetObject))\r
-               predefined = getFlagTargetObject(graph, selection);\r
-        else if (id.equals(flagSourceComposite))\r
-               predefined = getFlagSourceComposite(graph, selection);\r
-        else if (id.equals(flagTargetComposite))\r
-               predefined = getFlagTargetComposite(graph, selection);\r
-        else if (id.equals(flagRouterComponent))\r
-               predefined = getFlagRouterComponent(graph, selection);\r
-        return predefined;\r
-       }\r
-       \r
-       public Variable getPredefinedVariable(ReadGraph graph, Variable selection, String id) throws DatabaseException {\r
-               Resource predefined = this.getPredefinedResource(graph, selection, id);\r
-               if (predefined == null)\r
-                       return null;\r
-               \r
-        Variable v = selection;\r
-        if (predefined != null)\r
-            v = Variables.getPossibleVariable(graph, predefined);\r
-        return v;\r
-       }\r
-       \r
-       public Variable getVariable(ReadGraph graph, String path, Resource converter, Variable selection) throws DatabaseException {\r
-        if (path == null)\r
-               return null;\r
-        int colonInx = path.indexOf(':');\r
-        int firstSlash = path.indexOf('/');\r
-        int firstHash = path.indexOf('#');\r
-        int firstFlashInx = firstSlash;\r
-        if(firstFlashInx == -1) firstFlashInx = firstHash;\r
-        else {\r
-               if(firstHash > -1 && firstHash < firstFlashInx) firstFlashInx = firstHash;\r
-        }\r
-\r
-        String predefined = null;\r
-        String relativePath = null;\r
-\r
-        // if scheme is followed by absolute uri\r
-        // for examples:\r
-        // pre:/model/Library/logo.svg#data -- get under model\r
-        // pre:/./Library/logo.svg#data-- get under composite which corresponds the diagram\r
-        // pre:/project/Library/FORTUM_LOGO_CMYK.svg#data -- get under project\r
-        // pre:/root/Library/FORTUM_LOGO_CMYK.svg#data -- get under root\r
-        \r
-        if (colonInx != -1 && firstFlashInx != -1 && colonInx+1 == firstFlashInx && path.length() > firstFlashInx+1){\r
-            String scheme = path.substring(0, colonInx);\r
-            String absPath = path.substring(firstFlashInx+1);\r
-            if (scheme.equals("pre")){\r
-                int endOfPredefined1 = absPath.indexOf('/');\r
-                int endOfPredefined2 = absPath.indexOf('#');\r
-                if (endOfPredefined1 == -1 && endOfPredefined2 == -1)\r
-                    predefined = absPath;\r
-                if (endOfPredefined1 == -1 && endOfPredefined2 != -1)\r
-                    predefined = absPath.substring(0, endOfPredefined2);\r
-                if (endOfPredefined1 != -1 && endOfPredefined2 == -1)\r
-                    predefined = absPath.substring(0, endOfPredefined1);\r
-                if (endOfPredefined1 != -1 && endOfPredefined2 != -1){\r
-                    if (endOfPredefined2 < endOfPredefined1)\r
-                        endOfPredefined1 = endOfPredefined2;\r
-                    predefined = absPath.substring(0, endOfPredefined1);\r
-                }\r
-                relativePath = absPath.substring(predefined.length());\r
-            }\r
-        }\r
-\r
-        //Variable activeVariable = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context);\r
-        if (selection == null)\r
-               return null;\r
-        \r
-        Variable v = selection;\r
-        if (predefined != null)\r
-               v = getPredefinedVariable(graph, selection, predefined);\r
-\r
-        if (v == null)\r
-            return null;\r
-\r
-        Variable property = null;\r
-        if (relativePath != null){\r
-               if (relativePath.startsWith("/."))\r
-                       relativePath = relativePath.substring(1);\r
-            property = v.browsePossible(graph, relativePath);\r
-        }\r
-        else\r
-            property = v.browsePossible(graph, path);\r
-        return property;\r
-    }\r
-\r
-}\r
+package org.simantics.diagram.function;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.simantics.annotation.ontology.AnnotationResource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.diagram.content.ConnectionUtil;
+import org.simantics.diagram.flag.FlagUtil;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.template2d.ontology.Template2dResource;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.ui.SimanticsUI;
+
+public class PredefinedVariables {
+       public static final String root = "root";
+       public static final String project = "project";
+       public static final String model = "model";
+       public static final String template = "template";
+       public static final String current = ".";
+       public static final String diagramComposite = "diagramComposite";
+       public static final String diagram = "diagram";
+       public static final String flagAnnotation = "annotation";
+       
+       /** 
+        *  flagSourceObject    refers to a structural component which has an element on the flag's diagram  
+        */
+       public static final String flagSourceObject = "flagSourceObject";
+
+       /** 
+        *  flagTargetObject    refers to a structural component which has an element on the counterpart flag's diagram  
+        */
+       public static final String flagTargetObject = "flagTargetObject";
+
+       /** 
+        *  flagSourceComposite refers to a structural composite which corresponds the flag's diagram  
+        */
+       public static final String flagSourceComposite = "flagSourceComposite";
+
+       /** 
+        *  flagTargetComposite refers to a structural composite which corresponds the counterpart flag's diagram  
+        */
+       public static final String flagTargetComposite = "flagTargetComposite";
+
+       /** 
+        *  flagRouterComponent refers to a structural component which corresponds a graphical connection connected with the flag  
+        */
+       public static final String flagRouterComponent = "flagRouterComponent";
+
+       private static PredefinedVariables factory = new PredefinedVariables();
+       
+       public static PredefinedVariables getInstance(){
+               return factory;
+       }
+       
+       public static void setFactory(PredefinedVariables factory){
+               PredefinedVariables.factory = factory;
+       }
+       
+    Resource connectedComponent = null;
+    
+    private Resource getConnectedComponent(ReadGraph graph, Resource flag) throws DatabaseException {
+               StructuralResource2 STR = StructuralResource2.getInstance(graph);
+               ModelingResources MOD = ModelingResources.getInstance(graph);
+               ConnectionUtil cu = new ConnectionUtil(graph);
+               Resource connectedComponent = null;
+               Set<Resource> connectors = new HashSet<Resource>();
+               for (Resource connector : graph.getObjects(flag, STR.IsConnectedTo)) {
+                   Resource diagramConnection = ConnectionUtil.tryGetConnection(graph, connector);
+                   if (diagramConnection != null) {
+                       connectors.clear();
+                       cu.getConnectors(diagramConnection, connectors);
+                       connectors.remove(connector);
+                       if (connectors.isEmpty()) {
+                           continue;
+                       } else {
+                           //connectedComponent = graph.getPossibleObject(diagramConnection, MOD.ElementToComponent);
+                           if (connectedComponent == null) {
+                               for (Resource conn : connectors) {
+                                   Resource element = cu.getConnectedComponent(diagramConnection, conn);
+                                   if (element == null)
+                                       continue;
+                                   connectedComponent = graph.getPossibleObject(element, MOD.ElementToComponent);
+                                   if (connectedComponent != null)
+                                       break;
+                               }
+                           }
+                       }
+                   }
+               }
+               return connectedComponent;
+    }
+
+    public Resource getFlagRouterComponent(ReadGraph graph, Variable variable) throws DatabaseException {
+        Resource flag = variable.getPossibleRepresents(graph);
+        return flag == null ? null : getFlagRouterComponent(graph, flag);
+    }
+
+    public Resource getFlagRouterComponent(ReadGraph graph, Resource flag) throws DatabaseException {
+
+        Layer0 L0 = Layer0.getInstance(graph);
+        ModelingResources MOD = ModelingResources.getInstance(graph);
+
+        Resource container = graph.getSingleObject(flag, L0.PartOf);
+        Resource composite = graph.getSingleObject(container, MOD.DiagramToComposite);
+        Variable var = Variables.getVariable(graph, composite);
+
+//        System.err.println("var: " + var.getURI(graph));
+
+        Variable result = FlagUtil.getPossibleFlagSignal(graph, var, flag, L0.Entity);
+        if(result != null) return result.getRepresents(graph);
+        else return null;
+
+    }
+
+       private Resource getFlagTargetObject(ReadGraph graph, Variable variable){
+               try {
+                       Resource flag = variable.getRepresents(graph);
+                       Set<Resource> targetFlags = FlagUtil.getCounterparts(graph, flag);
+
+                       // if there are multiple targets
+                       if (targetFlags.size() != 1)
+                               return null;
+
+                       Resource targetFlag = targetFlags.toArray(new Resource[0])[0];
+                       if (targetFlag == null)
+                               return null;
+               Resource connectedComponent = getConnectedComponent(graph, targetFlag);
+                       if (connectedComponent == null)
+                               return null;
+                       return connectedComponent;
+               } catch (DatabaseException e) {
+               }
+               return null;
+       }
+
+       private Resource getFlagSourceObject(ReadGraph graph, Variable variable){
+               try {
+                       Resource flag = variable.getRepresents(graph);
+                       Resource connectedComponent = getConnectedComponent(graph, flag);
+                       if (connectedComponent == null)
+                               return null;
+                       return connectedComponent;
+               } catch (DatabaseException e) {
+               }
+               return null;
+       }
+       
+       private Resource getFlagSourceComposite(ReadGraph graph, Variable variable){
+               try {
+                       Layer0 L0 = Layer0.getInstance(graph);
+                       ModelingResources MOD = ModelingResources.getInstance(graph);
+                       
+                       Resource flag = variable.getRepresents(graph);
+                       Resource diagram = graph.getPossibleObject(flag, L0.PartOf);
+                       if (diagram == null)
+                               return null;
+                       Resource composite = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
+                       if (composite == null)
+                               return null;
+                       return composite;
+               } catch (DatabaseException e) {
+               }
+               return null;
+       }
+       
+       private Resource getFlagTargetComposite(ReadGraph graph, Variable variable){
+               try {
+                       Layer0 L0 = Layer0.getInstance(graph);
+                       ModelingResources MOD = ModelingResources.getInstance(graph);
+                       
+                       Resource flag = variable.getRepresents(graph);
+                       Set<Resource> targetFlags = FlagUtil.getCounterparts(graph, flag);
+                       
+                       // if there are multiple targets
+                       if (targetFlags.size() != 1)
+                               return null;
+                       
+                       Resource targetFlag = targetFlags.toArray(new Resource[0])[0];
+                       if (targetFlag == null)
+                               return null;
+                       Resource diagram = graph.getPossibleObject(targetFlag, L0.PartOf);
+                       if (diagram == null)
+                               return null;
+                       Resource composite = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
+                       if (composite == null)
+                               return null;
+                       return composite;
+               } catch (DatabaseException e) {
+               }
+               return null;
+       }
+
+       public static Resource getAnnotation(ReadGraph graph, Resource res) throws DatabaseException {
+               Layer0 L0 = Layer0.getInstance(graph);
+        Collection<Resource> children = graph.getObjects(res, L0.ConsistsOf);
+        Resource anno = null;
+        AnnotationResource ANNO = AnnotationResource.getInstance(graph);
+        for (Resource child:children){
+               if (graph.isInstanceOf(child, ANNO.Annotation)){
+                       anno = child;
+                       break;
+               }
+        }
+        return anno;
+       } 
+
+       private Resource getDiagramComposite(ReadGraph graph, Variable variable){
+               try {
+                       Resource res = variable.getRepresents(graph);
+                       if (res == null)
+                               return null;
+                       DiagramResource DIA = DiagramResource.getInstance(graph);
+                       if (graph.isInstanceOf(res, DIA.Flag)){
+                               ModelingResources MOD = ModelingResources.getInstance(graph);
+                               Layer0 L0 = Layer0.getInstance(graph);
+                               Resource parent = graph.getPossibleObject(res, L0.PartOf);
+                               if (parent == null)
+                                       return null;
+                               if (!graph.isInstanceOf(parent, DIA.Diagram))
+                                       return null;
+                               return graph.getPossibleObject(parent, MOD.DiagramToComposite);
+                       }
+                       return res;
+               } catch (DatabaseException e) {
+               }
+               return null;
+       }
+
+       public Resource getPredefinedResource(ReadGraph graph, Variable selection, String id) throws DatabaseException {
+               Resource predefined = null;
+        if (id.equals(root))
+               predefined = graph.getRootLibrary();
+        else if (id.equals(project))
+               predefined = SimanticsUI.getProject().get();
+        else if (id.equals(model))
+               predefined = Variables.getPossibleModel(graph, selection);
+        else if (id.equals(template)){
+                       Resource composite = selection.getRepresents(graph);
+                       if (composite == null)
+                               return null;
+                       ModelingResources MOD = ModelingResources.getInstance(graph);
+            Template2dResource TEPLATE2D = Template2dResource.getInstance(graph);
+                       Resource diagram = graph.getPossibleObject(composite, MOD.CompositeToDiagram);
+                       if (diagram == null)
+                               return null;
+                       predefined = graph.getPossibleObject(diagram, TEPLATE2D.HasDrawingTemplate);
+        }
+        else if (id.equals(current))
+               predefined =  selection.getPossibleRepresents(graph);
+        else if (id.equals(flagAnnotation)){
+               Resource flag = selection.getPossibleRepresents(graph);
+               if (flag != null)
+                       predefined = getAnnotation(graph, flag);
+        }
+        else if (id.equals(diagram)){
+                       Resource composite = selection.getPossibleRepresents(graph);
+                       if (composite == null)
+                               return null;
+                       ModelingResources MOD = ModelingResources.getInstance(graph);
+                       predefined = graph.getPossibleObject(composite, MOD.CompositeToDiagram);
+        }
+        else if (id.equals(diagramComposite))
+               predefined = getDiagramComposite(graph, selection);
+        else if (id.equals(flagSourceObject))
+               predefined = getFlagSourceObject(graph, selection);
+        else if (id.equals(flagTargetObject))
+               predefined = getFlagTargetObject(graph, selection);
+        else if (id.equals(flagSourceComposite))
+               predefined = getFlagSourceComposite(graph, selection);
+        else if (id.equals(flagTargetComposite))
+               predefined = getFlagTargetComposite(graph, selection);
+        else if (id.equals(flagRouterComponent))
+               predefined = getFlagRouterComponent(graph, selection);
+        return predefined;
+       }
+       
+       public Variable getPredefinedVariable(ReadGraph graph, Variable selection, String id) throws DatabaseException {
+               Resource predefined = this.getPredefinedResource(graph, selection, id);
+               if (predefined == null)
+                       return null;
+               
+        Variable v = selection;
+        if (predefined != null)
+            v = Variables.getPossibleVariable(graph, predefined);
+        return v;
+       }
+       
+       public Variable getVariable(ReadGraph graph, String path, Resource converter, Variable selection) throws DatabaseException {
+        if (path == null)
+               return null;
+        int colonInx = path.indexOf(':');
+        int firstSlash = path.indexOf('/');
+        int firstHash = path.indexOf('#');
+        int firstFlashInx = firstSlash;
+        if(firstFlashInx == -1) firstFlashInx = firstHash;
+        else {
+               if(firstHash > -1 && firstHash < firstFlashInx) firstFlashInx = firstHash;
+        }
+
+        String predefined = null;
+        String relativePath = null;
+
+        // if scheme is followed by absolute uri
+        // for examples:
+        // pre:/model/Library/logo.svg#data -- get under model
+        // pre:/./Library/logo.svg#data-- get under composite which corresponds the diagram
+        // pre:/project/Library/FORTUM_LOGO_CMYK.svg#data -- get under project
+        // pre:/root/Library/FORTUM_LOGO_CMYK.svg#data -- get under root
+        
+        if (colonInx != -1 && firstFlashInx != -1 && colonInx+1 == firstFlashInx && path.length() > firstFlashInx+1){
+            String scheme = path.substring(0, colonInx);
+            String absPath = path.substring(firstFlashInx+1);
+            if (scheme.equals("pre")){
+                int endOfPredefined1 = absPath.indexOf('/');
+                int endOfPredefined2 = absPath.indexOf('#');
+                if (endOfPredefined1 == -1 && endOfPredefined2 == -1)
+                    predefined = absPath;
+                if (endOfPredefined1 == -1 && endOfPredefined2 != -1)
+                    predefined = absPath.substring(0, endOfPredefined2);
+                if (endOfPredefined1 != -1 && endOfPredefined2 == -1)
+                    predefined = absPath.substring(0, endOfPredefined1);
+                if (endOfPredefined1 != -1 && endOfPredefined2 != -1){
+                    if (endOfPredefined2 < endOfPredefined1)
+                        endOfPredefined1 = endOfPredefined2;
+                    predefined = absPath.substring(0, endOfPredefined1);
+                }
+                relativePath = absPath.substring(predefined.length());
+            }
+        }
+
+        //Variable activeVariable = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context);
+        if (selection == null)
+               return null;
+        
+        Variable v = selection;
+        if (predefined != null)
+               v = getPredefinedVariable(graph, selection, predefined);
+
+        if (v == null)
+            return null;
+
+        Variable property = null;
+        if (relativePath != null){
+               if (relativePath.startsWith("/."))
+                       relativePath = relativePath.substring(1);
+            property = v.browsePossible(graph, relativePath);
+        }
+        else
+            property = v.browsePossible(graph, path);
+        return property;
+    }
+
+}