X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fcreator%2FCellCreatorBase.java.keep;fp=bundles%2Forg.simantics.spreadsheet.graph%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fgraph%2Fcreator%2FCellCreatorBase.java.keep;h=1539917e8889730220cbe200de4f68b6b7407b45;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=03874bdae545dc630b38c4e18196096982736556;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/creator/CellCreatorBase.java.keep b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/creator/CellCreatorBase.java.keep index 03874bdae..1539917e8 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/creator/CellCreatorBase.java.keep +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/creator/CellCreatorBase.java.keep @@ -1,77 +1,77 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.spreadsheet.graph.creator; - -import java.util.Collection; -import java.util.Collections; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.adapter.AdaptException; -import org.simantics.databoard.binding.Binding; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.spreadsheet.ModelCellManager.CellCreationData; -import org.simantics.spreadsheet.common.cell.Parsers; -import org.simantics.spreadsheet.graph.request.Columns; -import org.simantics.spreadsheet.graph.request.Rows; -import org.simantics.spreadsheet.graph.request.RowsColumnsIndex; - -abstract public class CellCreatorBase implements GraphCellCreator { - - final protected Resource realization; - - public CellCreatorBase(Resource realization) { - this.realization = realization; - } - - protected T getProperty(CellCreationData datum, String property, Binding binding) throws DatabaseException { - - try { - return (T)datum.properties.get(Parsers.EXPRESSION_PROPERTY).getValue(Bindings.STRING); - } catch (AdaptException e) { - throw new DatabaseException(e); - } - - } - - public void create(WriteGraph graph, CellCreationData cell) throws DatabaseException { - - create(graph, Collections.singleton(cell)); - - } - - public void create(WriteGraph graph, Collection data) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - - int maxRow = 0; - int maxColumn = 0; - for(CellCreationData datum : data) { - maxRow = Math.max(maxRow, datum.row); - maxColumn = Math.max(maxColumn, datum.column); - } - - Resource spreadsheet = graph.getPossibleObject(realization, l0.Represents); - - RowsColumnsIndex rowIndex = graph.syncRequest(new Rows(spreadsheet)); - RowsColumnsIndex columnIndex = graph.syncRequest(new Columns(spreadsheet)); - rowIndex = rowIndex.copy(); - columnIndex = columnIndex.copy(); - rowIndex.ensureIndex(graph, maxRow); - columnIndex.ensureIndex(graph, maxColumn); - - create(graph, rowIndex, columnIndex, data); - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.spreadsheet.graph.creator; + +import java.util.Collection; +import java.util.Collections; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.adapter.AdaptException; +import org.simantics.databoard.binding.Binding; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.spreadsheet.ModelCellManager.CellCreationData; +import org.simantics.spreadsheet.common.cell.Parsers; +import org.simantics.spreadsheet.graph.request.Columns; +import org.simantics.spreadsheet.graph.request.Rows; +import org.simantics.spreadsheet.graph.request.RowsColumnsIndex; + +abstract public class CellCreatorBase implements GraphCellCreator { + + final protected Resource realization; + + public CellCreatorBase(Resource realization) { + this.realization = realization; + } + + protected T getProperty(CellCreationData datum, String property, Binding binding) throws DatabaseException { + + try { + return (T)datum.properties.get(Parsers.EXPRESSION_PROPERTY).getValue(Bindings.STRING); + } catch (AdaptException e) { + throw new DatabaseException(e); + } + + } + + public void create(WriteGraph graph, CellCreationData cell) throws DatabaseException { + + create(graph, Collections.singleton(cell)); + + } + + public void create(WriteGraph graph, Collection data) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(graph); + + int maxRow = 0; + int maxColumn = 0; + for(CellCreationData datum : data) { + maxRow = Math.max(maxRow, datum.row); + maxColumn = Math.max(maxColumn, datum.column); + } + + Resource spreadsheet = graph.getPossibleObject(realization, l0.Represents); + + RowsColumnsIndex rowIndex = graph.syncRequest(new Rows(spreadsheet)); + RowsColumnsIndex columnIndex = graph.syncRequest(new Columns(spreadsheet)); + rowIndex = rowIndex.copy(); + columnIndex = columnIndex.copy(); + rowIndex.ensureIndex(graph, maxRow); + columnIndex.ensureIndex(graph, maxColumn); + + create(graph, rowIndex, columnIndex, data); + + } + +}