X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fadapter%2FDoubleArrayCells.java;h=a6db85a5e45db34cfe8f9b74a4bf64460ded52e0;hp=a6733ac55144025d3526742a6bb54bb16a4d023d;hb=5c67a96d34fe904b8c4b0375cd08ff1d543bf369;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCells.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCells.java index a6733ac55..a6db85a5e 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCells.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCells.java @@ -1,83 +1,82 @@ -package org.simantics.spreadsheet.graph.adapter; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Datatypes; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.ConstantChildVariable; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.VariableFactory; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.spreadsheet.SheetVariables; -import org.simantics.spreadsheet.resource.SpreadsheetResource; -import org.simantics.spreadsheet.util.SpreadsheetUtils; -import org.simantics.utils.datastructures.datatype.RGBInt8; - -public class DoubleArrayCells implements VariableFactory { - - private Binding RGB = Bindings.getBindingUnchecked(RGBInt8.class); -// private Datatype RGB = Datatypes.getDatatypeUnchecked(RGBInt8.class); - - private Resource configuration; - - public DoubleArrayCells(Resource configuration) { - this.configuration = configuration; - } - - final String[] propertyNames = { SheetVariables.CONTENT, SheetVariables.FOREGROUND, SheetVariables.BACKGROUND, Variables.LABEL, "immutable" }; - final Binding[] bindings = { Bindings.VARIANT, RGB, RGB, Bindings.STRING, Bindings.BOOLEAN }; - - private Collection toVariables(ReadGraph graph, Variable variable, double[] data, int width) throws DatabaseException { - - SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); - String location = graph.getPossibleRelatedValue(configuration, sr.HasLocation, Bindings.STRING); - if(location == null) return Collections.emptyList(); - - int rows = data.length / width; - - RGBInt8 fore = new RGBInt8(255, 255, 255); - RGBInt8 back = new RGBInt8(80, 130, 190); - - ArrayList result = new ArrayList(); - for(int offset=0,i=0;i error(ReadGraph graph, Variable variable, String message) throws DatabaseException { - - SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); - String location = graph.getPossibleRelatedValue(configuration, sr.HasLocation, Bindings.STRING); - if(location == null) return Collections.emptyList(); - - return Collections.singletonList(new ConstantChildVariable(variable, location, propertyNames, bindings, new Object[] { message })); - - } - - @Override - public Collection evaluate(ReadGraph graph, Variable variable) throws DatabaseException { - - SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); - double[] data = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasDoubleArray, Bindings.DOUBLE_ARRAY); - if(data == null) return error(graph, variable, "No double array data."); - Integer width = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasWidth, Bindings.INTEGER); - if(width == null) return error(graph, variable, "Invalid width for double array."); - - return toVariables(graph, variable, data, width); - - } - -} +package org.simantics.spreadsheet.graph.adapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.ConstantChildVariable; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.VariableFactory; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.spreadsheet.SheetVariables; +import org.simantics.spreadsheet.Spreadsheets; +import org.simantics.spreadsheet.resource.SpreadsheetResource; +import org.simantics.utils.datastructures.datatype.RGBInt8; + +public class DoubleArrayCells implements VariableFactory { + + private Binding RGB = Bindings.getBindingUnchecked(RGBInt8.class); +// private Datatype RGB = Datatypes.getDatatypeUnchecked(RGBInt8.class); + + private Resource configuration; + + public DoubleArrayCells(Resource configuration) { + this.configuration = configuration; + } + + final String[] propertyNames = { SheetVariables.CONTENT, SheetVariables.FOREGROUND, SheetVariables.BACKGROUND, Variables.LABEL, "immutable" }; + final Binding[] bindings = { Bindings.VARIANT, RGB, RGB, Bindings.STRING, Bindings.BOOLEAN }; + + private Collection toVariables(ReadGraph graph, Variable variable, double[] data, int width) throws DatabaseException { + + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + String location = graph.getPossibleRelatedValue(configuration, sr.HasLocation, Bindings.STRING); + if(location == null) return Collections.emptyList(); + + int rows = data.length / width; + + RGBInt8 fore = new RGBInt8(255, 255, 255); + RGBInt8 back = new RGBInt8(80, 130, 190); + + ArrayList result = new ArrayList(); + for(int offset=0,i=0;i error(ReadGraph graph, Variable variable, String message) throws DatabaseException { + + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + String location = graph.getPossibleRelatedValue(configuration, sr.HasLocation, Bindings.STRING); + if(location == null) return Collections.emptyList(); + + return Collections.singletonList(new ConstantChildVariable(variable, location, propertyNames, bindings, new Object[] { message })); + + } + + @Override + public Collection evaluate(ReadGraph graph, Variable variable) throws DatabaseException { + + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + double[] data = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasDoubleArray, Bindings.DOUBLE_ARRAY); + if(data == null) return error(graph, variable, "No double array data."); + Integer width = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasWidth, Bindings.INTEGER); + if(width == null) return error(graph, variable, "Invalid width for double array."); + + return toVariables(graph, variable, data, width); + + } + +}