]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5207
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 22 Aug 2014 08:11:29 +0000 (08:11 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 22 Aug 2014 08:11:29 +0000 (08:11 +0000)
Fixing IsOutputWidget and ReplaceableIndexes to use WidgetImpl.setInput instead of own custom input handling

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

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/IsOutputWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/ReplaceableIndexesWidget.java

index db9a513fde029e4b89e5ee308ca9374a56a05931..40fe24cb1804411daf9ada97cc4b3271adc5832e 100644 (file)
@@ -16,6 +16,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
@@ -23,7 +24,6 @@ import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.management.ISessionContext;\r
@@ -39,6 +39,14 @@ public class IsOutputWidget implements Widget{
     public IsOutputWidget(Composite parent, WidgetSupport support, int style) {\r
         support.register(this);\r
         isOutputButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+        isOutputButton.setSelectionFactory(new ReadFactoryImpl<Resource, Boolean>() {\r
+\r
+            @Override\r
+            public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                return graph.hasStatement(variable, sr.IsOutput);\r
+            }\r
+        });\r
         isOutputButton.setText("Is Output");\r
     }\r
 \r
@@ -56,34 +64,8 @@ public class IsOutputWidget implements Widget{
         \r
         if(variable == null) return;\r
         \r
-        try {\r
-            context.getSession().syncRequest(new ReadRequest() {\r
-                \r
-                @Override\r
-                public void run(ReadGraph graph) throws DatabaseException {\r
-                    SysdynResource sr = SysdynResource.getInstance(graph);\r
-                    final boolean isOutput = graph.hasStatement(variable, sr.IsOutput);\r
-                    final Button button = getWidget();\r
-                    button.getDisplay().asyncExec(new Runnable() {\r
-                        \r
-                        @Override\r
-                        public void run() {\r
-                            if(button.isDisposed()) return;\r
-                            \r
-                            if(isOutput)\r
-                                button.setSelection(true);\r
-                            else\r
-                                button.setSelection(false);\r
-                        }\r
-                    });\r
+        isOutputButton.setInput(context, input);\r
 \r
-                        \r
-                }\r
-            });\r
-        } catch (DatabaseException e) {\r
-            e.printStackTrace();\r
-        }\r
-        \r
         isOutputButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
 \r
             @Override\r
index 0dd0a49a46e977bb422194b63f2e32cea1c7808f..d5403ac984dcf2f1d5a25e4f30284d6bb6f17a30 100644 (file)
@@ -17,14 +17,16 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionListener;\r
 import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\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.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.utils.ui.ISelectionUtils;\r
@@ -38,6 +40,14 @@ public class ReplaceableIndexesWidget implements Widget {
     public ReplaceableIndexesWidget(Composite parent, WidgetSupport support, int style) {\r
         support.register(this);\r
         isReplaceableButton = new org.simantics.browsing.ui.swt.widgets.Button(parent, support, style |= SWT.CHECK);\r
+        isReplaceableButton.setSelectionFactory(new ReadFactoryImpl<Resource, Boolean>() {\r
+\r
+            @Override\r
+            public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                return graph.getPossibleRelatedValue(variable, sr.Enumeration_isReplaceable);\r
+            }\r
+        });\r
         isReplaceableButton.setText("Can be replaced by parent module");\r
     }\r
 \r
@@ -55,35 +65,7 @@ public class ReplaceableIndexesWidget implements Widget {
         \r
         if(variable == null) return;\r
         \r
-        try {\r
-            context.getSession().syncRequest(new ReadRequest() {\r
-                \r
-                @Override\r
-                public void run(ReadGraph graph) throws DatabaseException {\r
-                    SysdynResource sr = SysdynResource.getInstance(graph);\r
-                    final Boolean replaceable = graph.getPossibleRelatedValue(variable, sr.Enumeration_isReplaceable);\r
-                    if(replaceable != null)\r
-                       selected = replaceable;\r
-                    final Button button = getWidget();\r
-                    button.getDisplay().asyncExec(new Runnable() {\r
-                        \r
-                        @Override\r
-                        public void run() {\r
-                            if(button.isDisposed()) return;\r
-                            \r
-                            if(replaceable)\r
-                                button.setSelection(true);\r
-                            else\r
-                                button.setSelection(false);\r
-                        }\r
-                    });\r
-\r
-                        \r
-                }\r
-            });\r
-        } catch (DatabaseException e) {\r
-            e.printStackTrace();\r
-        }\r
+        isReplaceableButton.setInput(context, input);\r
         \r
         isReplaceableButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
 \r
@@ -98,6 +80,7 @@ public class ReplaceableIndexesWidget implements Widget {
                        graph.claimLiteral(input, sr.Enumeration_isReplaceable, true);\r
                        selected = true;\r
                 }\r
+                Layer0Utils.addCommentMetadata(graph, "Modified " + NameUtils.getSafeName(graph, input) + " can be replaced to " + selected);\r
             }\r
         });\r
     }\r