1 package org.simantics.charts.query;
3 import java.util.Arrays;
5 import org.simantics.charts.ontology.ChartResource;
6 import org.simantics.charts.ui.ChartData;
7 import org.simantics.charts.ui.ChartData.ItemKey;
8 import org.simantics.databoard.Bindings;
9 import org.simantics.db.Resource;
10 import org.simantics.db.WriteGraph;
11 import org.simantics.db.common.request.WriteRequest;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.layer0.Layer0;
14 import org.simantics.trend.configuration.YAxisMode;
16 public class ChartDataWrite extends WriteRequest {
21 public ChartDataWrite(Resource chart, ChartData data)
28 public void perform(WriteGraph g) throws DatabaseException {
30 Layer0 L0 = Layer0.getInstance(g);
31 ChartResource CHART = ChartResource.getInstance(g);
34 g.claimLiteral(chart, L0.HasName, data.name, Bindings.STRING);
37 if ( data.axisMode == YAxisMode.SingleAxis ) {
38 g.deny(chart, CHART.Chart_YAxisMode, CHART.YAxisMode_MultiAxis);
39 g.claim(chart, CHART.Chart_YAxisMode, CHART.YAxisMode_SingleAxis);
41 g.deny(chart, CHART.Chart_YAxisMode, CHART.YAxisMode_SingleAxis);
42 g.claim(chart, CHART.Chart_YAxisMode, CHART.YAxisMode_MultiAxis);
46 g.claimLiteral(chart, CHART.Chart_ShowMilestones, data.showMilestones, Bindings.BOOLEAN);
47 g.claimLiteral(chart, CHART.Chart_showGrid, data.showGrid, Bindings.BOOLEAN);
48 g.claimLiteral(chart, CHART.Chart_trackExperimentTime, data.trackExperimentTime, Bindings.BOOLEAN);
50 if ( data.timeIncrement!=null ) {
51 g.claimLiteral(chart, CHART.Chart_TimeWindowIncrement, data.timeIncrement, Bindings.DOUBLE);
53 g.deny(chart, CHART.Chart_TimeWindowIncrement);
56 if ( data.timeLength==null ) {
57 g.deny(chart, CHART.Chart_TimeWindowLength);
59 g.claimLiteral(chart, CHART.Chart_TimeWindowLength, data.timeLength, Bindings.DOUBLE);
61 if ( data.timeStart==null ) {
62 g.deny(chart, CHART.Chart_TimeWindowStart);
64 g.claimLiteral(chart, CHART.Chart_TimeWindowStart, data.timeStart, Bindings.DOUBLE);
67 if ( data.allItems != null && data.hiddenItems != null ) {
68 for (ItemKey item : data.allItems.keySet()) {
69 boolean shouldBeHidden = data.hiddenItems.contains(item);
70 Boolean isHidden = g.getRelatedValue(item.resource.getResource(), CHART.Chart_Item_hidden, Bindings.BOOLEAN);
71 if (shouldBeHidden != isHidden)
72 g.claimLiteral(item.resource.getResource(), CHART.Chart_Item_hidden, shouldBeHidden, Bindings.BOOLEAN);
76 if (data.backgroundColor1 == null) {
77 g.denyValue(chart, CHART.Chart_backgroundColor);
79 float[] oldValue = g.getPossibleRelatedValue(chart, CHART.Chart_backgroundColor, Bindings.FLOAT_ARRAY);
80 float[] newValue = data.backgroundGradient ? joinArrays(data.backgroundColor1, data.backgroundColor2) : data.backgroundColor1;
81 if (newValue != null && (oldValue == null || !Arrays.equals(oldValue, newValue))) {
82 g.claimLiteral(chart, CHART.Chart_backgroundColor, newValue, Bindings.FLOAT_ARRAY);
86 if (data.gridColor == null) {
87 g.denyValue(chart, CHART.Chart_gridColor);
89 float[] oldValue = g.getPossibleRelatedValue(chart, CHART.Chart_gridColor, Bindings.FLOAT_ARRAY);
90 if (data.gridColor != null && (oldValue == null || !Arrays.equals(oldValue, data.gridColor))) {
91 g.claimLiteral(chart, CHART.Chart_gridColor, data.gridColor, Bindings.FLOAT_ARRAY);
96 private static float[] joinArrays(float[] c1, float[] c2) {
97 int l1 = c1 != null ? c1.length : 0;
98 int l2 = c2 != null ? c2.length : 0;
100 float[] result = new float[l];
103 System.arraycopy(c1, 0, result, 0, l1);
107 System.arraycopy(c2, 0, result, i, l2);