1 /*******************************************************************************
\r
2 * Copyright (c) 2007- VTT Technical Research Centre of Finland.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.modeling.ui.diagram;
\r
13 import java.awt.geom.AffineTransform;
\r
15 import org.simantics.db.AsyncReadGraph;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.procedure.AsyncProcedure;
\r
18 import org.simantics.diagram.adapter.ElementFactory;
\r
19 import org.simantics.diagram.synchronization.graph.BasicResources;
\r
20 import org.simantics.g2d.canvas.ICanvasContext;
\r
21 import org.simantics.g2d.diagram.IDiagram;
\r
22 import org.simantics.g2d.element.ElementClass;
\r
23 import org.simantics.g2d.element.ElementUtils;
\r
24 import org.simantics.g2d.element.IElement;
\r
25 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
\r
26 import org.simantics.spreadsheet.graph.GraphBackend;
\r
27 import org.simantics.spreadsheet.graph.SpreadsheetResource;
\r
28 import org.simantics.spreadsheet.ui.SimpleContainerTableModel;
\r
32 * TODO: recognize experiment disposal and reset monitor contents at that point
\r
34 public class SheetFactory implements ElementFactory {
\r
36 public static ElementClass createSheetClass(Resource elementType) {
\r
37 return SheetClass.create(null, null, null, 1.0, 1.0, new StaticObjectAdapter(elementType));
\r
41 public void getClass(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram,
\r
42 Resource resource, AsyncProcedure<ElementClass> procedure) {
\r
43 procedure.execute(graph, createSheetClass(graph.getSession().getService(SpreadsheetResource.class).SpreadsheetElement));
\r
47 public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram,
\r
48 Resource elementType, AsyncProcedure<ElementClass> procedure) {
\r
49 procedure.execute(graph, createSheetClass(graph.getSession().getService(SpreadsheetResource.class).SpreadsheetElement));
\r
53 public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram,
\r
54 Resource resource, final IElement element) {
\r
56 SpreadsheetResource sr = graph.getService(SpreadsheetResource.class);
\r
58 AffineTransform at = new AffineTransform();
\r
59 ElementUtils.setTransform(element, at);
\r
61 graph.forPossibleObject(resource, sr.HasSheet, new AsyncProcedure<Resource>() {
\r
64 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
65 throwable.printStackTrace();
\r
69 public void execute(AsyncReadGraph graph, Resource sheet) {
\r
71 GraphBackend backend = new GraphBackend(graph.getSession());
\r
73 SimpleContainerTableModel tableModel = new SimpleContainerTableModel(backend);
\r
75 element.setHint(SheetClass.KEY_MODEL, tableModel);
\r
76 element.setHint(SheetClass.KEY_TABLE_MODEL, tableModel);
\r
78 backend.load(sheet, tableModel);
\r