]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Wrong query id caused query cache to store model variables separately for each variable
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 4 Feb 2014 14:47:14 +0000 (14:47 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 4 Feb 2014 14:47:14 +0000 (14:47 +0000)
Dispose methods for clearing local caches.

fixes #4694

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28771 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AllVariablesOfModel.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/StringChooser.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableExistsValidator.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/VariableProposalProvider.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesPropertyComposite2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesPropertyComposite2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab2.java

index f64435beda30edcc92d50c4f175b1fff215c7fd7..f3fcd7dd794b6e9172e8f97c067723014aa1eb3e 100644 (file)
@@ -6,22 +6,52 @@ import java.util.Collections;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
 \r
 public class AllVariablesOfModel implements Read<Collection<ChartVariable>> {\r
        \r
-       public Resource res;\r
+       public Resource model;\r
        \r
+       /**\r
+        * Queries all variables of a model \r
+        * @param res the model.\r
+        */\r
        public AllVariablesOfModel(Resource res) {\r
-               this.res = res;\r
+               this.model = res;\r
+       }\r
+       \r
+       public Resource getModel() {\r
+               return model;\r
        }\r
        \r
        @Override\r
        public Collection<ChartVariable> perform(ReadGraph graph) throws DatabaseException {\r
-               if(!graph.hasStatement(res))\r
+               if(!graph.hasStatement(model))\r
                 return Collections.emptyList();\r
-               IAllVariablesOfModel query = graph.adapt(res, IAllVariablesOfModel.class);\r
+               IAllVariablesOfModel query = graph.adapt(model, IAllVariablesOfModel.class);\r
                return graph.syncRequest(query.getVariablesQuery());\r
        }\r
+       \r
+       public static AllVariablesOfModel withRandomResource(ISessionContext context, final Resource resource) throws DatabaseException {\r
+               Resource model  = context.getSession().syncRequest(new Read<Resource>() {\r
+\r
+               @Override\r
+               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+                   Resource r = resource;\r
+                   while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) {\r
+                       if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model))\r
+                           return r;\r
+                   }\r
+                   return null;\r
+               }\r
+               \r
+           });\r
+               if (model == null)\r
+                       return null;\r
+               return new AllVariablesOfModel(model);\r
+       }\r
 \r
 }\r
index 892e99862ecf6330953f8df8c01744bffba2c6e2..ce1b351bb115727cf82fc7860256f4e24f2bb95c 100644 (file)
@@ -8,7 +8,6 @@ import java.util.Set;
 \r
 import org.eclipse.core.runtime.Assert;\r
 import org.eclipse.core.runtime.ListenerList;\r
-import org.eclipse.jface.dialogs.IInputValidator;\r
 import org.eclipse.jface.resource.JFaceResources;\r
 import org.eclipse.jface.resource.LocalResourceManager;\r
 import org.eclipse.jface.resource.ResourceManager;\r
@@ -31,7 +30,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Text;\r
 import org.simantics.browsing.ui.swt.widgets.DefaultColorProvider;\r
 import org.simantics.browsing.ui.swt.widgets.impl.ITrackedColorProvider;\r
-\r
 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory;\r
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
@@ -253,7 +251,8 @@ public class StringChooser<T> implements Widget{
         state |= EDITING | MOUSE_DOWN_FIRST_TIME;\r
     }\r
 \r
-    private void applyEdit() {\r
+    @SuppressWarnings("unchecked")\r
+       private void applyEdit() {\r
         try {\r
             if (isTextValid() != null) {\r
                 text.setText(textBeforeEdit);\r
@@ -261,9 +260,9 @@ public class StringChooser<T> implements Widget{
                setSelected(text.getText());\r
                 //System.out.println("apply");\r
                 if (modifyListeners != null) {\r
-                    StringChooserModifyEvent event = new StringChooserModifyEvent(text, selected, text.getText());\r
+                    StringChooserModifyEvent<T> event = new StringChooserModifyEvent<T>(text, selected, text.getText());\r
                     for (Object o : modifyListeners.getListeners()) {\r
-                        ((StringChooserModifyListener) o).modifySelection(event);\r
+                        ((StringChooserModifyListener<T>) o).modifySelection(event);\r
                     }\r
                 }\r
             }\r
@@ -360,14 +359,14 @@ public class StringChooser<T> implements Widget{
         return text;\r
     }\r
 \r
-    public synchronized void addModifyListener(StringChooserModifyListener listener) {\r
+       public synchronized void addModifyListener(StringChooserModifyListener<T> listener) {\r
         if (modifyListeners == null) {\r
             modifyListeners = new ListenerList(ListenerList.IDENTITY);\r
         }\r
         modifyListeners.add(listener);\r
     }\r
 \r
-    public synchronized void removeModifyListener(StringChooserModifyListener listener) {\r
+       public synchronized void removeModifyListener(StringChooserModifyListener<T> listener) {\r
         if (modifyListeners == null)\r
             return;\r
         modifyListeners.remove(listener);\r
@@ -587,4 +586,15 @@ public class StringChooser<T> implements Widget{
             }\r
         }\r
     }\r
+    \r
+    public void dispose() {\r
+       allowedLabels.clear();\r
+       allowedLabels = null;\r
+       objectFactory = null;\r
+       objectToLabel.clear();\r
+       objectToLabel = null;\r
+       \r
+    }\r
+    \r
+    \r
 }\r
index e8c8e03ba0e208153a75e4e86aaf076eb137405e..32abe9e6748d04e8c7bb20509d7a5e21e9d902cc 100644 (file)
@@ -7,14 +7,10 @@ import org.eclipse.jface.dialogs.IInputValidator;
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.AdaptionUtils;\r
 \r
@@ -97,28 +93,15 @@ public class VariableExistsValidator implements IInputValidator, Widget {
             return;\r
         }\r
         \r
-        Resource model = null;\r
+       \r
         try {\r
             /* Find the model resource. It can be found with PartOf \r
                relations from series resource in a chart */\r
-            model  = context.getSession().syncRequest(new Read<Resource>() {\r
-\r
-                @Override\r
-                public Resource perform(ReadGraph graph) throws DatabaseException {\r
-                    Resource r = resource;\r
-                    while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) {\r
-                        if(graph.isInstanceOf(r, SimulationResource.getInstance(graph).Model))\r
-                            return r;\r
-                    }\r
-                    return null;\r
-                }\r
-                \r
-            });\r
+           AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
             \r
-            if(model != null) {\r
+            if(query != null) {\r
                 // Find all variables and set them as the reference for isValid(String)\r
-                SimanticsUI.getSession().asyncRequest(\r
-                        new AllVariablesOfModel(model)\r
+                SimanticsUI.getSession().asyncRequest(query\r
                 , new Listener<Collection<ChartVariable>>() {\r
 \r
                     @Override\r
index c32297479c334dc58d853d3b8ae02bf05383a5e4..da399f6b6dc588ebf76acd34d813e09f43f31482 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Control;
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.ui.SimanticsUI;\r
@@ -156,29 +157,37 @@ public class VariableProposalProvider implements IContentProposalProvider, Widge
         if(resource == null)\r
             return;\r
         this.resource = resource;\r
+        /* Find the model resource. It can be found with PartOf \r
+        relations from series resource in a chart */\r
+       try {\r
+               AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
+                SimanticsUI.getSession().asyncRequest(query\r
+               , new Listener<Collection<ChartVariable>>() {\r
+\r
+                   @Override\r
+                   public void execute(Collection<ChartVariable> result) {\r
+                       setProposals(result);\r
+                   }\r
+\r
+                   @Override\r
+                   public void exception(Throwable t) {\r
+                       t.printStackTrace();\r
+                   }\r
+\r
+                   @Override\r
+                   public boolean isDisposed() {\r
+                       return control == null || \r
+                               control.isDisposed() || \r
+                               !resource.equals(VariableProposalProvider.this.resource);\r
+                   }\r
+\r
+               }); \r
+       } catch (DatabaseException e) {\r
+               // TODO Auto-generated catch block\r
+               e.printStackTrace();\r
+       }\r
         \r
-        SimanticsUI.getSession().asyncRequest(\r
-                new AllVariablesOfModel(resource)\r
-        , new Listener<Collection<ChartVariable>>() {\r
-\r
-            @Override\r
-            public void execute(Collection<ChartVariable> result) {\r
-                setProposals(result);\r
-            }\r
-\r
-            @Override\r
-            public void exception(Throwable t) {\r
-                t.printStackTrace();\r
-            }\r
-\r
-            @Override\r
-            public boolean isDisposed() {\r
-                return control == null || \r
-                        control.isDisposed() || \r
-                        !resource.equals(VariableProposalProvider.this.resource);\r
-            }\r
-\r
-        }); \r
+       \r
         \r
     }\r
     \r
index 9cb7fdc2d0912ab6b8788be2c87ee005e28fb1bf..a9a1d48d99a4b40073b0b8ba511b716533e0cf7d 100644 (file)
@@ -114,4 +114,11 @@ public class BarSeriesPropertyComposite2 extends Composite {
                GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
         }\r
     }\r
+    \r
+    @Override\r
+    public void dispose() {\r
+       variable.dispose();\r
+       variable = null;\r
+       super.dispose();\r
+    }\r
 }\r
index 0f6d81f2a29c751edc53279361056ed2ba9e5b5e..24076dda6460b6f7387937744ac1845aecf30de9 100644 (file)
@@ -132,7 +132,8 @@ public class BarSeriesTab2 extends LabelPropertyTabContributor implements Widget
         }\r
         \r
         try {\r
-               Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+               AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
+               Collection<ChartVariable> variables = context.getSession().syncRequest(query);\r
                \r
                spc = new BarSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, options, SWT.NONE);\r
        \r
index 181f78ca73d2d024c4078aef987bb3e4244a7cb1..3f3c4aff246e362ecaf4b04709f118dc1ddb6b35 100644 (file)
@@ -125,5 +125,12 @@ public class PieSeriesPropertyComposite2 extends Composite {
         exploded.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Series_exploded));\r
         GridDataFactory.fillDefaults().applyTo(exploded.getWidget());\r
     }\r
+    \r
+    @Override\r
+    public void dispose() {\r
+       variable.dispose();\r
+       variable = null;\r
+       super.dispose();\r
+    }\r
 \r
 }\r
index 42076996f5bc47227aa83965a3ca939128b91b5b..7103b6f8a2ffaf52dba7a57bf0aaf5d257ec217a 100644 (file)
@@ -131,7 +131,8 @@ public class PieSeriesTab2 extends LabelPropertyTabContributor implements Widget
         }\r
 \r
         try {\r
-               Collection<ChartVariable> variables = context.getSession().syncRequest(new AllVariablesOfModel(resource));\r
+               AllVariablesOfModel query = AllVariablesOfModel.withRandomResource(context, resource);\r
+               Collection<ChartVariable> variables = context.getSession().syncRequest(query);\r
                PieSeriesPropertyComposite2 spc = new PieSeriesPropertyComposite2(propertyContainer, context, additionalSupport, variables, options, SWT.NONE);\r
                propertyContainer.setContent(spc);\r
                Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r