]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Look for variable from diagram elements in sysdyn ResourceSelectionProcessor.
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Sun, 20 Jun 2010 10:13:44 +0000 (10:13 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Sun, 20 Jun 2010 10:13:44 +0000 (10:13 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16246 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java

index 86cfbf610a0e87cba8987f25928028885b8f9649..52404a86d61207d99e0d044b612a73ef0a7fae6a 100644 (file)
@@ -9,19 +9,31 @@ import org.simantics.browsing.ui.SelectionProcessor;
 import org.simantics.browsing.ui.swt.ComparableTabContributor;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
 import org.simantics.db.exception.ServiceException;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
 \r
 public class ResourceSelectionProcessor implements SelectionProcessor<ISelection, ReadGraph>  {\r
-    \r
+\r
     @Override\r
     public Collection<?> process(ISelection selection, ReadGraph backend) {\r
         Resource r = AdaptionUtils.adaptToSingle(selection, Resource.class);\r
-        if(r != null)\r
+        if(r == null)\r
+            return Collections.emptyList();\r
+\r
         try {\r
             SysdynResource sr = SysdynResource.getInstance(backend);\r
+            DiagramResource dr = DiagramResource.getInstance(backend);\r
+            ModelingResources mr = ModelingResources.getInstance(backend);\r
             Collection<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
+            if (backend.isInstanceOf(r, dr.Element)) {\r
+                Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
+                if (component != null)\r
+                    r = component;\r
+            }\r
             if (backend.isInstanceOf(r, sr.IndependentVariable)) {\r
                 tabs.add(new ComparableTabContributor(\r
                         new EquationTab(),\r
@@ -32,39 +44,41 @@ public class ResourceSelectionProcessor implements SelectionProcessor<ISelection
                         new VariableInformationTab(),\r
                         1,\r
                         r,\r
-                        "Additional Information"));                \r
+                "Additional Information"));\r
                 return tabs;\r
             }\r
             if (backend.isInstanceOf(r, sr.Configuration))\r
                 return Collections.singleton(\r
                         new ComparableTabContributor(\r
-                            new ConfigurationTab(),\r
-                            0,\r
-                            r,\r
-                            "Configuration Properties"));\r
+                                new ConfigurationTab(),\r
+                                0,\r
+                                r,\r
+                        "Configuration Properties"));\r
             if (backend.isInstanceOf(r, sr.Experiment))\r
                 return Collections.singleton(\r
                         new ComparableTabContributor(\r
-                            new ExperimentTab(),\r
-                            0,\r
-                            r,\r
-                            "Experiment Properties"));\r
+                                new ExperimentTab(),\r
+                                0,\r
+                                r,\r
+                        "Experiment Properties"));\r
             if (backend.isInstanceOf(r, sr.SysdynModel))\r
                 return Collections.singleton(\r
                         new ComparableTabContributor(\r
-                            new ModelTab(),\r
-                            0,\r
-                            r,\r
-                            "Model Properties"));\r
+                                new ModelTab(),\r
+                                0,\r
+                                r,\r
+                        "Model Properties"));\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
+                                new ResultTab(),\r
+                                0,\r
+                                r,\r
+                        "Result Properties"));\r
         } catch (ServiceException e) {\r
             e.printStackTrace();\r
+        } catch (ManyObjectsForFunctionalRelationException e) {\r
+            e.printStackTrace();\r
         }\r
         return Collections.emptyList();\r
     }\r