]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/query/TrendSpecQuery.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / query / TrendSpecQuery.java
index f84cb9c59fbe3bfd423c8ddf4f4d6fcc6214a4d3..fbbac7c9a9c1757198626751bee17e5e068b8087 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
- * in 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.charts.query;\r
-\r
-import java.util.UUID;\r
-\r
-import org.simantics.charts.ontology.ChartResource;\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.BinaryRead;\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.trend.configuration.TrendItem;\r
-import org.simantics.trend.configuration.TrendSpec;\r
-import org.simantics.trend.configuration.ViewProfile;\r
-import org.simantics.trend.configuration.YAxisMode;\r
-\r
-/**\r
- * This query reads trend configuration (Resource) and returns TrendSpec.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class TrendSpecQuery extends BinaryRead<UUID, Resource, TrendSpec> {\r
-\r
-    public TrendSpecQuery(UUID id, Resource resource) {\r
-        super(id, resource);\r
-    }\r
-\r
-    @Override\r
-    public TrendSpec perform(ReadGraph graph) throws DatabaseException {\r
-        Resource chart = parameter2;\r
-\r
-        ChartResource CHART = ChartResource.getInstance(graph);\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        \r
-        TrendSpec spec = new TrendSpec();\r
-        spec.init();\r
-        if ( !graph.hasStatement(chart) ) return spec;\r
-        spec.name = graph.getPossibleRelatedValue(chart, L0.HasName, Bindings.STRING);\r
-        if (spec.name == null)\r
-            spec.name = "Unnamed Chart";\r
-\r
-        spec.axisMode = YAxisMode.MultiAxis;\r
-        Resource axisMode = graph.getPossibleObject(chart, CHART.Chart_YAxisMode);\r
-        if (CHART.YAxisMode_SingleAxis.equals(axisMode))\r
-            spec.axisMode = YAxisMode.SingleAxis;\r
-        else if (CHART.YAxisMode_MultiAxis.equals(axisMode))\r
-            spec.axisMode = YAxisMode.MultiAxis;\r
-        \r
-        readProfile(graph, chart, spec.viewProfile);\r
-\r
-        for (Resource plot : graph.syncRequest(new ObjectsWithType(chart, L0.ConsistsOf, CHART.Chart_Item))) {\r
-               TrendItem item = graph.sync( new TrendItemQuery(plot) );\r
-//             if ( item.subscriptionId.equals("") ) continue;\r
-            spec.items.add( item );\r
-        }\r
-\r
-        spec.sortItems();\r
-        return spec;\r
-    }\r
-\r
-    private void readProfile(ReadGraph graph, Resource profile, ViewProfile viewProfile) throws DatabaseException {\r
-        viewProfile.profileName = "Custom Profile";\r
-        viewProfile.showMilestones = false;\r
-//        viewProfile.timeWindow.timeWindowStart = 0.0;\r
-//        viewProfile.timeWindow.timeWindowLength = 60.0;\r
-        viewProfile.timeWindow.timeWindowIncrement = 50.0;\r
-\r
-        if (profile != null) {\r
-            Layer0 L0 = Layer0.getInstance(graph);\r
-            ChartResource CHART = ChartResource.getInstance(graph);\r
-            String pn = graph.getPossibleRelatedValue(profile, L0.HasName);\r
-            if (pn != null)\r
-                viewProfile.profileName = pn;\r
-\r
-            viewProfile.showMilestones = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_ShowMilestones, Bindings.BOOLEAN) );\r
-            viewProfile.showGrid       = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_showGrid, Bindings.BOOLEAN) );\r
-\r
-            Double windowStart = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowStart, Double.class);\r
-            if (windowStart != null && !Double.isNaN(windowStart))\r
-                viewProfile.timeWindow.timeWindowStart = windowStart;\r
-            Double windowLength = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowLength, Double.class);\r
-            if (windowLength != null)\r
-                viewProfile.timeWindow.timeWindowLength = windowLength;\r
-            Double windowIncrement = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowIncrement, Double.class);\r
-            if (windowIncrement != null)\r
-                viewProfile.timeWindow.timeWindowIncrement = windowIncrement;\r
-\r
-            Boolean trackExperimentTime = graph.getPossibleRelatedValue(profile, CHART.Chart_trackExperimentTime, Bindings.BOOLEAN);\r
-            if (trackExperimentTime != null)\r
-                viewProfile.trackExperimentTime = trackExperimentTime;\r
-            double[] valueViewPosition = graph.getPossibleRelatedValue(profile, CHART.Chart_valueViewPosition, Bindings.DOUBLE_ARRAY);\r
-            if (valueViewPosition != null && valueViewPosition.length >= 2) {\r
-                viewProfile.valueViewPositionX = valueViewPosition[0];\r
-                viewProfile.valueViewPositionY = valueViewPosition[1];\r
-            }\r
-\r
-            float[] bgColor = graph.getPossibleRelatedValue(profile, CHART.Chart_backgroundColor, Bindings.FLOAT_ARRAY);\r
-            if (bgColor != null && bgColor.length >= 3) {\r
-                viewProfile.backgroundColor = bgColor;\r
-            }\r
-\r
-            float[] gridColor = graph.getPossibleRelatedValue(profile, CHART.Chart_gridColor, Bindings.FLOAT_ARRAY);\r
-            if (gridColor != null && gridColor.length >= 3) {\r
-                viewProfile.gridColor = gridColor;\r
-            }\r
-        }\r
-    }\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.charts.query;
+
+import java.util.UUID;
+
+import org.simantics.charts.ontology.ChartResource;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.BinaryRead;
+import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.trend.configuration.TrendItem;
+import org.simantics.trend.configuration.TrendSpec;
+import org.simantics.trend.configuration.ViewProfile;
+import org.simantics.trend.configuration.YAxisMode;
+
+/**
+ * This query reads trend configuration (Resource) and returns TrendSpec.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class TrendSpecQuery extends BinaryRead<UUID, Resource, TrendSpec> {
+
+    public TrendSpecQuery(UUID id, Resource resource) {
+        super(id, resource);
+    }
+
+    @Override
+    public TrendSpec perform(ReadGraph graph) throws DatabaseException {
+        Resource chart = parameter2;
+
+        ChartResource CHART = ChartResource.getInstance(graph);
+        Layer0 L0 = Layer0.getInstance(graph);
+        
+        TrendSpec spec = new TrendSpec();
+        spec.init();
+        if ( !graph.hasStatement(chart) ) return spec;
+        spec.name = graph.getPossibleRelatedValue(chart, L0.HasName, Bindings.STRING);
+        if (spec.name == null)
+            spec.name = "Unnamed Chart";
+
+        spec.axisMode = YAxisMode.MultiAxis;
+        Resource axisMode = graph.getPossibleObject(chart, CHART.Chart_YAxisMode);
+        if (CHART.YAxisMode_SingleAxis.equals(axisMode))
+            spec.axisMode = YAxisMode.SingleAxis;
+        else if (CHART.YAxisMode_MultiAxis.equals(axisMode))
+            spec.axisMode = YAxisMode.MultiAxis;
+        
+        readProfile(graph, chart, spec.viewProfile);
+
+        for (Resource plot : graph.syncRequest(new ObjectsWithType(chart, L0.ConsistsOf, CHART.Chart_Item))) {
+               TrendItem item = graph.sync( new TrendItemQuery(plot) );
+//             if ( item.subscriptionId.equals("") ) continue;
+            spec.items.add( item );
+        }
+
+        spec.sortItems();
+        return spec;
+    }
+
+    private void readProfile(ReadGraph graph, Resource profile, ViewProfile viewProfile) throws DatabaseException {
+        viewProfile.profileName = "Custom Profile";
+        viewProfile.showMilestones = false;
+//        viewProfile.timeWindow.timeWindowStart = 0.0;
+//        viewProfile.timeWindow.timeWindowLength = 60.0;
+        viewProfile.timeWindow.timeWindowIncrement = 50.0;
+
+        if (profile != null) {
+            Layer0 L0 = Layer0.getInstance(graph);
+            ChartResource CHART = ChartResource.getInstance(graph);
+            String pn = graph.getPossibleRelatedValue(profile, L0.HasName);
+            if (pn != null)
+                viewProfile.profileName = pn;
+
+            viewProfile.showMilestones = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_ShowMilestones, Bindings.BOOLEAN) );
+            viewProfile.showGrid       = Boolean.TRUE.equals( graph.getPossibleRelatedValue(profile, CHART.Chart_showGrid, Bindings.BOOLEAN) );
+
+            Double windowStart = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowStart, Double.class);
+            if (windowStart != null && !Double.isNaN(windowStart))
+                viewProfile.timeWindow.timeWindowStart = windowStart;
+            Double windowLength = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowLength, Double.class);
+            if (windowLength != null)
+                viewProfile.timeWindow.timeWindowLength = windowLength;
+            Double windowIncrement = graph.getPossibleRelatedAdapter(profile, CHART.Chart_TimeWindowIncrement, Double.class);
+            if (windowIncrement != null)
+                viewProfile.timeWindow.timeWindowIncrement = windowIncrement;
+
+            Boolean trackExperimentTime = graph.getPossibleRelatedValue(profile, CHART.Chart_trackExperimentTime, Bindings.BOOLEAN);
+            if (trackExperimentTime != null)
+                viewProfile.trackExperimentTime = trackExperimentTime;
+            double[] valueViewPosition = graph.getPossibleRelatedValue(profile, CHART.Chart_valueViewPosition, Bindings.DOUBLE_ARRAY);
+            if (valueViewPosition != null && valueViewPosition.length >= 2) {
+                viewProfile.valueViewPositionX = valueViewPosition[0];
+                viewProfile.valueViewPositionY = valueViewPosition[1];
+            }
+
+            float[] bgColor = graph.getPossibleRelatedValue(profile, CHART.Chart_backgroundColor, Bindings.FLOAT_ARRAY);
+            if (bgColor != null && bgColor.length >= 3) {
+                viewProfile.backgroundColor = bgColor;
+            }
+
+            float[] gridColor = graph.getPossibleRelatedValue(profile, CHART.Chart_gridColor, Bindings.FLOAT_ARRAY);
+            if (gridColor != null && gridColor.length >= 3) {
+                viewProfile.gridColor = gridColor;
+            }
+        }
+    }
+
 }
\ No newline at end of file