X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FElementFactoryAdapter.java;h=d5ba8d0aa2ed4dc3b9949becb469a45595d37119;hb=617b9475710b80a125597f222f9777224972ce72;hp=0d1eb82353608f3f71c608ea4b0c8aef7fd444aa;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryAdapter.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryAdapter.java index 0d1eb8235..d5ba8d0aa 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryAdapter.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ElementFactoryAdapter.java @@ -1,73 +1,73 @@ -/******************************************************************************* - * 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.Resource; -import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; -import org.simantics.db.procedure.AsyncProcedure; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.element.ElementClass; -import org.simantics.g2d.element.IElement; - -/** - * @author Tuukka Lehtonen - */ -public class ElementFactoryAdapter implements ElementFactory { - - @Override - public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, - AsyncProcedure procedure) { - procedure.exception(graph, new UnsupportedOperationException(getClass().getName() + " does not support ElementFactory.create")); - } - - protected Resource getElementClassBaseType(AsyncReadGraph graph) { - return graph.getService(DiagramResource.class).Element; - } - - @Override - public void getClass(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, - Resource elementResource, final AsyncProcedure procedure) { - // A most usual default implementation. - graph.forSingleType(elementResource, getElementClassBaseType(graph), new AsyncProcedure() { - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - procedure.exception(graph, throwable); - } - @Override - public void execute(AsyncReadGraph graph, Resource elementType) { - // Implements caching of element class requests. - graph.asyncRequest(new CreateElementClassRequest(ElementFactoryAdapter.this, elementType, canvas, diagram), - new TransientCacheAsyncListener() { - @Override - public void exception(AsyncReadGraph graph, Throwable t) { - procedure.exception(graph, t); - } - @Override - public void execute(AsyncReadGraph graph, ElementClass result) { - //System.out.println("RESULT ELEMENTCLASS: " + System.identityHashCode(result) + ": " + result); - procedure.execute(graph, result); - } - }); - } - }); - } - - @Override - public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, - IElement element, AsyncProcedure procedure) { - procedure.exception(graph, new UnsupportedOperationException(getClass().getName() + " does not support ElementFactory.load")); - } - -} +/******************************************************************************* + * 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.Resource; +import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; +import org.simantics.db.procedure.AsyncProcedure; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.IElement; + +/** + * @author Tuukka Lehtonen + */ +public class ElementFactoryAdapter implements ElementFactory { + + @Override + public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, + AsyncProcedure procedure) { + procedure.exception(graph, new UnsupportedOperationException(getClass().getName() + " does not support ElementFactory.create")); + } + + protected Resource getElementClassBaseType(AsyncReadGraph graph) { + return graph.getService(DiagramResource.class).Element; + } + + @Override + public void getClass(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, + Resource elementResource, final AsyncProcedure procedure) { + // A most usual default implementation. + graph.forSingleType(elementResource, getElementClassBaseType(graph), new AsyncProcedure() { + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + @Override + public void execute(AsyncReadGraph graph, Resource elementType) { + // Implements caching of element class requests. + graph.asyncRequest(new CreateElementClassRequest(ElementFactoryAdapter.this, elementType, canvas, diagram), + new TransientCacheAsyncListener() { + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + procedure.exception(graph, t); + } + @Override + public void execute(AsyncReadGraph graph, ElementClass result) { + //System.out.println("RESULT ELEMENTCLASS: " + System.identityHashCode(result) + ": " + result); + procedure.execute(graph, result); + } + }); + } + }); + } + + @Override + public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, + IElement element, AsyncProcedure procedure) { + procedure.exception(graph, new UnsupportedOperationException(getClass().getName() + " does not support ElementFactory.load")); + } + +}