]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5092
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jul 2014 08:02:30 +0000 (08:02 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jul 2014 08:02:30 +0000 (08:02 +0000)
Fixing undo problems in platform by adding graph.markUndoPoint() calls in write transactions

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

org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/BooleanSelectionListener.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java

index 3fe269b9098c4600da4f32b2a7b124e3d16a3246..ff27eb2e5d6fae04ed866c5eb0820f6037f669b4 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ObjectsWithType;\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.layer0.Layer0;\r
 \r
@@ -85,9 +86,13 @@ public class BooleanSelectionListener extends SelectionListenerImpl<Resource> {
     private void setValue(WriteGraph graph, Resource resource) throws DatabaseException {\r
         Resource property =  graph.getResource(propertyURI);\r
         Boolean value = graph.getPossibleRelatedValue(resource, property, Bindings.BOOLEAN);\r
-        if (value == null)\r
+        if (value == null) {\r
                graph.claimLiteral(resource, property, !defaultValue);\r
-        else\r
-               graph.claimLiteral(resource, property, Boolean.FALSE.equals(value));\r
+               Layer0Utils.addCommentMetadata(graph, "Modified " + graph.getPossibleRelatedValue2(property, Layer0.getInstance(graph).HasName, Bindings.STRING) + " for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasLabel, Bindings.STRING) + " to " + !defaultValue);\r
+        } else { \r
+            boolean newValue = Boolean.FALSE.equals(value);\r
+               graph.claimLiteral(resource, property, newValue);\r
+            Layer0Utils.addCommentMetadata(graph, "Modified " + graph.getPossibleRelatedValue2(property, Layer0.getInstance(graph).HasName, Bindings.STRING) + " for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasLabel, Bindings.STRING) + " to " + newValue);\r
+        }\r
     }\r
 }
\ No newline at end of file
index e5f003f8d12514a1b0eb333b81217a7147fd56d6..7a0d9ce5422c7acae6317a443f7b92e828acdf7e 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart.properties;\r
 \r
+import java.util.Arrays;\r
+\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.resource.ImageDescriptor;\r
@@ -24,22 +26,26 @@ import org.eclipse.swt.widgets.ColorDialog;
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Display;\r
 import org.eclipse.swt.widgets.Shell;\r
+import org.simantics.Simantics;\r
 import org.simantics.browsing.ui.swt.widgets.Button;\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.databoard.Bindings;\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.WriteRequest;\r
+import org.simantics.db.common.request.UniqueRead;\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.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.diagram.stubs.G2DResource;\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
-import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.RunnableWithObject;\r
 import org.simantics.utils.datastructures.Triple;\r
 import org.simantics.utils.ui.AdaptionUtils;\r
@@ -264,47 +270,50 @@ public class ColorPicker extends Composite implements Widget {
             this.e = e;\r
             super.widgetSelected(e);\r
         }\r
+        \r
+        @Override\r
+        public void beforeApply(final Resource input) {\r
+            try {\r
+                final RGB oldRGB = Simantics.getSession().syncRequest(new UniqueRead<RGB>() {\r
+\r
+                    @Override\r
+                    public RGB perform(ReadGraph graph) throws DatabaseException {\r
+                        Resource resource = getResource(graph, input);\r
+                        return getColor(graph, resource);\r
+                    }\r
+                });\r
+                \r
+                final Display display = color.getWidget().getDisplay();\r
+                \r
+                // Use color dialog to select a color\r
+                Shell shell = new Shell(display);\r
+                ColorDialog cd = new ColorDialog(shell);\r
+                Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150);\r
+                cd.getParent().setLocation(point.x, point.y);\r
+                cd.setText("Select color");\r
+                cd.setRGB(oldRGB);\r
+                rgb = cd.open();\r
+                if(rgb == null)\r
+                    return;\r
+                \r
+                \r
+            } catch (DatabaseException e) {\r
+                e.printStackTrace();\r
+            }\r
+        }\r
 \r
         @Override\r
         public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
-            if(color.getWidget().isDisposed())\r
-                return;\r
-            \r
-            final Resource resource = getResource(graph, input);\r
-            final Display display = color.getWidget().getDisplay();\r
-            final RGB oldRGB = getColor(graph, resource);\r
             \r
-            display.asyncExec(new RunnableWithObject(oldRGB) {\r
-                @Override\r
-                public void run() {\r
-                    // Use color dialog to select a color\r
-                    Shell shell = new Shell(display);\r
-                    ColorDialog cd = new ColorDialog(shell);\r
-                    Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150);\r
-                    cd.getParent().setLocation(point.x, point.y);\r
-                    cd.setText("Select color");\r
-                    cd.setRGB((RGB)getObject());\r
-                    rgb = cd.open();\r
-                    if(rgb == null)\r
-                        return;\r
-                    \r
-                    SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-                        \r
-                        @Override\r
-                        public void perform(WriteGraph graph) throws DatabaseException {\r
-                            G2DResource g2d = G2DResource.getInstance(graph);\r
-                            float[] components = new float[] {rgb.red / 255.0f,  rgb.green / 255.0f, rgb.blue / 255.0f, 1.0f};\r
-                            graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components);                            \r
-                        }\r
-                    });\r
-                    \r
-                }\r
-            });\r
-            \r
-            \r
-\r
+            G2DResource g2d = G2DResource.getInstance(graph);\r
+            float[] components = new float[] {rgb.red / 255.0f,  rgb.green / 255.0f, rgb.blue / 255.0f, 1.0f};\r
+            Resource resource = getResource(graph, input);\r
+            float[] currentComponents = graph.getPossibleRelatedValue2(resource, getColorRelation(graph));\r
+            if (currentComponents == null || !Arrays.equals(components, currentComponents)) {\r
+                graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components);\r
+                Layer0Utils.addCommentMetadata(graph, "Modified color of " + NameUtils.getSafeName(graph, resource) + " to " + Arrays.toString(components));\r
+            }\r
         }\r
-\r
     }\r
 \r
     /**\r
@@ -376,10 +385,15 @@ public class ColorPicker extends Composite implements Widget {
                     float[] components = java.awt.Color.BLUE.getColorComponents(new float[4]);\r
                     components[3] = 1.0f;\r
                     graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components);\r
+                    Layer0Utils.addCommentMetadata(graph, "Color for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING) + " set to custom ");\r
                 }\r
             } else {\r
                 // Default selected, remove color definition\r
-                graph.deny(resource, getColorRelation(graph));\r
+                Object o = graph.getPossibleObject(resource, getColorRelation(graph));\r
+                if (o != null) {\r
+                    graph.deny(resource, getColorRelation(graph));\r
+                    Layer0Utils.addCommentMetadata(graph, "Color for " + graph.getPossibleRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING) + " set to Default");\r
+                }\r
             }\r
         }\r
     }\r