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%2FDoubleArrayCellVariable.java;h=8650fc8f91fdc8e87dd205f1dd34e6fa10a7183e;hp=d2aa76fffe2c56f3d653847817c70db29ad22ad9;hb=5c67a96d34fe904b8c4b0375cd08ff1d543bf369;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCellVariable.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCellVariable.java index d2aa76fff..8650fc8f9 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCellVariable.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/adapter/DoubleArrayCellVariable.java @@ -1,77 +1,77 @@ -package org.simantics.spreadsheet.graph.adapter; - -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.WriteGraph; -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.Variables; -import org.simantics.spreadsheet.Range; -import org.simantics.spreadsheet.common.cell.VariableCellEditor; -import org.simantics.spreadsheet.resource.SpreadsheetResource; -import org.simantics.spreadsheet.util.SpreadsheetUtils; - -public class DoubleArrayCellVariable extends ConstantChildVariable { - - public DoubleArrayCellVariable(Variable parent, String name, String[] properties, Binding[] bindings, Object ... values) { - super(parent, name, properties, bindings, values); - } - - @SuppressWarnings("unchecked") - protected T tryAdapt(ReadGraph graph, Class clazz) throws DatabaseException { - if(VariableCellEditor.class == clazz) { - return (T)new VariableCellEditor() { - - @Override - public void edit(WriteGraph graph, Variable cell, String text) throws DatabaseException { - - SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); - Resource configuration = cell.getPossibleRepresents(graph); - double[] data = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasDoubleArray, Bindings.DOUBLE_ARRAY); - if(data == null) return; - Integer width = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasWidth, Bindings.INTEGER); - if(width == null) return; - String baseLocation = graph.getPossibleRelatedValue(configuration, sr.HasLocation, Bindings.STRING); - if(baseLocation == null) return; - String editLocation = cell.getPossiblePropertyValue(graph, Variables.NAME); - - Range baseRange = SpreadsheetUtils.decodeCellAbsolute(baseLocation); - Range editRange = SpreadsheetUtils.decodeCellAbsolute(editLocation); - - int x = editRange.startColumn - baseRange.startColumn; - int y = editRange.startRow - baseRange.startRow; - - int height = data.length / width; - - if(x>=0 && x=0 && y T adapt(ReadGraph graph, Class clazz) throws DatabaseException { - T t = tryAdapt(graph, clazz); - return t != null ? t : super.adapt(graph, clazz); - } - - @Override - public T adaptPossible(ReadGraph graph, Class clazz) throws DatabaseException { - return tryAdapt(graph, clazz); - } - -} +package org.simantics.spreadsheet.graph.adapter; + +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.WriteGraph; +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.Variables; +import org.simantics.spreadsheet.Range; +import org.simantics.spreadsheet.Spreadsheets; +import org.simantics.spreadsheet.common.cell.VariableCellEditor; +import org.simantics.spreadsheet.resource.SpreadsheetResource; + +public class DoubleArrayCellVariable extends ConstantChildVariable { + + public DoubleArrayCellVariable(Variable parent, String name, String[] properties, Binding[] bindings, Object ... values) { + super(parent, name, properties, bindings, values); + } + + @SuppressWarnings("unchecked") + protected T tryAdapt(ReadGraph graph, Class clazz) throws DatabaseException { + if(VariableCellEditor.class == clazz) { + return (T)new VariableCellEditor() { + + @Override + public void edit(WriteGraph graph, Variable cell, String text) throws DatabaseException { + + SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); + Resource configuration = cell.getPossibleRepresents(graph); + double[] data = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasDoubleArray, Bindings.DOUBLE_ARRAY); + if(data == null) return; + Integer width = graph.getPossibleRelatedValue(configuration, sr.DoubleArrayCell_HasWidth, Bindings.INTEGER); + if(width == null) return; + String baseLocation = graph.getPossibleRelatedValue(configuration, sr.HasLocation, Bindings.STRING); + if(baseLocation == null) return; + String editLocation = cell.getPossiblePropertyValue(graph, Variables.NAME); + + Range baseRange = Spreadsheets.decodeCellAbsolute(baseLocation); + Range editRange = Spreadsheets.decodeCellAbsolute(editLocation); + + int x = editRange.startColumn - baseRange.startColumn; + int y = editRange.startRow - baseRange.startRow; + + int height = data.length / width; + + if(x>=0 && x=0 && y T adapt(ReadGraph graph, Class clazz) throws DatabaseException { + T t = tryAdapt(graph, clazz); + return t != null ? t : super.adapt(graph, clazz); + } + + @Override + public T adaptPossible(ReadGraph graph, Class clazz) throws DatabaseException { + return tryAdapt(graph, clazz); + } + +}