]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Merged trunk @29859, 29877, 29880, 29881, 29864, 29886
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 16 Jul 2014 13:11:04 +0000 (13:11 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 16 Jul 2014 13:11:04 +0000 (13:11 +0000)
refs #5090
refs #5092
refs #5099

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/1.8@29908 ac1ea38d-2e2b-0410-8846-a27921b304fc

15 files changed:
org.simantics.jfreechart/src/org/simantics/jfreechart/ChartSelectionTabContributor.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AdjustableTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/BooleanSelectionListener.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ColorPicker.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/LabelPropertyTabContributor.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarAxisTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarGeneralPropertiesTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieGeneralPropertiesTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineAxisAndVariablesTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineGeneralPropertiesTab.java

index f8b0d764f6b0e825173331fdb78915c88662a896..df95e7144a3e43bacf2771df66f9da31582b96b9 100644 (file)
@@ -41,46 +41,46 @@ public class ChartSelectionTabContributor {
 \r
                  if(backend.isInstanceOf(plot, jfree.XYPlot)) {\r
                      tabs.add(new ComparableTabContributor(\r
-                             new XYLineGeneralPropertiesTab(),\r
+                             new XYLineGeneralPropertiesTab(r),\r
                              10,\r
                              r,\r
                              "General"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new XYLineAxisAndVariablesTab(),\r
+                             new XYLineAxisAndVariablesTab(r),\r
                              9,\r
                              r,\r
                              "Axis and Variables"));\r
                  } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
                      tabs.add(new ComparableTabContributor(\r
-                             new BarGeneralPropertiesTab(options),\r
+                             new BarGeneralPropertiesTab(r, options),\r
                              10,\r
                              r,\r
                              "General"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new BarSeriesTab(options),\r
+                             new BarSeriesTab(r, options),\r
                              9,\r
                              r,\r
                              "Variables"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new BarAxisTab(),\r
+                             new BarAxisTab(r),\r
                              8,\r
                              r,\r
                              "Axis"));                        \r
                  } else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
                      tabs.add(new ComparableTabContributor(\r
-                             new PieGeneralPropertiesTab(options),\r
+                             new PieGeneralPropertiesTab(r, options),\r
                              10,\r
                              r,\r
                              "General"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new PieSeriesTab(options),\r
+                             new PieSeriesTab(r, options),\r
                              9,\r
                              r,\r
                              "Variables"));\r
                  }\r
 \r
                  tabs.add(new ComparableTabContributor(\r
-                         new ChartTab(),\r
+                         new ChartTab(r),\r
                          1,\r
                          r,\r
                          "Chart"));\r
@@ -110,46 +110,46 @@ public class ChartSelectionTabContributor {
 \r
                  if(backend.isInstanceOf(plot, jfree.XYPlot)) {\r
                      tabs.add(new ComparableTabContributor(\r
-                             new XYLineGeneralPropertiesTab(),\r
+                             new XYLineGeneralPropertiesTab(r),\r
                              10,\r
                              r,\r
                              "General"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new XYLineAxisAndVariablesTab(),\r
+                             new XYLineAxisAndVariablesTab(r),\r
                              9,\r
                              r,\r
                              "Axis and Variables"));\r
                  } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
                      tabs.add(new ComparableTabContributor(\r
-                             new BarGeneralPropertiesTab(options),\r
+                             new BarGeneralPropertiesTab(r, options),\r
                              10,\r
                              r,\r
                              "General"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new BarSeriesTab2(options),\r
+                             new BarSeriesTab2(r, options),\r
                              9,\r
                              r,\r
                              "Variables"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new BarAxisTab(),\r
+                             new BarAxisTab(r),\r
                              8,\r
                              r,\r
                              "Axis"));                        \r
                  } else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
                      tabs.add(new ComparableTabContributor(\r
-                             new PieGeneralPropertiesTab(options),\r
+                             new PieGeneralPropertiesTab(r, options),\r
                              10,\r
                              r,\r
                              "General"));\r
                      tabs.add(new ComparableTabContributor(\r
-                             new PieSeriesTab2(options),\r
+                             new PieSeriesTab2(r, options),\r
                              9,\r
                              r,\r
                              "Variables"));\r
                  }\r
 \r
                  tabs.add(new ComparableTabContributor(\r
-                         new ChartTab(),\r
+                         new ChartTab(r),\r
                          1,\r
                          r,\r
                          "Chart"));\r
index 7fffd394d5ecc2ee2e4d121229288b32e2fb9dd2..a0f8308ddaa5ff8049a0d0d1e6f1ab69edb6d6c3 100644 (file)
@@ -32,6 +32,10 @@ public abstract class AdjustableTab extends LabelPropertyTabContributor {
        private static final int WIDE_SCREEN_WIDTH = 1100;\r
        protected Composite composite;\r
        \r
+       public AdjustableTab(Object id) {\r
+           super(id);\r
+       }\r
+       \r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) {\r
                // Get size of the available area.\r
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 d8d20f0e7242946018641856e812d92406e4cb30..1135348d6dd5ac8c74489835ee12566195d3e0ce 100644 (file)
@@ -28,6 +28,10 @@ import org.simantics.utils.ui.AdaptionUtils;
  */\r
 public class ChartTab extends LabelPropertyTabContributor implements Widget {\r
 \r
+    public ChartTab(Object id) {\r
+        super(id);\r
+    }\r
+\r
     private Composite parent;\r
 \r
     @Override\r
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
index 8c0441c48b42ee73c745a9d6f30665d51d51aa9d..b1cbbbfb96a1181e508e0b5eeb08103b2a234dd7 100644 (file)
@@ -24,6 +24,13 @@ import org.simantics.utils.ui.AdaptionUtils;
 \r
 public abstract class LabelPropertyTabContributor extends PropertyTabContributorImpl {\r
 \r
+    protected final Object id;\r
+    \r
+    public LabelPropertyTabContributor(Object id) {\r
+        assert (id != null);\r
+        this.id = id;\r
+    }\r
+    \r
     @Override\r
     public Read<String> getPartNameReadRequest(final ISelection forSelection) {\r
 \r
@@ -63,4 +70,21 @@ public abstract class LabelPropertyTabContributor extends PropertyTabContributor
         \r
     }\r
 \r
+    @Override\r
+    public int hashCode() {\r
+        return id.hashCode();\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        if (obj == null)\r
+            return false;\r
+        if (getClass() != obj.getClass())\r
+            return false;\r
+        LabelPropertyTabContributor other = (LabelPropertyTabContributor) obj;\r
+        return id.equals(other.id);\r
+    }\r
+\r
 }\r
index 38f7d21ef28223ba58ca4dc91ff8390149e4c915..9bb9ade9ab9ae920d8255b5dfeb59f5ba60ac519 100644 (file)
@@ -61,6 +61,10 @@ import org.simantics.utils.ui.AdaptionUtils;
  */\r
 public class BarAxisTab extends AdjustableTab implements Widget {\r
 \r
+    public BarAxisTab(Object id) {\r
+        super(id);\r
+    }\r
+\r
     private TrackedSpinner angle;\r
     private Integer angleInt = null;\r
     private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl();\r
index 370d14dc3f26b8e284d8417348878706de4162e8..79bdf9229a93f81c1979a01c6ec07e8c2028f829 100644 (file)
@@ -90,11 +90,8 @@ public class BarGeneralPropertiesTab extends AdjustableTab {
        private TrackedText fraction;\r
        private Point size;\r
     \r
-    public BarGeneralPropertiesTab() {\r
-       \r
-    }\r
-    \r
-    public BarGeneralPropertiesTab(int options) {\r
+    public BarGeneralPropertiesTab(Object id, int options) {\r
+        super(id);\r
        showTime = ((options & ChartPropertyOptions.SHOW_TIME) > 0); \r
        showFilter = ((options & ChartPropertyOptions.SHOW_FILTER) > 0);\r
     }\r
index 5a9c55a25fd158f91f01c38e4e19d83abf816b39..9d9ca5c67120a45c72c659bd66130953c856c4fc 100644 (file)
@@ -63,7 +63,8 @@ public class BarSeriesTab extends AdjustableTab implements Widget {
     private int options;\r
        private Composite buttonComposite;\r
 \r
-    public BarSeriesTab(int options) {\r
+    public BarSeriesTab(Object id, int options) {\r
+        super(id);\r
         additionalSupport = new WidgetSupportImpl();\r
         this.options = options;\r
     }\r
index 24076dda6460b6f7387937744ac1845aecf30de9..cff6d719fee8f9347e25040c4d543fdb5d666d98 100644 (file)
@@ -66,7 +66,8 @@ public class BarSeriesTab2 extends LabelPropertyTabContributor implements Widget
     private BarSeriesPropertyComposite2 spc;\r
     private int options;\r
 \r
-    public BarSeriesTab2(int options) {\r
+    public BarSeriesTab2(Object id, int options) {\r
+        super(id);\r
         additionalSupport = new WidgetSupportImpl();\r
         this.options = options;\r
     }\r
index 3185932ae240aee9f37fd8f8186fc363fa79debc..75ee2a6285aadfd7862192ca09b9fdc544afe765 100644 (file)
@@ -72,11 +72,8 @@ public class PieGeneralPropertiesTab extends AdjustableTab {
        private TrackedText fraction;\r
        private Point size;\r
     \r
-    public PieGeneralPropertiesTab() {\r
-       \r
-    }\r
-    \r
-    public PieGeneralPropertiesTab(int options) {\r
+    public PieGeneralPropertiesTab(Object id, int options) {\r
+        super(id);\r
        showTime = ((options & ChartPropertyOptions.SHOW_TIME) > 0); \r
        showFilter = ((options & ChartPropertyOptions.SHOW_FILTER) > 0);\r
     }\r
index d5cf346a84280367fbfbb69943cbd7c367d5a7ae..5fbb53c1dd5c50b2c3ef7c98123bd51e55eb82b5 100644 (file)
@@ -62,7 +62,8 @@ public class PieSeriesTab extends AdjustableTab implements Widget {
     private int options;\r
        private Composite buttonComposite;\r
     \r
-    public PieSeriesTab(int options) {\r
+    public PieSeriesTab(Object id, int options) {\r
+        super(id);\r
         additionalSupport = new WidgetSupportImpl();\r
         this.options = options;\r
     }\r
index 7103b6f8a2ffaf52dba7a57bf0aaf5d257ec217a..8d54eb5c7e7d5f1a4db3250615533b396d11430e 100644 (file)
@@ -65,7 +65,8 @@ public class PieSeriesTab2 extends LabelPropertyTabContributor implements Widget
     private Resource chartResource;\r
     private int options;\r
 \r
-    public PieSeriesTab2(int options) {\r
+    public PieSeriesTab2(Object id, int options) {\r
+        super(id);\r
         additionalSupport = new WidgetSupportImpl();\r
         this.options = options;\r
     }\r
index 98d7107e27a4409161123876c8c7b1ea780a4c8f..ea2714ec4bec3bbe2ece69b48da426b42a16d1cd 100644 (file)
@@ -65,7 +65,8 @@ public class XYLineAxisAndVariablesTab extends AdjustableTab {
     private WidgetSupportImpl additionalSupport;\r
        private Composite buttonComposite;\r
 \r
-    public XYLineAxisAndVariablesTab() {\r
+    public XYLineAxisAndVariablesTab(Object id) {\r
+        super(id);\r
         additionalSupport = new WidgetSupportImpl();\r
     }\r
 \r
index 81581d1401af3fa9abe9294032ad1504a3f1808e..3521025b39b29e0f341bfdaa5a4ceb8c1320da30 100644 (file)
@@ -71,6 +71,10 @@ import org.simantics.utils.ui.AdaptionUtils;
  */\r
 public class XYLineGeneralPropertiesTab extends AdjustableTab implements Widget {\r
 \r
+    public XYLineGeneralPropertiesTab(Object id) {\r
+        super(id);\r
+    }\r
+\r
     private ScrolledComposite sc;\r
     private TrackedText name, title, xlabel, xvariable, xmin, xmax;\r
     private TrackedCombo type;\r