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.Resource;
16 import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;
17 import org.simantics.db.procedure.AsyncProcedure;
18 import org.simantics.db.procedure.Procedure;
19 import org.simantics.g2d.canvas.ICanvasContext;
20 import org.simantics.g2d.diagram.IDiagram;
21 import org.simantics.g2d.element.ElementClass;
22 import org.simantics.g2d.element.IElement;
25 * The base interface for loading diagram elements from the graph database into
26 * {@link ElementClass} and {@link IElement} instances for use with the g2d
29 * @author Tuukka Lehtonen
31 * @see ElementFactoryAdapter
32 * @see SyncElementFactory
34 public interface ElementFactory {
37 * Retrieves the {@link ElementClass} for the given modelled element type.
39 void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure);
42 * Retrieves the {@link ElementClass} for the given modelled element
43 * instance. The only real difference to
44 * {@link #create(AsyncReadGraph, ICanvasContext, IDiagram, Resource, AsyncProcedure)}
45 * is that the resource argument is an element instance, not a type.
47 * The most usual default implementation of this method is to get the type
48 * of the resource and invoke
49 * {@link #create(AsyncReadGraph, ICanvasContext, IDiagram, Resource, AsyncProcedure)}
52 void getClass(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, AsyncProcedure<ElementClass> procedure);
55 * Loads data from given modelled element resource into the given element.
58 * The loader shall notify the specified <code>procedure</code> when the
59 * element has been loaded. If the element cannot be loaded properly for
60 * some reason, {@link Procedure#exception(Throwable)} should be invoked.
61 * Only invoke either {@link Procedure#exception(Throwable)} or
62 * {@link Procedure#execute(Object)} once.
63 * {@link GuardedAsyncProceureWrapper} can help with that.
66 * IMPORTANT: Diagram elements are essentially nothing more than their
67 * {@link ElementClass} and a set of hints. Updating the appearance or any
68 * other property related to an IElement is always a matter of updating its
69 * hint values. This is exactly what {@link GraphToDiagramSynchronizer} does
70 * in order to keep the run-time IElement representation in sync with the
71 * database contents. IElements may contain any number of hints that are set
72 * outside of the ElementFactory that loaded the element. In order for the
73 * graph → IElement updates to work properly, the updater must be able
74 * to rely on the fact that it simply needs to replace the existing hint
75 * values with the new hint values loaded by this method. Therefore
76 * implementers need to ensure that the same set of hint keys is always
77 * loaded for a single element. Otherwise the update process will
78 * potentially leave unwanted hints lying around in the run-time diagram
81 * @see GuardedAsyncProcedureWrapper
83 void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element, AsyncProcedure<IElement> procedure);