]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #4373
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 2 Jul 2013 13:50:48 +0000 (13:50 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 2 Jul 2013 13:50:48 +0000 (13:50 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27673 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.jfreechart.ontology/graph.tg
org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph
org.simantics.jfreechart.ontology/src/org/simantics/sysdyn/JFreeChartResource.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/CategoryPlot.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteredDataset.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringPieDataset.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/DoublePropertyFactory2.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/DoublePropertyModifier2.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarGeneralPropertiesTab.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieGeneralPropertiesTab.java

index 3abaa9be847550808ab81c7e8e16fbfe528e4f5a..5a57c746c0774f4bfe84830680f528209574867a 100644 (file)
Binary files a/org.simantics.jfreechart.ontology/graph.tg and b/org.simantics.jfreechart.ontology/graph.tg differ
index aaf0a275a2264f0bb380b09b52486b265c2138c1..f185b412249c0e8fb9fb2f1ac1a5966c45a4c56a 100644 (file)
@@ -130,4 +130,12 @@ JFREE.Right <T JFREE.Position
 JFREE.ChartElement <T DIA.Element
     L0.HasDescription "Element for displaying charts in diagrams"
     >-- JFREE.ChartElement.component --> JFREE.Chart <R L0.IsWeaklyRelatedTo
-        
\ No newline at end of file
+    
+//#####################################################################
+// Filtering
+//#####################################################################
+JFREE.Filter <T L0.Library
+JFREE.Filter.used <R L0.HasProperty : L0.FunctionalRelation
+   L0.HasRange L0.Boolean
+JFREE.Filter.fraction <R L0.HasProperty : L0.FunctionalRelation
+   L0.HasRange L0.Double
\ No newline at end of file
index 9faec9520b92f0ac8b432a341a17862003b7c503..543c17dde055f5b4f9612ae1a12b9aba29cb40e6 100644 (file)
@@ -70,6 +70,11 @@ public class JFreeChartResource {
     public final Resource Dataset_seriesList;\r
     public final Resource Dataset_seriesList_Inverse;\r
     public final Resource DeviationRenderer;\r
+    public final Resource Filter;\r
+    public final Resource Filter_fraction;\r
+    public final Resource Filter_fraction_Inverse;\r
+    public final Resource Filter_used;\r
+    public final Resource Filter_used_Inverse;\r
     public final Resource ImageTitle;\r
     public final Resource Left;\r
     public final Resource LegendTitle;\r
@@ -196,6 +201,11 @@ public class JFreeChartResource {
         public static final String Dataset_seriesList = "http://www.simantics.org/JFreeChart-1.0/Dataset/seriesList";\r
         public static final String Dataset_seriesList_Inverse = "http://www.simantics.org/JFreeChart-1.0/Dataset/seriesList/Inverse";\r
         public static final String DeviationRenderer = "http://www.simantics.org/JFreeChart-1.0/DeviationRenderer";\r
+        public static final String Filter = "http://www.simantics.org/JFreeChart-1.0/Filter";\r
+        public static final String Filter_fraction = "http://www.simantics.org/JFreeChart-1.0/Filter/fraction";\r
+        public static final String Filter_fraction_Inverse = "http://www.simantics.org/JFreeChart-1.0/Filter/fraction/Inverse";\r
+        public static final String Filter_used = "http://www.simantics.org/JFreeChart-1.0/Filter/used";\r
+        public static final String Filter_used_Inverse = "http://www.simantics.org/JFreeChart-1.0/Filter/used/Inverse";\r
         public static final String ImageTitle = "http://www.simantics.org/JFreeChart-1.0/ImageTitle";\r
         public static final String Left = "http://www.simantics.org/JFreeChart-1.0/Left";\r
         public static final String LegendTitle = "http://www.simantics.org/JFreeChart-1.0/LegendTitle";\r
@@ -332,6 +342,11 @@ public class JFreeChartResource {
         Dataset_seriesList = getResourceOrNull(graph, URIs.Dataset_seriesList);\r
         Dataset_seriesList_Inverse = getResourceOrNull(graph, URIs.Dataset_seriesList_Inverse);\r
         DeviationRenderer = getResourceOrNull(graph, URIs.DeviationRenderer);\r
+        Filter = getResourceOrNull(graph, URIs.Filter);\r
+        Filter_fraction = getResourceOrNull(graph, URIs.Filter_fraction);\r
+        Filter_fraction_Inverse = getResourceOrNull(graph, URIs.Filter_fraction_Inverse);\r
+        Filter_used = getResourceOrNull(graph, URIs.Filter_used);\r
+        Filter_used_Inverse = getResourceOrNull(graph, URIs.Filter_used_Inverse);\r
         ImageTitle = getResourceOrNull(graph, URIs.ImageTitle);\r
         Left = getResourceOrNull(graph, URIs.Left);\r
         LegendTitle = getResourceOrNull(graph, URIs.LegendTitle);\r
index 12ea8d7b0d2ca8fef914a1107e9c75262f20e2f9..b4a52d912c8b3e9e77b27f0fb89b4b989efd161c 100644 (file)
@@ -16,7 +16,9 @@ import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.Plot;\r
 import org.jfree.chart.plot.PlotOrientation;\r
 import org.jfree.chart.renderer.category.CategoryItemRenderer;\r
+import org.jfree.data.general.Dataset;\r
 import org.jfree.ui.RectangleInsets;\r
+import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -54,6 +56,8 @@ public class CategoryPlot extends AbstractPlot {
         for(int i = 0; i < properties.domains.size(); i++) {\r
             cplot.setDomainAxis(i, (CategoryAxis)properties.domains.get(i).getAxis());\r
         }\r
+       \r
+        \r
         \r
         IAxis axis;\r
         for(int i = 0; i < properties.datasets.size(); i++) {\r
@@ -68,6 +72,19 @@ public class CategoryPlot extends AbstractPlot {
             axis = properties.domainMappings.get(dataset);\r
             if(axis != null && properties.ranges.contains(axis))\r
                 cplot.mapDatasetToDomainAxis(i, properties.domains.indexOf(axis));\r
+            \r
+            if (ds instanceof FilteredDataset) {\r
+               FilteredDataset f = (FilteredDataset)ds;\r
+               Boolean useFilter = (Boolean)properties.otherProperties.get("useFilter");\r
+                Double filterFraction = (Double)properties.otherProperties.get("filterFraction");\r
+                if (useFilter != null && filterFraction != null) {\r
+                       f.setFiltering(useFilter);\r
+                       f.setFilterFraction(filterFraction*0.01);\r
+                       f.updateFiltered();\r
+                } else {\r
+                       f.setFiltering(false);\r
+                }\r
+            }\r
         }\r
 \r
         Boolean visibleGrid = (Boolean)properties.otherProperties.get("visibleGrid");\r
@@ -96,6 +113,11 @@ public class CategoryPlot extends AbstractPlot {
         properties.otherProperties.put("visibleGrid", visibleGrid);\r
         Boolean orientation = graph.getPossibleRelatedValue(resource, jfree.Plot_orientation);\r
         properties.otherProperties.put("orientation", orientation);\r
+        \r
+        Boolean useFilter = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Filter_used, Bindings.BOOLEAN);\r
+        Double  filterFraction = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Filter_fraction, Bindings.DOUBLE);\r
+        properties.otherProperties.put("useFilter", useFilter);\r
+        properties.otherProperties.put("filterFraction", filterFraction);\r
     }\r
 \r
 }\r
diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteredDataset.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteredDataset.java
new file mode 100644 (file)
index 0000000..1d11f12
--- /dev/null
@@ -0,0 +1,26 @@
+package org.simantics.jfreechart.chart;\r
+\r
+/**\r
+ * Interface for configuring data filtering.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public interface FilteredDataset {\r
+\r
+       public boolean isFiltering();\r
+       public void setFiltering(boolean filtering);\r
+       \r
+       \r
+       public double getFilterFraction();\r
+       /**\r
+        * Sets filtering fraction 0 <= fraction <= 1\r
+        * With filtering fraction 0 nothing gets filtered.\r
+        * With filtering fraction 1 everything gets filtered.\r
+        * \r
+        * @param filterFraction\r
+        */\r
+       public void setFilterFraction(double filterFraction);\r
+       \r
+       public void updateFiltered();\r
+}\r
diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java
new file mode 100644 (file)
index 0000000..510518a
--- /dev/null
@@ -0,0 +1,178 @@
+package org.simantics.jfreechart.chart;\r
+\r
+/**\r
+ * Filters CategoryDataset by creating "Other" item for filtered data.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+import java.util.List;\r
+\r
+import org.jfree.data.category.DefaultCategoryDataset;\r
+import org.jfree.data.general.AbstractDataset;\r
+import org.jfree.data.general.DatasetChangeEvent;\r
+\r
+@SuppressWarnings("rawtypes")\r
+public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset{\r
+       \r
+       private static final long serialVersionUID = -4955124650051030544L;\r
+       \r
+       org.jfree.data.category.CategoryDataset original;\r
+       DefaultCategoryDataset filtered;\r
+       org.jfree.data.category.CategoryDataset used;\r
+       \r
+       boolean filterRows = true;\r
+       boolean filtering = true;\r
+       double filterFraction = 0.05;\r
+       private Comparable other;\r
+       \r
+       public FilteringCategoryDataset(org.jfree.data.category.CategoryDataset dataset, Comparable other) {\r
+               this.original = dataset;\r
+               this.filtered = new DefaultCategoryDataset();\r
+               this.other = other;\r
+               this.used = filtered;\r
+               updateFiltered();\r
+       }\r
+       \r
+       @Override\r
+       public boolean isFiltering() {\r
+               return filtering;\r
+       }\r
+       \r
+       @Override\r
+       public void setFiltering(boolean filtering) {\r
+               this.filtering = filtering;\r
+               if (filtering)\r
+                       used = filtered;\r
+               else\r
+                       used = original;\r
+               notifyListeners(new DatasetChangeEvent(this, this));\r
+       }\r
+       \r
+       public void setFilterFraction(double filterFraction) {\r
+               this.filterFraction = filterFraction;\r
+       }\r
+       \r
+       public double getFilterFraction() {\r
+               return filterFraction;\r
+       }\r
+       \r
+       /**\r
+        * Filter rows or columns.\r
+        * @param filterRows\r
+        */\r
+       public void setFilterRows(boolean filterRows) {\r
+               this.filterRows = filterRows;\r
+       }\r
+       \r
+       public boolean isFilterRows() {\r
+               return filterRows;\r
+       }\r
+       \r
+       public void updateFiltered() {\r
+               filtered.clear();\r
+               if (filterRows) {\r
+                       for (Object column : original.getColumnKeys()) {\r
+                               Double total = 0.0;\r
+                               Double other = 0.0;\r
+                               for (Object row : original.getRowKeys()) {\r
+                                       Number value =  original.getValue((Comparable) row, (Comparable)column);\r
+                                       if (value != null)\r
+                                               total+=value.doubleValue();\r
+                               }\r
+                               total *= filterFraction;\r
+                               for (Object row : original.getRowKeys()) {\r
+                                       Number value = original.getValue((Comparable) row, (Comparable)column);\r
+                                       if (value == null)\r
+                                               continue;\r
+                                       if (value.doubleValue() > total) {\r
+                                               filtered.addValue(value, (Comparable) row, (Comparable)column);\r
+                                       } else {\r
+                                               other += value.doubleValue(); \r
+                                       }\r
+                               }\r
+                               if (other > 0.0) {\r
+                                       filtered.addValue(other, this.other, (Comparable)column);\r
+                               }\r
+                       }\r
+               } else {\r
+                       for (Object row : original.getRowKeys()) {\r
+                               Double total = 0.0;\r
+                               Double other = 0.0;\r
+                               for (Object column : original.getColumnKeys()) {\r
+                                       Number value = original.getValue((Comparable) row, (Comparable)column);\r
+                                       if (value != null)\r
+                                               total += value.doubleValue();\r
+                               }\r
+                               total *= filterFraction;\r
+                               for (Object column : original.getColumnKeys()) {\r
+                                       Number value = original.getValue((Comparable) row, (Comparable)column);\r
+                                       if (value == null)\r
+                                               continue;\r
+                                       if (value.doubleValue() > total) {\r
+                                               filtered.addValue(value, (Comparable) row, (Comparable)column);\r
+                                       } else {\r
+                                               other += value.doubleValue(); \r
+                                       }\r
+                               }\r
+                               if (other > 0.0) {\r
+                                       filtered.addValue(other, (Comparable)row, this.other);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public int getColumnCount() {\r
+               return used.getColumnCount();\r
+       }\r
+       \r
+       @Override\r
+       public int getRowCount() {\r
+               return used.getRowCount();\r
+       }\r
+       \r
+       @Override\r
+       public Number getValue(Comparable rowKey, Comparable columnKey) {\r
+               return used.getValue(rowKey, columnKey);\r
+       }\r
+       \r
+       @Override\r
+       public Number getValue(int row, int column) {\r
+               return used.getValue(row, column);\r
+       }\r
+       \r
+       @Override\r
+       public List getColumnKeys() {\r
+               return used.getColumnKeys();\r
+       }       \r
+       \r
+       @Override\r
+       public Comparable getColumnKey(int column) {\r
+               return used.getColumnKey(column);\r
+       }\r
+       \r
+       @Override\r
+       public List getRowKeys() {\r
+               return used.getRowKeys();\r
+       }\r
+       \r
+       @Override\r
+       public Comparable getRowKey(int row) {\r
+               return used.getRowKey(row);\r
+       }\r
+       \r
+       @Override\r
+       public int getRowIndex(Comparable key) {\r
+               return used.getRowIndex(key);\r
+       }\r
+       \r
+       @Override\r
+       public int getColumnIndex(Comparable key) {\r
+               return used.getColumnIndex(key);\r
+       }\r
+       \r
+       \r
+       \r
+\r
+}\r
diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringPieDataset.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringPieDataset.java
new file mode 100644 (file)
index 0000000..f815b03
--- /dev/null
@@ -0,0 +1,117 @@
+package org.simantics.jfreechart.chart;\r
+\r
+import java.util.List;\r
+\r
+import org.jfree.data.general.AbstractDataset;\r
+import org.jfree.data.general.DatasetChangeEvent;\r
+import org.jfree.data.general.DefaultPieDataset;\r
+import org.jfree.data.general.PieDataset;\r
+\r
+/**\r
+ * Filters PieDataset by creating "Other" item for filtered data.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+@SuppressWarnings("rawtypes")\r
+public class FilteringPieDataset extends AbstractDataset implements PieDataset, FilteredDataset{\r
+       \r
+       private static final long serialVersionUID = -4955124650051030544L;\r
+       \r
+       PieDataset original;\r
+       DefaultPieDataset filtered;\r
+       PieDataset used;\r
+       \r
+\r
+       boolean filtering = true;\r
+       double filterFraction = 0.05;\r
+       \r
+       private Comparable other = "other";\r
+       \r
+       public FilteringPieDataset(PieDataset dataset, Comparable other) {\r
+               this.original = dataset;\r
+               this.filtered = new DefaultPieDataset();\r
+               this.other = other;\r
+               this.used = filtered;\r
+               updateFiltered();\r
+       }\r
+       \r
+       @Override\r
+       public boolean isFiltering() {\r
+               return filtering;\r
+       }\r
+       \r
+       @Override\r
+       public void setFiltering(boolean filtering) {\r
+               this.filtering = filtering;\r
+               if (filtering)\r
+                       used = filtered;\r
+               else\r
+                       used = original;\r
+               notifyListeners(new DatasetChangeEvent(this, this));\r
+       }\r
+       \r
+\r
+       public void setFilterFraction(double filterFraction) {\r
+               this.filterFraction = filterFraction;\r
+       }\r
+       \r
+       public double getFilterFraction() {\r
+               return filterFraction;\r
+       }\r
+       \r
+       public void updateFiltered() {\r
+               filtered.clear();\r
+               Double total = 0.0;\r
+               Double other = 0.0;\r
+               for (Object key : original.getKeys()) {\r
+                       total += original.getValue((Comparable) key).doubleValue();\r
+               }\r
+               total *= filterFraction;\r
+               for (Object key : original.getKeys()) {\r
+                       Number value = original.getValue((Comparable) key).doubleValue();\r
+                       \r
+                       if (value.doubleValue() > total) {\r
+                               filtered.setValue((Comparable) key,value);\r
+                       } else {\r
+                               other += value.doubleValue(); \r
+                       }\r
+               }\r
+               if (other > 0.0) {\r
+                       filtered.setValue(this.other, other);\r
+               }\r
+                       \r
+               \r
+       }\r
+       \r
+       @Override\r
+       public List getKeys() {\r
+               return used.getKeys();\r
+       }\r
+       \r
+       @Override\r
+       public int getItemCount() {\r
+               return used.getItemCount();\r
+       }\r
+       \r
+       @Override\r
+       public Comparable getKey(int index) {\r
+               return used.getKey(index);\r
+       }\r
+       \r
+       @Override\r
+       public int getIndex(Comparable key) {\r
+               return used.getIndex(key);\r
+       }\r
+       \r
+       @Override\r
+       public Number getValue(Comparable key) {\r
+               return used.getValue(key);\r
+       }\r
+       \r
+       @Override\r
+       public Number getValue(int index) {\r
+               return used.getValue(index);\r
+       }\r
+\r
+}\r
index 925816a81d2c678d54a238167b92efe5ac35dde1..2c0705007cfaba8dcaed9aa4bf9296ad749e1462 100644 (file)
@@ -79,6 +79,11 @@ public class PiePlot extends AbstractPlot {
     protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException {\r
         Boolean labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN);\r
         properties.otherProperties.put("labelsVisible", labelsVisible);\r
+        \r
+        Boolean useFilter = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Filter_used, Bindings.BOOLEAN);\r
+        Double  filterFraction = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Filter_fraction, Bindings.DOUBLE);\r
+        properties.otherProperties.put("useFilter", useFilter);\r
+        properties.otherProperties.put("filterFraction", filterFraction);\r
     }\r
     \r
     @Override\r
@@ -103,6 +108,19 @@ public class PiePlot extends AbstractPlot {
             pieDataset = (org.jfree.data.general.PieDataset)dataset;\r
             piePlot.setDataset(pieDataset);\r
             \r
+            if (pieDataset instanceof FilteredDataset) {\r
+               FilteredDataset f = (FilteredDataset)pieDataset;\r
+               Boolean useFilter = (Boolean)properties.otherProperties.get("useFilter");\r
+                Double filterFraction = (Double)properties.otherProperties.get("filterFraction");\r
+                if (useFilter != null && filterFraction != null) {\r
+                       f.setFiltering(useFilter);\r
+                       f.setFilterFraction(filterFraction*0.01);\r
+                       f.updateFiltered();\r
+                } else {\r
+                       f.setFiltering(false);\r
+                }\r
+            }\r
+            \r
             Boolean labelsVisible = (Boolean)properties.otherProperties.get("labelsVisible");\r
             if(Boolean.FALSE.equals(labelsVisible))\r
                 piePlot.setLabelGenerator(null);\r
diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/DoublePropertyFactory2.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/DoublePropertyFactory2.java
new file mode 100644 (file)
index 0000000..3bd4250
--- /dev/null
@@ -0,0 +1,119 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.jfreechart.chart.properties;\r
+\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.utils.datastructures.Quad;\r
+\r
+/**\r
+ * PropertyFactory for finding a double property. Supports also finding the \r
+ * property from a first occurrence of resource ConsistsOf type HasProperty   \r
+ * \r
+ * @author Teemu Lempinen\r
+ * @author Marko Luukkainen\r
+ *\r
+ */\r
+public class DoublePropertyFactory2 extends ReadFactoryImpl<Resource, String> {\r
+\r
+    final private String propertyURI;\r
+    final private String typeURI;\r
+    final private Double defaultValue;\r
+    \r
+    /**\r
+     * PropertyFactory for finding a boolean property with propertyURI\r
+     * \r
+     * @param propertyURI URI for the boolean property\r
+     */\r
+    public DoublePropertyFactory2(String propertyURI) {\r
+        this(null, propertyURI);\r
+    }\r
+    \r
+\r
+    /**\r
+     * PropertyFactory for finding a boolean property with propertyURI.\r
+     *  \r
+     * Finds the property for first ObjectWithType(resource, L0.ConsistsOf, type)\r
+     *  \r
+     * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible)\r
+     *  \r
+     * @param typeURI URI for a resource (resource ConsistsOf type) (null allowed)\r
+     * @param propertyURI URI for the boolean property\r
+     * @param inverse Invert the result?\r
+     */\r
+    public DoublePropertyFactory2(String typeURI, String propertyURI) {\r
+        this(typeURI, propertyURI, 0.0);\r
+    }\r
+    \r
+    /**\r
+     * PropertyFactory for finding a boolean property with propertyURI.\r
+     *  \r
+     * Finds the property for first ObjectWithType(resource, L0.ConsistsOf, type)\r
+     *  \r
+     * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible)\r
+     * \r
+     * @param typeURI URI for a resource (resource ConsistsOf type) (null allowed -> not used)\r
+     * @param propertyURI URI for the boolean property\r
+     * @param inverse Invert the result?\r
+     * @param defaultValue default value\r
+     */\r
+    public DoublePropertyFactory2(String typeURI, String propertyURI, double defaultValue) {\r
+        this.propertyURI = propertyURI;\r
+        this.typeURI = typeURI;\r
+        this.defaultValue = defaultValue;\r
+    }\r
+\r
+    @Override\r
+    public Object getIdentity(Object inputContents) {\r
+        return new Quad<Resource, String, Object, Double>((Resource) inputContents, propertyURI, getClass(), defaultValue);\r
+    }\r
+\r
+    @Override\r
+    public String perform(ReadGraph graph, Resource r) throws DatabaseException {\r
+        if(typeURI == null) {\r
+            // if no typeUri, use the default resource r\r
+            return getValue(graph, r);\r
+        } else {\r
+            // typeURI was defined, find the property for the first occurence of ConsistsOf type\r
+            Resource type =  graph.getResource(typeURI);\r
+            for(Resource o : graph.syncRequest(new ObjectsWithType(r, Layer0.getInstance(graph).ConsistsOf, type))) {\r
+                // Returns the value for the first occurrence\r
+                return getValue(graph, o);\r
+            }\r
+        }\r
+        // if nothing was found with typeURI\r
+        return "";\r
+    }\r
+    \r
+    /**\r
+     * Return the value for a Boolean literal possibly inverted (or default if resource != Boolean literal) \r
+     * \r
+     * @param graph ReadGraph\r
+     * @param resource Literal Boolean resource \r
+     * @return value of the parameter (or default or inverted)\r
+     * @throws DatabaseException\r
+     */\r
+    private String getValue(ReadGraph graph, Resource resource) throws DatabaseException {\r
+        Double value = graph.getPossibleRelatedValue(resource, graph.getResource(propertyURI), Bindings.DOUBLE);\r
+        if(value != null) {\r
+            return value.toString();\r
+        } else if (defaultValue != null){\r
+            return defaultValue.toString();\r
+        }\r
+        return "";\r
+    }\r
+}
\ No newline at end of file
diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/DoublePropertyModifier2.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/DoublePropertyModifier2.java
new file mode 100644 (file)
index 0000000..a7dfe81
--- /dev/null
@@ -0,0 +1,49 @@
+package org.simantics.jfreechart.chart.properties;\r
+\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.Resource;\r
+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.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class DoublePropertyModifier2 extends TextModifyListenerImpl<Resource> {\r
+\r
+       final private String typeUri;\r
+    final private String propertyURI;\r
+\r
+    public DoublePropertyModifier2(ISessionContext context, String propertyURI) {\r
+        this.propertyURI = propertyURI;\r
+        this.typeUri = null;\r
+    }\r
+    \r
+    public DoublePropertyModifier2(ISessionContext context, String typeURI, String propertyURI) {\r
+        this.propertyURI = propertyURI;\r
+        this.typeUri = typeURI;\r
+    }\r
+\r
+    @Override\r
+    public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException {\r
+        if (typeUri == null)\r
+               applyValue(graph, input, text);\r
+        else {\r
+               Resource type =  graph.getResource(typeUri);\r
+            for(Resource object : graph.syncRequest(new ObjectsWithType(input, Layer0.getInstance(graph).ConsistsOf, type))) {\r
+                applyValue(graph, object,text);\r
+            }\r
+        }\r
+       \r
+    }\r
+    \r
+    private void applyValue(WriteGraph graph, Resource input, String text) throws DatabaseException {\r
+       if (text == null || text.trim().isEmpty()) {\r
+            if (graph.hasStatement(input, graph.getResource(propertyURI)))\r
+                graph.denyValue(input, graph.getResource(propertyURI));\r
+        } else {\r
+            graph.claimLiteral(input, graph.getResource(propertyURI), Double.parseDouble(text), Bindings.DOUBLE);\r
+        }\r
+    }\r
+\r
+}\r
index f66cc7e1d3868ddab01bda08154531dea5455f21..8221f81992f8cf73d6e5c34c50f1f4dcba983913 100644 (file)
@@ -40,6 +40,8 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;\r
 import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;\r
+import org.simantics.jfreechart.chart.properties.DoublePropertyFactory2;\r
+import org.simantics.jfreechart.chart.properties.DoublePropertyModifier2;\r
 import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
@@ -77,7 +79,7 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor {
         sc.setExpandVertical(true);\r
 \r
         composite = new Composite(sc, SWT.NONE);\r
-        GridLayoutFactory.fillDefaults().numColumns(3).margins(3, 3).applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().numColumns(4).margins(3, 3).applyTo(composite);\r
 \r
         // General properties\r
         Group general = new Group(composite, SWT.NONE);\r
@@ -203,6 +205,26 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor {
         sc.setContent(composite);\r
         Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
         sc.setMinSize(size);\r
+        \r
+        Group filteringGroup = new Group(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(filteringGroup);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(filteringGroup);\r
+        hideGroup.setText("Filter");\r
+        label = new Label(filteringGroup, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label.setText("Use:");\r
+        Button useFilter = new Button(filteringGroup, support, SWT.CHECK);\r
+        useFilter.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used, false));\r
+        useFilter.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used));\r
+        label = new Label(filteringGroup, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label.setText("Fraction:");\r
+        TrackedText fraction = new TrackedText(filteringGroup, support, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fraction.getWidget());\r
+        fraction.setTextFactory(new DoublePropertyFactory2(JFreeChartResource.URIs.Plot,JFreeChartResource.URIs.Filter_fraction));\r
+        fraction.addModifyListener(new DoublePropertyModifier2(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_fraction));\r
+        fraction.setInputValidator(new DoubleValidator(true));\r
+        fraction.setColorProvider(new JFreeChartPropertyColorProvider(fraction.getResourceManager()));\r
     }\r
 \r
     /**\r
index cb721a587a17b6f374fd3165c7194ef1997d614a..9f72dc2bdae55b80eedfa0ead7069e6ae6ed7ea5 100644 (file)
@@ -29,6 +29,8 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;\r
 import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;\r
+import org.simantics.jfreechart.chart.properties.DoublePropertyFactory2;\r
+import org.simantics.jfreechart.chart.properties.DoublePropertyModifier2;\r
 import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;\r
@@ -61,7 +63,7 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
         sc.setExpandVertical(true);\r
 \r
         composite = new Composite(sc, SWT.NONE);\r
-        GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().numColumns(3).margins(3, 3).applyTo(composite);\r
 \r
         // General properties\r
         Group general = new Group(composite, SWT.NONE);\r
@@ -151,6 +153,28 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
         hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));\r
         hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));\r
         \r
+        \r
+        Group filteringGroup = new Group(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(filteringGroup);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(filteringGroup);\r
+        hideGroup.setText("Filter");\r
+        label = new Label(filteringGroup, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label.setText("Use:");\r
+        Button useFilter = new Button(filteringGroup, support, SWT.CHECK);\r
+        useFilter.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used, false));\r
+        useFilter.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used));\r
+        label = new Label(filteringGroup, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label.setText("Fraction:");\r
+        TrackedText fraction = new TrackedText(filteringGroup, support, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fraction.getWidget());\r
+        fraction.setTextFactory(new DoublePropertyFactory2(JFreeChartResource.URIs.Plot,JFreeChartResource.URIs.Filter_fraction));\r
+        fraction.addModifyListener(new DoublePropertyModifier2(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_fraction));\r
+        fraction.setInputValidator(new DoubleValidator(true));\r
+        fraction.setColorProvider(new JFreeChartPropertyColorProvider(fraction.getResourceManager()));\r
+        \r
+        \r
         sc.setContent(composite);\r
         Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
         sc.setMinSize(size);\r