X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Ffunction%2FAll.java;h=0f6f422eb982c8229ce37fa200b66c8e8ba70a43;hb=e5871be84f8ba53a1c80be728bcfb67231c29279;hp=9b0f708df8c11628fbb1c13af1dabf76bf46b669;hpb=f56d8b5c5225ef421009dadca4cec0ac56aef019;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java index 9b0f708df..0f6f422eb 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/function/All.java @@ -55,6 +55,7 @@ import org.simantics.spreadsheet.CellEditor; import org.simantics.spreadsheet.ClientModel; import org.simantics.spreadsheet.Range; import org.simantics.spreadsheet.Spreadsheets; +import org.simantics.spreadsheet.Transaction; import org.simantics.spreadsheet.graph.SpreadsheetGraphUtils; import org.simantics.spreadsheet.graph.SpreadsheetNodeManager; import org.simantics.spreadsheet.graph.SpreadsheetSessionManager; @@ -113,7 +114,6 @@ public class All { @Override public void setValue(WriteGraph graph, Variable context, Object value, Binding binding) throws DatabaseException { - System.out.println("contentValueAccessor.context=" + context.getURI(graph)); if(value instanceof String) { // Expressions are given as string @@ -134,7 +134,6 @@ public class All { } else { Variable cell = context.getParent(graph); - System.out.println("setValue : " + cell.getURI(graph)); String formula = text.substring(1); @@ -153,7 +152,7 @@ public class All { Variant v = new Variant(ExcelFormula.BINDING, new ExcelFormula(formula)); Layer0Utils.claimLiteral(graph, cell.getRepresents(graph), SHEET.Cell_content, SHEET.Cell_content_Inverse, Layer0.getInstance(graph).Variant, v, Bindings.VARIANT); - + } } else { @@ -195,9 +194,6 @@ public class All { private void setValueToEngine(WriteGraph graph, Variable cell, Variable context, Object value, Binding binding) throws DatabaseException { Variable sheet = cell.getParent(graph); - if(Bindings.STRING.equals(binding) && !(value instanceof String)) - System.err.println("asd"); - SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); while(!sheet.getType(graph).equals(SHEET.Spreadsheet)) { @@ -212,7 +208,7 @@ public class All { StandardRealm realm = SpreadsheetSessionManager.getInstance().getOrCreateRealm(graph, sessionName); SpreadsheetBook book = realm.getEngine(); SpreadsheetCell sc = book.get(sheet.getName(graph), r.startRow, r.startColumn); - sc.setContent(value); + //sc.setContent(value); realm.asyncExec(new Runnable() { @Override @@ -433,17 +429,11 @@ public class All { return super.getVariable(graph, context, name); -// TMap map = new THashMap(); -// getVariables(graph, context, map); -// return map.get(name); - } @Override public Map getVariables(ReadGraph graph, Variable context, Map map) throws DatabaseException { - System.err.println("getVariables " + context.getURI(graph)); - if(ProxyVariables.isProxy(graph, context)) return StandardChildDomainChildren.getStandardChildDomainChildVariables(graph, context, Collections.emptyMap(), map); @@ -571,88 +561,96 @@ public class All { } }; + + public static class DefaultSheetCellEditor extends GraphCellEditorAdapter { + + final public Variable sheet; + + public DefaultSheetCellEditor(Variable sheet, Variable cell) { + super(cell); + this.sheet = sheet; + } + @Override + public void edit(final Transaction transaction, final String location, final String property, final T value, final Binding binding, Consumer callback) { - @SCLValue(type = "ReadGraph -> Resource -> Variable -> CellEditor") - public static CellEditor defaultSheetCellEditor(ReadGraph graph, Resource resource, final Variable context_) throws DatabaseException { - - final Variable sheet = context_.getParent(graph); - - return new GraphCellEditorAdapter(null) { + SpreadsheetUtils.schedule(transaction, new WriteRequest() { - @Override - public void edit(final Transaction transaction, final String location, final String property, final T value, final Binding binding, Consumer callback) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + CellEditor editor = getPossibleCellEditor(graph, location, value == null ? null : new Variant(binding, value)); + if (editor == null) + return; + editor.edit(transaction, location, property, value, binding, callback); + } + }); - SpreadsheetUtils.schedule(transaction, new WriteRequest() { + } - @Override - public void perform(WriteGraph graph) throws DatabaseException { - CellEditor editor = getPossibleCellEditor(graph, location, value == null ? null : new Variant(binding, value)); - if (editor == null) - return; - editor.edit(transaction, location, property, value, binding, callback); - } - }); + @Override + public void edit(final Transaction transaction, final String location, final Variant value, Consumer callback) { + SpreadsheetUtils.schedule(transaction, new WriteRequest() { - } + @Override + public void perform(WriteGraph graph) throws DatabaseException { + CellEditor editor = getPossibleCellEditor(graph, location, value); + if (editor == null) + return; + editor.edit(transaction, location, value, callback); + } + }); - @Override - public void edit(final Transaction transaction, final String location, final Variant value, Consumer callback) { - SpreadsheetUtils.schedule(transaction, new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - CellEditor editor = getPossibleCellEditor(graph, location, value); - if (editor == null) - return; - editor.edit(transaction, location, value, callback); - } - }); + } - } + private CellEditor getPossibleCellEditor(WriteGraph graph, String location, Variant value) throws DatabaseException { + SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); + Range range = Spreadsheets.decodePossibleCellAbsolute(location); + if(range == null) return null; //No editor found - private CellEditor getPossibleCellEditor(WriteGraph graph, String location, Variant value) throws DatabaseException { - SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); - Range range = Spreadsheets.decodePossibleCellAbsolute(location); - if(range == null) return null; //No editor found - - List cells = SpreadsheetGraphUtils.possibleConfigurationCellVariables(graph, sheet, range); - if (cells.isEmpty()) { - if (value == null) { - return null; - } else { - cells = SpreadsheetGraphUtils.getOrCreateConfigurationCellVariables(graph, sheet, range); - } + List cells = SpreadsheetGraphUtils.possibleConfigurationCellVariables(graph, sheet, range); + if (cells.isEmpty()) { + if (value == null) { + return null; + } else { + cells = SpreadsheetGraphUtils.getOrCreateConfigurationCellVariables(graph, sheet, range); } - if (cells.size() != 1) - throw new DatabaseException("Can edit only one cell at a time!"); - - return cells.iterator().next().getPropertyValue(graph, SHEET.cellEditor); } + if (cells.size() != 1) + throw new DatabaseException("Can edit only one cell at a time!"); - @Override - public void copy(final Transaction transaction, final String location, final MutableVariant variant, Consumer callback) { + return cells.iterator().next().getPropertyValue(graph, SHEET.cellEditor); + } - SpreadsheetUtils.schedule(transaction, new WriteRequest() { + @Override + public void copy(final Transaction transaction, final String location, final MutableVariant variant, Consumer callback) { + + SpreadsheetUtils.schedule(transaction, new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { + @Override + public void perform(WriteGraph graph) throws DatabaseException { - SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); - Variable variable = sheet.getPossibleChild(graph, location); - if(variable != null) { - CellEditor editor = variable.getPossiblePropertyValue(graph, SHEET.cellEditor); - if(editor != null) { - editor.copy(transaction, location, variant, null); - } + SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); + Variable variable = sheet.getPossibleChild(graph, location); + if(variable != null) { + CellEditor editor = variable.getPossiblePropertyValue(graph, SHEET.cellEditor); + if(editor != null) { + editor.copy(transaction, location, variant, null); } } + } - }); + }); - } + } + + } - }; + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> CellEditor") + public static CellEditor defaultSheetCellEditor(ReadGraph graph, Resource resource, final Variable context_) throws DatabaseException { + + final Variable sheet = context_.getParent(graph); + return new DefaultSheetCellEditor(sheet, null); } @@ -716,7 +714,6 @@ public class All { if (style != null) styleId = graph.getPossibleRelatedValue(style, SR.Style_id, Bindings.INTEGER); if (styleId == null) { - System.err.println("Style " + style + " has no ID or either cell "+ repr + " has no style attached to it !!"); styleId = SpreadsheetStyle.empty().getStyleId(); } @@ -751,9 +748,7 @@ public class All { @SCLValue(type = "ReadGraph -> Resource -> Variable -> CellEditor") public static CellEditor textCellEditor(ReadGraph graph, Resource resource, final Variable context_) throws DatabaseException { - System.out.println("Context URI : " + context_.getURI(graph)); Variable cells = context_.getParent(graph); - System.out.println("Cell URI : " + cells.getURI(graph)); return new GraphCellEditorAdapter(cells) { @@ -777,7 +772,6 @@ public class All { if (runCell != null) runCell.setPropertyValue(graph, SHEET.Cell_content, value, Bindings.VARIANT); } else if(ClientModel.CONTENT_EXPRESSION.equals(property)) { - System.err.println("cell: " + cell.getURI(graph)); cell.setPropertyValue(graph, SHEET.Cell_content, value, Bindings.STRING); Variable runCell = null; Object transactionContext = transaction.getContext(); @@ -903,7 +897,6 @@ public class All { } if (runCell != null) { - System.out.println("All.edit " + runCell.getURI(graph)); runCell.setPropertyValue(graph, SHEET.Cell_content, value, Bindings.VARIANT); } } @@ -920,7 +913,6 @@ public class All { runCell = Variables.switchRealization(graph, cell, context.getRepresents(graph), context); } - //Variant content = cell.getPropertyValue(graph, SHEET.Cell_content, Bindings.VARIANT); Object object = cell.getPropertyValue(graph, SHEET.Cell_content); Variant content = null; if (object instanceof Variant) {