X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FSyncElementFactory.java;h=5e9d2204dcdab61c881c1e5e07f215f8871bb5d6;hb=617b9475710b80a125597f222f9777224972ce72;hp=be03b91256295349d1f954e4900a47b2f3eb056d;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/SyncElementFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/SyncElementFactory.java index be03b9125..5e9d2204d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/SyncElementFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/SyncElementFactory.java @@ -1,72 +1,72 @@ -/******************************************************************************* - * 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.diagram.adapter; - -import org.simantics.db.AsyncReadGraph; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.procedure.AsyncProcedure; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.element.ElementClass; -import org.simantics.g2d.element.IElement; - -/** - * A synchronous graph request wrapper for {@link ElementFactory} and - * {@link ElementFactoryAdapter}. Using it will provide simpler but slower - * implementations. - * - * @author Tuukka Lehtonen - */ -public class SyncElementFactory extends ElementFactoryAdapter { - - @Override - public void create(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, - final Resource elementType, final AsyncProcedure procedure) { - graph.asyncRequest(new UniqueRead() { - @Override - public ElementClass perform(ReadGraph graph) throws DatabaseException { - return create(graph, canvas, diagram, elementType); - } - }, procedure); - } - - @Override - public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, - final Resource elementResource, final IElement element, final AsyncProcedure procedure) { - graph.asyncRequest(new UniqueRead() { - @Override - public IElement perform(ReadGraph graph) throws DatabaseException { - if(isOk(graph, elementResource)) - load(graph, canvas, diagram, elementResource, element); - return element; - } - }, procedure); - } - - public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType) - throws DatabaseException { - throw new UnsupportedOperationException(); - } - - public boolean isOk(ReadGraph graph, Resource elementResource) throws DatabaseException { - return graph.hasStatement(elementResource); - } - - public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element) - throws DatabaseException { - throw new UnsupportedOperationException(); - } - -} +/******************************************************************************* + * 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.diagram.adapter; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.IElement; + +/** + * A synchronous graph request wrapper for {@link ElementFactory} and + * {@link ElementFactoryAdapter}. Using it will provide simpler but slower + * implementations. + * + * @author Tuukka Lehtonen + */ +public class SyncElementFactory extends ElementFactoryAdapter { + + @Override + public void create(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, + final Resource elementType, final AsyncProcedure procedure) { + graph.asyncRequest(new UniqueRead() { + @Override + public ElementClass perform(ReadGraph graph) throws DatabaseException { + return create(graph, canvas, diagram, elementType); + } + }, procedure); + } + + @Override + public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, + final Resource elementResource, final IElement element, final AsyncProcedure procedure) { + graph.asyncRequest(new UniqueRead() { + @Override + public IElement perform(ReadGraph graph) throws DatabaseException { + if(isOk(graph, elementResource)) + load(graph, canvas, diagram, elementResource, element); + return element; + } + }, procedure); + } + + public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType) + throws DatabaseException { + throw new UnsupportedOperationException("This method should be implemented by subclass " + getClass().getName()); + } + + public boolean isOk(ReadGraph graph, Resource elementResource) throws DatabaseException { + return graph.hasStatement(elementResource); + } + + public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element) + throws DatabaseException { + throw new UnsupportedOperationException("This method should be implemented by subclass " + getClass().getName()); + } + +}