1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.spreadsheet.graph.creator;
14 import java.util.Collection;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.layer0.Layer0;
21 import org.simantics.spreadsheet.ModelCellManager.CellCreationData;
22 import org.simantics.spreadsheet.common.cell.Parsers;
23 import org.simantics.spreadsheet.graph.request.RowsColumnsIndex;
24 import org.simantics.spreadsheet.resource.SpreadsheetResource;
26 public class TextBlockCellCreator extends CellCreatorBase {
28 public TextBlockCellCreator(Resource realization) {
33 public void create(WriteGraph graph, final RowsColumnsIndex rowIndex, final RowsColumnsIndex columnIndex, final Collection<CellCreationData> data) throws DatabaseException {
35 Layer0 l0 = Layer0.getInstance(graph);
36 SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
38 Resource spreadsheet = graph.getPossibleObject(realization, l0.Represents);
40 for(CellCreationData datum : data) {
41 Resource newCell = graph.newResource();
42 graph.claim(newCell, l0.InstanceOf, null, sr.TextBlockCell);
43 String label = getProperty(datum, Parsers.LABEL_PROPERTY, Bindings.STRING);
44 Resource rowResource = rowIndex.getResource(datum.row);
45 Resource columnResource = columnIndex.getResource(datum.column);
46 graph.claim(newCell, sr.HasRow, sr.RowOf, rowResource);
47 graph.claim(newCell, sr.HasColumn, sr.ColumnOf, columnResource);
48 graph.addLiteral(newCell, sr.Label, sr.LabelOf, l0.String, label, Bindings.STRING);
49 graph.claim(spreadsheet, l0.ConsistsOf, l0.PartOf, newCell);