X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fadapter%2FStringArrayCells.java;h=b75142b3462c262ed5bd0f884ee06f7794b158f2;hb=82ed7c74;hp=1669fe1eef3560e187a49f7189e556edf2922e30;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/StringArrayCells.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/StringArrayCells.java index 1669fe1ee..b75142b34 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/StringArrayCells.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/StringArrayCells.java @@ -1,73 +1,73 @@ -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.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.resource.SpreadsheetResource; -import org.simantics.spreadsheet.util.SpreadsheetUtils; - -public class StringArrayCells implements VariableFactory { - - private Resource configuration; - - public StringArrayCells(Resource configuration) { - this.configuration = configuration; - } - - final String[] propertyNames = { Variables.LABEL, "immutable" }; - final Binding[] bindings = { Bindings.STRING, Bindings.BOOLEAN }; - - private Collection toVariables(ReadGraph graph, Variable variable, String[] 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; - - 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); - String[] data = graph.getPossibleRelatedValue(configuration, sr.StringArrayCell_HasStringArray, Bindings.STRING_ARRAY); - if(data == null) return error(graph, variable, "No string array data."); - Integer width = graph.getPossibleRelatedValue(configuration, sr.StringArrayCell_HasWidth, Bindings.INTEGER); - if(width == null) return error(graph, variable, "Invalid width for string 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.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.resource.SpreadsheetResource; +import org.simantics.spreadsheet.util.SpreadsheetUtils; + +public class StringArrayCells implements VariableFactory { + + private Resource configuration; + + public StringArrayCells(Resource configuration) { + this.configuration = configuration; + } + + final String[] propertyNames = { Variables.LABEL, "immutable" }; + final Binding[] bindings = { Bindings.STRING, Bindings.BOOLEAN }; + + private Collection toVariables(ReadGraph graph, Variable variable, String[] 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; + + 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); + String[] data = graph.getPossibleRelatedValue(configuration, sr.StringArrayCell_HasStringArray, Bindings.STRING_ARRAY); + if(data == null) return error(graph, variable, "No string array data."); + Integer width = graph.getPossibleRelatedValue(configuration, sr.StringArrayCell_HasWidth, Bindings.INTEGER); + if(width == null) return error(graph, variable, "Invalid width for string array."); + + return toVariables(graph, variable, data, width); + + } + +}