]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Modelled property tabs for SVG (svg code) and Document (css code) selections. (refs...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 12 Sep 2012 07:27:43 +0000 (07:27 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 12 Sep 2012 07:27:43 +0000 (07:27 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25714 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java

index 56e6f9166e5f91b71ae8e0111cf09fe120374c8c..6576dd3273f37a75a22a757b708f8eb828cfb4c2 100644 (file)
@@ -22,8 +22,9 @@ SYSDYN.ImportedOntologies : PROJ.NamespaceRequirement
     PROJ.RequiresNamespace
         "http://www.simantics.org/Sysdyn-1.1" : L0.URI
         "http://www.simantics.org/Layer0-1.1" : L0.URI
-//        "http://www.simantics.org/Documentation-1.1" : L0.URI // Experimental documentation tool
         "http://www.simantics.org/SelectionView-1.2" : L0.URI
+//        "http://www.simantics.org/Documentation-1.1" : L0.URI // Experimental documentation tool
+//        "http://www.simantics.org/DocumentWorkbench-1.0" : L0.URI // Experimental documentation tool
                 
 SYSDYN.SharedFunctionOntology <T L0.Ontology
 SYSDYN.SharedModuleOntology <T L0.Ontology      
index 754cd3b631dc7858c6e089165d79e48c4afe4307..74eeb77d7ec174f8710f1e2db275550ad72257a2 100644 (file)
@@ -25,12 +25,21 @@ import org.simantics.browsing.ui.swt.ContextMenuInitializer;
 import org.simantics.browsing.ui.swt.DefaultSelectionDataResolver;\r
 import org.simantics.browsing.ui.swt.GraphExplorerFactory;\r
 import org.simantics.browsing.ui.swt.IContextMenuInitializer;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ResourceRead;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.SelectionHints;\r
 import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
 import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
+import org.simantics.ui.selection.AnyResource;\r
+import org.simantics.ui.selection.AnyVariable;\r
+import org.simantics.ui.selection.WorkbenchSelectionContentType;\r
 import org.simantics.ui.workbench.IPropertyPage;\r
 import org.simantics.utils.datastructures.BinaryFunction;\r
 import org.simantics.utils.datastructures.hints.IHintContext;\r
@@ -47,6 +56,61 @@ public class SysdynBrowser extends GraphExplorerView {
 \r
     private BinaryFunction<Object[], GraphExplorer, Object[]> selectionTransformation = new BinaryFunction<Object[], GraphExplorer, Object[]>() {\r
 \r
+        \r
+        /*\r
+        private Key[] KEYS = new Key[] { SelectionHints.KEY_MAIN };\r
+        \r
+        @Override\r
+        public Object[] call(GraphExplorer explorer, Object[] objects) {\r
+            Object[] result = new Object[objects.length];\r
+            for (int i = 0; i < objects.length; i++) {\r
+                SelectionElement context = new SelectionElement(KEYS, objects[i]);\r
+                context.setHint(SelectionHints.KEY_MAIN, objects[i]);\r
+                result[i] = context;\r
+            }\r
+            return result;\r
+        }\r
+        */\r
+        \r
+        class SelectionElement extends AdaptableHintContext {\r
+\r
+            private Variable variable;\r
+            private Resource resource;\r
+            \r
+            public SelectionElement(Variable variable, Resource resource, Key... keys) {\r
+                super(keys);\r
+                this.variable = variable;\r
+                this.resource = resource;\r
+            }\r
+\r
+            @SuppressWarnings("unchecked")\r
+            @Override\r
+            public <T> T getContent(WorkbenchSelectionContentType<T> contentType) {\r
+                if(contentType instanceof AnyResource) return (T)resource;\r
+                else if(contentType instanceof AnyVariable) {\r
+                    AnyVariable type = (AnyVariable)contentType;\r
+                    try {\r
+                        \r
+                        if(variable != null) return (T)variable;\r
+                        \r
+                        if(resource == null) return null;\r
+                        \r
+                        return (T) type.processor.sync(new ResourceRead<Variable>(resource) {\r
+                            @Override\r
+                            public Variable perform(ReadGraph graph) throws DatabaseException {\r
+                                return Variables.getPossibleVariable(graph, resource);\r
+                            }\r
+                            \r
+                        });\r
+                    } catch (DatabaseException e) {\r
+                        Logger.defaultLogError(e);\r
+                    }\r
+                } \r
+                return null;\r
+            }                        \r
+\r
+        }\r
+\r
                @Override\r
                public Object[] call(GraphExplorer explorer, Object[] objects) {\r
                Object[] result = new Object[objects.length];\r
@@ -57,11 +121,12 @@ public class SysdynBrowser extends GraphExplorerView {
                                VariableNode<Variable> vn = (VariableNode<Variable>) ctx.getAdapter(VariableNode.class);\r
                    IHintContext context;\r
                    if(vn != null && vn.getVariable() != null) {\r
-                       context = new AdaptableHintContext(SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY);\r
+                       context = new SelectionElement(vn.getVariable(),vn.data, SelectionHints.KEY_MAIN, SelectionHints.KEY_SELECTION_PROPERTY);\r
                        context.setHint(SelectionHints.KEY_MAIN, new BrowserSelection(objects[i], vn));\r
                        context.setHint(SelectionHints.KEY_SELECTION_PROPERTY, vn.getVariable());\r
                    } else {\r
-                       context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
+                       Object resource = ctx.getAdapter(Resource.class);\r
+                       context = new SelectionElement(null, resource == null ? null : (Resource)resource, SelectionHints.KEY_MAIN);\r
                        context.setHint(SelectionHints.KEY_MAIN, objects[i]);\r
                    }\r
                    result[i] = context;\r
index c866309cb45858561e0fd18de69fc03b93c754cf..0b623ee4130ddb0d21e8db0a8b469f6e7af1ca11 100644 (file)
@@ -60,410 +60,410 @@ import org.simantics.utils.ui.ISelectionUtils;
  */\r
 public class ResourceSelectionProcessor implements SelectionProcessor<Object, ReadGraph>  {\r
 \r
-       private SpecialNodeType sharedFunctionsTestNode;\r
-\r
-       @Override\r
-       public Collection<?> process(Object selection, ReadGraph backend) {\r
-               Collection<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
-               SysdynResource sr = SysdynResource.getInstance(backend);\r
-               DiagramResource dr = DiagramResource.getInstance(backend);\r
-               ModelingResources mr = ModelingResources.getInstance(backend);\r
-               SimulationResource simu = SimulationResource.getInstance(backend);\r
-               JFreeChartResource jfree = JFreeChartResource.getInstance(backend);\r
-\r
-               // Test nodes\r
-               if(sharedFunctionsTestNode == null)\r
-                       sharedFunctionsTestNode = new SpecialNodeType(sr.ModelingBrowseContext_SharedFunctionsFolder, Resource.class);\r
-\r
-               try {\r
-                       // Many elements \r
-                       if (selection instanceof ArrayList<?> && ((ArrayList<?>) selection).size() > 1) {\r
-                               List<Resource> independentVariables = new ArrayList<Resource>();\r
-                               Resource model = null;\r
-                               for(Object o : (ArrayList<?>)selection) {\r
-                                       Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
-                                       if(r != null && backend.isInstanceOf(r, sr.IndependentVariable)) {\r
-                                               if(model == null)\r
-                                                       model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf);\r
-                                               if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf)))\r
-                                                       independentVariables.add(r);\r
-                                       }\r
-                               }\r
-\r
-                               tabs.add(new ComparableTabContributor(\r
-                                               new ArrayIndexesTab(),\r
-                                               1,\r
-                                               independentVariables,\r
-                                               "Indexes"));\r
-\r
-                               return tabs;\r
-                       }\r
-\r
-                       // Single element\r
-                       Variable var = null; \r
-                       WorkbenchSelectionElement wse = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class);\r
-                       if(wse != null) {\r
-                               var = wse.getContent(new AnyVariable(backend));\r
-                               if(var == null) {\r
-                                       var = AdaptionUtils.adaptToSingle(selection, Variable.class);\r
-                                       if(var != null) {\r
-                                               Variable possibleActiveVariable = backend.syncRequest(new PossibleActiveVariableFromVariable(var));\r
-                                               if(possibleActiveVariable != null)\r
-                                                       var = possibleActiveVariable;\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
-                       if(r == null) {\r
-                               // Selection is not directly a resource, try if it is a variable \r
-                               var = AdaptionUtils.adaptToSingle(selection, Variable.class);\r
-                                               r = var.getRepresents(backend);\r
-                       }\r
-\r
-                       if(r == null) {\r
-                               // SharedFunctionsFolder has properties but no adapted resource\r
-                               SharedFunctionsFolder sff = AdaptionUtils.adaptToSingle(selection, SharedFunctionsFolder.class);\r
-                               if (sff != null) {\r
-                                       return Collections.singleton(new ComparableTabContributor(\r
-                                                       new SharedFunctionLibrariesTab(),\r
-                                                       2,\r
-                                                       sff.data,\r
-                                                       "Shared Functions"));\r
-                               }\r
-\r
-                               return Collections.emptyList();\r
-                       }\r
-\r
-                       NodeContext nc = AdaptionUtils.adaptToSingle(selection, NodeContext.class);\r
-                       if(nc != null) {\r
-                               NodeType type = nc.getConstant(NodeType.TYPE);\r
-                               if(type != null && type.equals(sharedFunctionsTestNode)) {\r
-                                       return Collections.singleton(new ComparableTabContributor(\r
-                                                       new SharedFunctionLibrariesTab(),\r
-                                                       2,\r
-                                                       r,\r
-                                                       "Shared Functions"));\r
-                               }\r
-                       }\r
-                       \r
-                       // SVG elements in symbol editor\r
+    private SpecialNodeType sharedFunctionsTestNode;\r
+\r
+    @Override\r
+    public Collection<?> process(Object selection, ReadGraph backend) {\r
+        Collection<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
+        SysdynResource sr = SysdynResource.getInstance(backend);\r
+        DiagramResource dr = DiagramResource.getInstance(backend);\r
+        ModelingResources mr = ModelingResources.getInstance(backend);\r
+        SimulationResource simu = SimulationResource.getInstance(backend);\r
+        JFreeChartResource jfree = JFreeChartResource.getInstance(backend);\r
+\r
+        // Test nodes\r
+        if(sharedFunctionsTestNode == null)\r
+            sharedFunctionsTestNode = new SpecialNodeType(sr.ModelingBrowseContext_SharedFunctionsFolder, Resource.class);\r
+\r
+        try {\r
+            // Many elements \r
+            if (selection instanceof ArrayList<?> && ((ArrayList<?>) selection).size() > 1) {\r
+                List<Resource> independentVariables = new ArrayList<Resource>();\r
+                Resource model = null;\r
+                for(Object o : (ArrayList<?>)selection) {\r
+                    Resource r = AdaptionUtils.adaptToSingle(o, Resource.class);\r
+                    if(r != null && backend.isInstanceOf(r, sr.IndependentVariable)) {\r
+                        if(model == null)\r
+                            model = backend.getSingleObject(r, Layer0.getInstance(backend).PartOf);\r
+                        if(model.equals( backend.getSingleObject(r, Layer0.getInstance(backend).PartOf)))\r
+                            independentVariables.add(r);\r
+                    }\r
+                }\r
+\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ArrayIndexesTab(),\r
+                        1,\r
+                        independentVariables,\r
+                        "Indexes"));\r
+\r
+                return tabs;\r
+            }\r
+\r
+            // Single element\r
+            Variable var = null; \r
+            WorkbenchSelectionElement wse = ISelectionUtils.filterSingleSelection(selection, WorkbenchSelectionElement.class);\r
+            if(wse != null) {\r
+                var = wse.getContent(new AnyVariable(backend));\r
+                if(var == null) {\r
+                    var = AdaptionUtils.adaptToSingle(selection, Variable.class);\r
+                    if(var != null) {\r
+                        Variable possibleActiveVariable = backend.syncRequest(new PossibleActiveVariableFromVariable(var));\r
+                        if(possibleActiveVariable != null)\r
+                            var = possibleActiveVariable;\r
+                    }\r
+                }\r
+            }\r
+\r
+            Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
+            if(r == null) {\r
+                // Selection is not directly a resource, try if it is a variable \r
+                var = AdaptionUtils.adaptToSingle(selection, Variable.class);\r
+                r = var.getRepresents(backend);\r
+            }\r
+\r
+            if(r == null) {\r
+                // SharedFunctionsFolder has properties but no adapted resource\r
+                SharedFunctionsFolder sff = AdaptionUtils.adaptToSingle(selection, SharedFunctionsFolder.class);\r
+                if (sff != null) {\r
+                    return Collections.singleton(new ComparableTabContributor(\r
+                            new SharedFunctionLibrariesTab(),\r
+                            2,\r
+                            sff.data,\r
+                            "Shared Functions"));\r
+                }\r
+\r
+                return Collections.emptyList();\r
+            }\r
+\r
+            NodeContext nc = AdaptionUtils.adaptToSingle(selection, NodeContext.class);\r
+            if(nc != null) {\r
+                NodeType type = nc.getConstant(NodeType.TYPE);\r
+                if(type != null && type.equals(sharedFunctionsTestNode)) {\r
+                    return Collections.singleton(new ComparableTabContributor(\r
+                            new SharedFunctionLibrariesTab(),\r
+                            2,\r
+                            r,\r
+                            "Shared Functions"));\r
+                }\r
+            }\r
+\r
+            // SVG elements in symbol editor\r
             if (backend.isInstanceOf(r, dr.SVGElement))\r
                 return Collections.singleton(SVGElementComposite.make(r, 1, "SVG"));\r
 \r
-                       // if r == diagram element, change it to component\r
-                                       if (backend.isInstanceOf(r, dr.Element)) {\r
-                                               Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
-                                               if (component != null) {\r
-                                                       r = component;\r
-                                               } else {\r
-                                                       Resource connection = backend.getPossibleObject(r, mr.DiagramConnectionToConnection);\r
-                                                       if(connection != null)\r
-                                                               r = connection;\r
-                                               }\r
-                                       }\r
-\r
-                                       // Independent variable\r
-                                       if (backend.isInstanceOf(r, sr.IndependentVariable)) {\r
-                                               Resource activeExpression = backend.getPossibleObject(r, sr.IndependentVariable_activeExpression);\r
-                                               Resource expression = null;\r
-                                               if(activeExpression != null)\r
-                                                       // if variable has active expression, display it\r
-                                                       expression = activeExpression;\r
-                                               else if (backend.hasStatement(r, sr.Variable_expressions)){\r
-                                                       // else display the first expression of the variable\r
-                                                       Resource expressions = backend.getPossibleObject(r, sr.Variable_expressions);\r
-                                                       List<Resource> expressionList = OrderedSetUtils.toList(backend, expressions);\r
-                                                       if(expressionList.isEmpty()) {\r
-                                                               System.err.println("expressionList is empty for " + r);\r
-                                                               return Collections.emptyList();\r
-                                                       }\r
-                                                       expression = expressionList.get(0);\r
-                                               }\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new EquationTab(),\r
-                                                               3,\r
-                                                               var != null ? var : r,\r
-                                                               "Equation"));\r
-                                               if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) {\r
-                                                       // WithLookupExpression has its own extra tab for visual configuration\r
-                                                       tabs.add(new ComparableTabContributor(\r
-                                                                       new LookupTableTab(),\r
-                                                                       2,\r
-                                                                       expression,\r
-                                                                       "Lookup Table"));\r
-                                               }\r
-\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new ArrayIndexesTab(),\r
-                                                               1,\r
-                                                               r,\r
-                                                               "Indexes"));\r
-\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new VariableInformationTab(),\r
-                                                               0,\r
-                                                               r,\r
-                                                               "Additional Information"));\r
-                                               return tabs;\r
-                                       }\r
-\r
-                                       // Input variable\r
-                                       if (backend.isInstanceOf(r, sr.Input)) {\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new InputVariableTab(),\r
-                                                               2,\r
-                                                               r,\r
-                                                               "Input"));\r
-\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new ArrayIndexesTab(),\r
-                                                               1,\r
-                                                               r,\r
-                                                               "Indexes"));\r
-\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new VariableInformationTab(),\r
-                                                               0,\r
-                                                               r,\r
-                                                               "Additional Information"));\r
-                                               return tabs;\r
-                                       }\r
-\r
-                                       // Enumeration\r
-                                       if (backend.isInstanceOf(r, sr.Enumeration)) {\r
-                                               Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class);\r
-                                               if(s == null)\r
-                                                       s = r;\r
-                                               // give either variable or the actual resource\r
-                                               return Collections.singleton(new ComparableTabContributor(\r
-                                                               new EnumerationTab(),\r
-                                                               2,\r
-                                                               s,\r
-                                                               "Enumeration"));\r
-                                       }\r
-\r
-                                       // Configuration and model. They both show the properties of the configuration\r
-                                       if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
-                                               if(!backend.isInstanceOf(r, sr.SysdynModel))\r
-                                                       r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf);\r
-                                               if (r != null)\r
-                                                       return Collections.singleton(\r
-                                                                       new ComparableTabContributor(\r
-                                                                                       new ConfigurationTab(),\r
-                                                                                       0,\r
-                                                                                       r,\r
-                                                                                       "Model Properties"));\r
-                                       }\r
-\r
-                                       // Module\r
-                                       if (backend.isInstanceOf(r, sr.Module)){\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new ModuleTab(),\r
-                                                               10,\r
-                                                               r,\r
-                                                               "Module Properties"));\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new ModuleParameterTab(),\r
-                                                               9,\r
-                                                               r,\r
-                                                               "Parameters"));\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new ModuleInputTab(),\r
-                                                               2,\r
-                                                               r,\r
-                                                               "Inputs"));\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new ModuleOutputTab(),\r
-                                                               1,\r
-                                                               r,\r
-                                                               "Outputs"));\r
-                                               return tabs;\r
-                                       }\r
-\r
-                                       // Playback experiment\r
-                                       if (backend.isInstanceOf(r, sr.PlaybackExperiment))\r
-                                               return Collections.singleton(\r
-                                                               new ComparableTabContributor(\r
-                                                                               new PlaybackExperimentTab(),\r
-                                                                               0,\r
-                                                                               r,\r
-                                                                               "Experiment Properties"));\r
-                                       \r
-                                       // Game experiment\r
-                                       if (backend.isInstanceOf(r, sr.GameExperiment))\r
-                                               return Collections.singleton(\r
-                                                               new ComparableTabContributor(\r
-                                                                               new GameExperimentTab(),\r
-                                                                               0,\r
-                                                                               r,\r
-                                                                               "Experiment Properties"));\r
-                                       \r
-                                       // Default experiment\r
-                                       if (backend.isInstanceOf(r, simu.Experiment))\r
-                                               return Collections.singleton(\r
-                                                               new ComparableTabContributor(\r
-                                                                               new ExperimentTab(),\r
-                                                                               0,\r
-                                                                               r,\r
-                                                                               "Experiment Properties"));\r
-\r
-                                       // History data\r
-                                       if (backend.isInstanceOf(r, sr.HistoryDataset))\r
-                                               return Collections.singleton(\r
-                                                               new ComparableTabContributor(\r
-                                                                               new HistoryDataTab(),\r
-                                                                               0,\r
-                                                                               r,\r
-                                                                               "History Data Properties"));\r
-\r
-                                       // Saved simulation result\r
-                                       if (backend.isInstanceOf(r, sr.Result))\r
-                                               return Collections.singleton(\r
-                                                               new ComparableTabContributor(\r
-                                                                               new ResultTab(),\r
-                                                                               0,\r
-                                                                               r,\r
-                                                                               "Result Properties"));\r
-\r
-                                       // Dependency\r
-                                       if (backend.isInstanceOf(r, sr.Dependency))\r
-                                               if (backend.hasStatement(r, sr.Dependency_refersTo))\r
-                                                       return Collections.singleton(\r
-                                                                       new ComparableTabContributor(\r
-                                                                                       new ReferenceDependencyTab(),\r
-                                                                                       0,\r
-                                                                                       r,\r
-                                                                                       "Reference Properties"));\r
-                                               else {\r
-                                                       Resource diaConnection = backend.getPossibleObject(r, ModelingResources.getInstance(backend).ConnectionToDiagramConnection);\r
-                                                       return Collections.singleton(\r
-                                                                       new ComparableTabContributor(\r
-                                                                                       new DependencyTab(),\r
-                                                                                       0,\r
-                                                                                       diaConnection,\r
-                                                                                       "Dependency Properties"));\r
-                                               }\r
-\r
-                                       // Module symbol. Modules in modules-folder are actually symbol resources\r
-                                       if (backend.isInheritedFrom(r, sr.ModuleSymbol)) {\r
-                                               // Find the component resource\r
-                                               r =  backend.getPossibleObject(r, mr.SymbolToComponentType);\r
-                                               if(r != null)\r
-                                                       return Collections.singleton(\r
-                                                                       new ComparableTabContributor(\r
-                                                                                       new ModuleTypeTab(),\r
-                                                                                       0,\r
-                                                                                       r,\r
-                                                                                       "Module Type Properties"));\r
-                                       }\r
-\r
-                                       // Function\r
-                                       if (backend.isInstanceOf(r, sr.SysdynModelicaFunction)) {\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new FunctionTab(),\r
-                                                               2,\r
-                                                               r,\r
-                                                               "Function"));\r
-                                               tabs.add(new ComparableTabContributor(\r
-                                                               new ExternalFilesTab(),\r
-                                                               1,\r
-                                                               r,\r
-                                                               "External files"));\r
-                                               return tabs;\r
-                                       }\r
-\r
-                                       // Function library\r
-                                       if (backend.isInstanceOf(r, sr.SysdynModelicaFunctionLibrary)) {\r
-                                               Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class);\r
-                                               if(s == null)\r
-                                                       s = r;\r
-                                               // give either variable or the actual resource\r
-                                               return Collections.singleton(new ComparableTabContributor(\r
-                                                               new FunctionLibraryTab(),\r
-                                                               2,\r
-                                                               s,\r
-                                                               "Function library"));\r
-                                       }\r
-\r
-                                       // Chart Element\r
-                                       if(backend.isInstanceOf(r, jfree.ChartElement)) {\r
-                                               if(backend.hasStatement(r, jfree.ChartElement_component))\r
-                                                       r = backend.getSingleObject(r, jfree.ChartElement_component);\r
-                                       }\r
-                                       // Chart\r
-                                       if (backend.isInstanceOf(r, jfree.Chart)) {\r
-\r
-                                               Collection<Resource> plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot));\r
-                                               if(!plots.isEmpty()) {\r
-                                                       Resource plot = plots.iterator().next();\r
-\r
-                                                       if(backend.isInstanceOf(plot, jfree.XYPlot)) {\r
-                                                               tabs.add(new ComparableTabContributor(\r
-                                                                               new XYLineGeneralPropertiesTab(),\r
-                                                                               10,\r
-                                                                               r,\r
-                                                                               "General"));\r
-                                                               tabs.add(new ComparableTabContributor(\r
-                                                                               new XYLineAxisAndVariablesTab(),\r
-                                                                               9,\r
-                                                                               r,\r
-                                                                               "Axis and Variables"));\r
-                                                       } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
-                                                               tabs.add(new ComparableTabContributor(\r
-                                                                               new BarGeneralPropertiesTab(),\r
-                                                                               10,\r
-                                                                               r,\r
-                                                                               "General"));\r
-                                                               tabs.add(new ComparableTabContributor(\r
-                                                                               new BarSeriesTab(),\r
-                                                                               9,\r
-                                                                               r,\r
-                                                                               "Variables"));\r
-                                                               tabs.add(new ComparableTabContributor(\r
-                                                                               new BarAxisTab(),\r
-                                                                               8,\r
-                                                                               r,\r
-                                                                               "Axis"));                        \r
-                                                       } else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
-                                                               tabs.add(new ComparableTabContributor(\r
-                                                                               new PieGeneralPropertiesTab(),\r
-                                                                               10,\r
-                                                                               r,\r
-                                                                               "General"));\r
-                                                               tabs.add(new ComparableTabContributor(\r
-                                                                               new PieSeriesTab(),\r
-                                                                               9,\r
-                                                                               r,\r
-                                                                               "Variables"));\r
-                                                       }\r
-\r
-                                                       tabs.add(new ComparableTabContributor(\r
-                                                                       new ChartTab(),\r
-                                                                       1,\r
-                                                                       r,\r
-                                                                       "Chart"));\r
-                                                       return tabs;\r
-\r
-                                               \r
-                                       }\r
-\r
-                                       // Default experiment\r
-                                       if (backend.isInstanceOf(r, sr.AdditionalSymbols_MultilineText))\r
-                                               return Collections.singleton(\r
-                                                               new ComparableTabContributor(\r
-                                                                               new CommentTab(),\r
-                                                                               0,\r
-                                                                               r,\r
-                                                                               "Comment"));\r
-\r
-               } catch (ServiceException e) {\r
-                       e.printStackTrace();\r
-               } catch (ManyObjectsForFunctionalRelationException e) {\r
-                       e.printStackTrace();\r
-               } catch (DatabaseException e) {\r
-                       e.printStackTrace();\r
-               }\r
-               return Collections.emptyList();\r
-       }\r
+            // if r == diagram element, change it to component\r
+            if (backend.isInstanceOf(r, dr.Element)) {\r
+                Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
+                if (component != null) {\r
+                    r = component;\r
+                } else {\r
+                    Resource connection = backend.getPossibleObject(r, mr.DiagramConnectionToConnection);\r
+                    if(connection != null)\r
+                        r = connection;\r
+                }\r
+            }\r
+\r
+            // Independent variable\r
+            if (backend.isInstanceOf(r, sr.IndependentVariable)) {\r
+                Resource activeExpression = backend.getPossibleObject(r, sr.IndependentVariable_activeExpression);\r
+                Resource expression = null;\r
+                if(activeExpression != null)\r
+                    // if variable has active expression, display it\r
+                    expression = activeExpression;\r
+                else if (backend.hasStatement(r, sr.Variable_expressions)){\r
+                    // else display the first expression of the variable\r
+                    Resource expressions = backend.getPossibleObject(r, sr.Variable_expressions);\r
+                    List<Resource> expressionList = OrderedSetUtils.toList(backend, expressions);\r
+                    if(expressionList.isEmpty()) {\r
+                        System.err.println("expressionList is empty for " + r);\r
+                        return Collections.emptyList();\r
+                    }\r
+                    expression = expressionList.get(0);\r
+                }\r
+                tabs.add(new ComparableTabContributor(\r
+                        new EquationTab(),\r
+                        3,\r
+                        var != null ? var : r,\r
+                        "Equation"));\r
+                if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) {\r
+                    // WithLookupExpression has its own extra tab for visual configuration\r
+                    tabs.add(new ComparableTabContributor(\r
+                            new LookupTableTab(),\r
+                            2,\r
+                            expression,\r
+                            "Lookup Table"));\r
+                }\r
+\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ArrayIndexesTab(),\r
+                        1,\r
+                        r,\r
+                        "Indexes"));\r
+\r
+                tabs.add(new ComparableTabContributor(\r
+                        new VariableInformationTab(),\r
+                        0,\r
+                        r,\r
+                        "Additional Information"));\r
+                return tabs;\r
+            }\r
+\r
+            // Input variable\r
+            if (backend.isInstanceOf(r, sr.Input)) {\r
+                tabs.add(new ComparableTabContributor(\r
+                        new InputVariableTab(),\r
+                        2,\r
+                        r,\r
+                        "Input"));\r
+\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ArrayIndexesTab(),\r
+                        1,\r
+                        r,\r
+                        "Indexes"));\r
+\r
+                tabs.add(new ComparableTabContributor(\r
+                        new VariableInformationTab(),\r
+                        0,\r
+                        r,\r
+                        "Additional Information"));\r
+                return tabs;\r
+            }\r
+\r
+            // Enumeration\r
+            if (backend.isInstanceOf(r, sr.Enumeration)) {\r
+                Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class);\r
+                if(s == null)\r
+                    s = r;\r
+                // give either variable or the actual resource\r
+                return Collections.singleton(new ComparableTabContributor(\r
+                        new EnumerationTab(),\r
+                        2,\r
+                        s,\r
+                        "Enumeration"));\r
+            }\r
+\r
+            // Configuration and model. They both show the properties of the configuration\r
+            if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
+                if(!backend.isInstanceOf(r, sr.SysdynModel))\r
+                    r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf);\r
+                if (r != null)\r
+                    return Collections.singleton(\r
+                            new ComparableTabContributor(\r
+                                    new ConfigurationTab(),\r
+                                    0,\r
+                                    r,\r
+                                    "Model Properties"));\r
+            }\r
+\r
+            // Module\r
+            if (backend.isInstanceOf(r, sr.Module)){\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ModuleTab(),\r
+                        10,\r
+                        r,\r
+                        "Module Properties"));\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ModuleParameterTab(),\r
+                        9,\r
+                        r,\r
+                        "Parameters"));\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ModuleInputTab(),\r
+                        2,\r
+                        r,\r
+                        "Inputs"));\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ModuleOutputTab(),\r
+                        1,\r
+                        r,\r
+                        "Outputs"));\r
+                return tabs;\r
+            }\r
+\r
+            // Playback experiment\r
+            if (backend.isInstanceOf(r, sr.PlaybackExperiment))\r
+                return Collections.singleton(\r
+                        new ComparableTabContributor(\r
+                                new PlaybackExperimentTab(),\r
+                                0,\r
+                                r,\r
+                                "Experiment Properties"));\r
+\r
+            // Game experiment\r
+            if (backend.isInstanceOf(r, sr.GameExperiment))\r
+                return Collections.singleton(\r
+                        new ComparableTabContributor(\r
+                                new GameExperimentTab(),\r
+                                0,\r
+                                r,\r
+                                "Experiment Properties"));\r
+\r
+            // Default experiment\r
+            if (backend.isInstanceOf(r, simu.Experiment))\r
+                return Collections.singleton(\r
+                        new ComparableTabContributor(\r
+                                new ExperimentTab(),\r
+                                0,\r
+                                r,\r
+                                "Experiment Properties"));\r
+\r
+            // History data\r
+            if (backend.isInstanceOf(r, sr.HistoryDataset))\r
+                return Collections.singleton(\r
+                        new ComparableTabContributor(\r
+                                new HistoryDataTab(),\r
+                                0,\r
+                                r,\r
+                                "History Data Properties"));\r
+\r
+            // Saved simulation result\r
+            if (backend.isInstanceOf(r, sr.Result))\r
+                return Collections.singleton(\r
+                        new ComparableTabContributor(\r
+                                new ResultTab(),\r
+                                0,\r
+                                r,\r
+                                "Result Properties"));\r
+\r
+            // Dependency\r
+            if (backend.isInstanceOf(r, sr.Dependency))\r
+                if (backend.hasStatement(r, sr.Dependency_refersTo))\r
+                    return Collections.singleton(\r
+                            new ComparableTabContributor(\r
+                                    new ReferenceDependencyTab(),\r
+                                    0,\r
+                                    r,\r
+                                    "Reference Properties"));\r
+                else {\r
+                    Resource diaConnection = backend.getPossibleObject(r, ModelingResources.getInstance(backend).ConnectionToDiagramConnection);\r
+                    return Collections.singleton(\r
+                            new ComparableTabContributor(\r
+                                    new DependencyTab(),\r
+                                    0,\r
+                                    diaConnection,\r
+                                    "Dependency Properties"));\r
+                }\r
+\r
+            // Module symbol. Modules in modules-folder are actually symbol resources\r
+            if (backend.isInheritedFrom(r, sr.ModuleSymbol)) {\r
+                // Find the component resource\r
+                r =  backend.getPossibleObject(r, mr.SymbolToComponentType);\r
+                if(r != null)\r
+                    return Collections.singleton(\r
+                            new ComparableTabContributor(\r
+                                    new ModuleTypeTab(),\r
+                                    0,\r
+                                    r,\r
+                                    "Module Type Properties"));\r
+            }\r
+\r
+            // Function\r
+            if (backend.isInstanceOf(r, sr.SysdynModelicaFunction)) {\r
+                tabs.add(new ComparableTabContributor(\r
+                        new FunctionTab(),\r
+                        2,\r
+                        r,\r
+                        "Function"));\r
+                tabs.add(new ComparableTabContributor(\r
+                        new ExternalFilesTab(),\r
+                        1,\r
+                        r,\r
+                        "External files"));\r
+                return tabs;\r
+            }\r
+\r
+            // Function library\r
+            if (backend.isInstanceOf(r, sr.SysdynModelicaFunctionLibrary)) {\r
+                Object s = AdaptionUtils.adaptToSingle(selection, ISelection.class);\r
+                if(s == null)\r
+                    s = r;\r
+                // give either variable or the actual resource\r
+                return Collections.singleton(new ComparableTabContributor(\r
+                        new FunctionLibraryTab(),\r
+                        2,\r
+                        s,\r
+                        "Function library"));\r
+            }\r
+\r
+            // Chart Element\r
+            if(backend.isInstanceOf(r, jfree.ChartElement)) {\r
+                if(backend.hasStatement(r, jfree.ChartElement_component))\r
+                    r = backend.getSingleObject(r, jfree.ChartElement_component);\r
+            }\r
+            // Chart\r
+            if (backend.isInstanceOf(r, jfree.Chart)) {\r
+\r
+                Collection<Resource> plots = backend.syncRequest(new ObjectsWithType(r, Layer0.getInstance(backend).ConsistsOf, jfree.Plot));\r
+                if(!plots.isEmpty()) {\r
+                    Resource plot = plots.iterator().next();\r
+\r
+                    if(backend.isInstanceOf(plot, jfree.XYPlot)) {\r
+                        tabs.add(new ComparableTabContributor(\r
+                                new XYLineGeneralPropertiesTab(),\r
+                                10,\r
+                                r,\r
+                                "General"));\r
+                        tabs.add(new ComparableTabContributor(\r
+                                new XYLineAxisAndVariablesTab(),\r
+                                9,\r
+                                r,\r
+                                "Axis and Variables"));\r
+                    } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
+                        tabs.add(new ComparableTabContributor(\r
+                                new BarGeneralPropertiesTab(),\r
+                                10,\r
+                                r,\r
+                                "General"));\r
+                        tabs.add(new ComparableTabContributor(\r
+                                new BarSeriesTab(),\r
+                                9,\r
+                                r,\r
+                                "Variables"));\r
+                        tabs.add(new ComparableTabContributor(\r
+                                new BarAxisTab(),\r
+                                8,\r
+                                r,\r
+                                "Axis"));                        \r
+                    } else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
+                        tabs.add(new ComparableTabContributor(\r
+                                new PieGeneralPropertiesTab(),\r
+                                10,\r
+                                r,\r
+                                "General"));\r
+                        tabs.add(new ComparableTabContributor(\r
+                                new PieSeriesTab(),\r
+                                9,\r
+                                r,\r
+                                "Variables"));\r
+                    }\r
+\r
+                    tabs.add(new ComparableTabContributor(\r
+                            new ChartTab(),\r
+                            1,\r
+                            r,\r
+                            "Chart"));\r
+                    return tabs;\r
+\r
+                } \r
+            }\r
+\r
+            // Default experiment\r
+            if (backend.isInstanceOf(r, sr.AdditionalSymbols_MultilineText))\r
+                return Collections.singleton(\r
+                        new ComparableTabContributor(\r
+                                new CommentTab(),\r
+                                0,\r
+                                r,\r
+                                "Comment"));\r
+\r
+        } catch (ServiceException e) {\r
+            e.printStackTrace();\r
+        } catch (ManyObjectsForFunctionalRelationException e) {\r
+            e.printStackTrace();\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+        return Collections.emptyList();\r
+    }\r
 }\r