1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.adapter;
\r
14 import org.simantics.db.AsyncReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;
\r
17 import org.simantics.db.procedure.AsyncProcedure;
\r
18 import org.simantics.db.procedure.Procedure;
\r
19 import org.simantics.g2d.canvas.ICanvasContext;
\r
20 import org.simantics.g2d.diagram.IDiagram;
\r
21 import org.simantics.g2d.element.ElementClass;
\r
22 import org.simantics.g2d.element.IElement;
\r
25 * The base interface for loading diagram elements from the graph database into
\r
26 * {@link ElementClass} and {@link IElement} instances for use with the g2d
\r
27 * diagram framework.
\r
29 * @author Tuukka Lehtonen
\r
31 * @see ElementFactoryAdapter
\r
32 * @see SyncElementFactory
\r
34 public interface ElementFactory {
\r
37 * Retrieves the {@link ElementClass} for the given modelled element type.
\r
39 void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure);
\r
42 * Retrieves the {@link ElementClass} for the given modelled element
\r
43 * instance. The only real difference to
\r
44 * {@link #create(AsyncReadGraph, ICanvasContext, IDiagram, Resource, AsyncProcedure)}
\r
45 * is that the resource argument is an element instance, not a type.
\r
47 * The most usual default implementation of this method is to get the type
\r
48 * of the resource and invoke
\r
49 * {@link #create(AsyncReadGraph, ICanvasContext, IDiagram, Resource, AsyncProcedure)}
\r
52 void getClass(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, AsyncProcedure<ElementClass> procedure);
\r
55 * Loads data from given modelled element resource into the given element.
\r
58 * The loader shall notify the specified <code>procedure</code> when the
\r
59 * element has been loaded. If the element cannot be loaded properly for
\r
60 * some reason, {@link Procedure#exception(Throwable)} should be invoked.
\r
61 * Only invoke either {@link Procedure#exception(Throwable)} or
\r
62 * {@link Procedure#execute(Object)} once.
\r
63 * {@link GuardedAsyncProceureWrapper} can help with that.
\r
66 * IMPORTANT: Diagram elements are essentially nothing more than their
\r
67 * {@link ElementClass} and a set of hints. Updating the appearance or any
\r
68 * other property related to an IElement is always a matter of updating its
\r
69 * hint values. This is exactly what {@link GraphToDiagramSynchronizer} does
\r
70 * in order to keep the run-time IElement representation in sync with the
\r
71 * database contents. IElements may contain any number of hints that are set
\r
72 * outside of the ElementFactory that loaded the element. In order for the
\r
73 * graph → IElement updates to work properly, the updater must be able
\r
74 * to rely on the fact that it simply needs to replace the existing hint
\r
75 * values with the new hint values loaded by this method. Therefore
\r
76 * implementers need to ensure that the same set of hint keys is always
\r
77 * loaded for a single element. Otherwise the update process will
\r
78 * potentially leave unwanted hints lying around in the run-time diagram
\r
81 * @see GuardedAsyncProcedureWrapper
\r
83 void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element, AsyncProcedure<IElement> procedure);
\r