--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.adapter;\r
+\r
+import org.simantics.db.AsyncReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;\r
+import org.simantics.db.procedure.AsyncProcedure;\r
+import org.simantics.db.procedure.Procedure;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.IElement;\r
+\r
+/**\r
+ * The base interface for loading diagram elements from the graph database into\r
+ * {@link ElementClass} and {@link IElement} instances for use with the g2d\r
+ * diagram framework.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * \r
+ * @see ElementFactoryAdapter\r
+ * @see SyncElementFactory\r
+ */\r
+public interface ElementFactory {\r
+\r
+ /**\r
+ * Retrieves the {@link ElementClass} for the given modelled element type.\r
+ */\r
+ void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure);\r
+\r
+ /**\r
+ * Retrieves the {@link ElementClass} for the given modelled element\r
+ * instance. The only real difference to\r
+ * {@link #create(AsyncReadGraph, ICanvasContext, IDiagram, Resource, AsyncProcedure)}\r
+ * is that the resource argument is an element instance, not a type.\r
+ * \r
+ * The most usual default implementation of this method is to get the type\r
+ * of the resource and invoke\r
+ * {@link #create(AsyncReadGraph, ICanvasContext, IDiagram, Resource, AsyncProcedure)}\r
+ * with the type.\r
+ */\r
+ void getClass(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, AsyncProcedure<ElementClass> procedure);\r
+\r
+ /**\r
+ * Loads data from given modelled element resource into the given element.\r
+ * \r
+ * <p>\r
+ * The loader shall notify the specified <code>procedure</code> when the\r
+ * element has been loaded. If the element cannot be loaded properly for\r
+ * some reason, {@link Procedure#exception(Throwable)} should be invoked.\r
+ * Only invoke either {@link Procedure#exception(Throwable)} or\r
+ * {@link Procedure#execute(Object)} once.\r
+ * {@link GuardedAsyncProceureWrapper} can help with that.\r
+ * \r
+ * <p>\r
+ * IMPORTANT: Diagram elements are essentially nothing more than their\r
+ * {@link ElementClass} and a set of hints. Updating the appearance or any\r
+ * other property related to an IElement is always a matter of updating its\r
+ * hint values. This is exactly what {@link GraphToDiagramSynchronizer} does\r
+ * in order to keep the run-time IElement representation in sync with the\r
+ * database contents. IElements may contain any number of hints that are set\r
+ * outside of the ElementFactory that loaded the element. In order for the\r
+ * graph → IElement updates to work properly, the updater must be able\r
+ * to rely on the fact that it simply needs to replace the existing hint\r
+ * values with the new hint values loaded by this method. Therefore\r
+ * implementers need to ensure that the same set of hint keys is always\r
+ * loaded for a single element. Otherwise the update process will\r
+ * potentially leave unwanted hints lying around in the run-time diagram\r
+ * elements.\r
+ * \r
+ * @see GuardedAsyncProcedureWrapper\r
+ */\r
+ void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element, AsyncProcedure<IElement> procedure);\r
+\r
+}\r