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.diagram.adapter;
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.common.request.UniqueRead;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.procedure.AsyncProcedure;
20 import org.simantics.g2d.canvas.ICanvasContext;
21 import org.simantics.g2d.diagram.IDiagram;
22 import org.simantics.g2d.element.ElementClass;
23 import org.simantics.g2d.element.IElement;
26 * A synchronous graph request wrapper for {@link ElementFactory} and
27 * {@link ElementFactoryAdapter}. Using it will provide simpler but slower
30 * @author Tuukka Lehtonen
32 public class SyncElementFactory extends ElementFactoryAdapter {
35 public void create(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram,
36 final Resource elementType, final AsyncProcedure<ElementClass> procedure) {
37 graph.asyncRequest(new UniqueRead<ElementClass>() {
39 public ElementClass perform(ReadGraph graph) throws DatabaseException {
40 return create(graph, canvas, diagram, elementType);
46 public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram,
47 final Resource elementResource, final IElement element, final AsyncProcedure<IElement> procedure) {
48 graph.asyncRequest(new UniqueRead<IElement>() {
50 public IElement perform(ReadGraph graph) throws DatabaseException {
51 if(isOk(graph, elementResource))
52 load(graph, canvas, diagram, elementResource, element);
58 public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)
59 throws DatabaseException {
60 throw new UnsupportedOperationException("This method should be implemented by subclass " + getClass().getName());
63 public boolean isOk(ReadGraph graph, Resource elementResource) throws DatabaseException {
64 return graph.hasStatement(elementResource);
67 public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element)
68 throws DatabaseException {
69 throw new UnsupportedOperationException("This method should be implemented by subclass " + getClass().getName());