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.modeling.ui.diagram;
14 import java.awt.geom.AffineTransform;
16 import org.simantics.db.AsyncReadGraph;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.procedure.AsyncProcedure;
21 import org.simantics.diagram.adapter.SyncElementFactory;
22 import org.simantics.diagram.synchronization.SynchronizationHints;
23 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
24 import org.simantics.diagram.synchronization.graph.MonitorSynchronizer;
25 import org.simantics.g2d.canvas.ICanvasContext;
26 import org.simantics.g2d.diagram.IDiagram;
27 import org.simantics.g2d.element.ElementClass;
28 import org.simantics.g2d.element.ElementHints;
29 import org.simantics.g2d.element.ElementUtils;
30 import org.simantics.g2d.element.IElement;
31 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
32 import org.simantics.layer0.Layer0;
33 import org.simantics.scenegraph.swing.SymbolMonitorClass;
37 * TODO: recognize experiment disposal and reset monitor contents at that point
38 * FIXME: SymbolMonitorClass is not properly implemented equals/hashCode-wise
40 public class SymbolMonitorClassFactory extends SyncElementFactory {
42 public static ElementClass createMonitorClass(Resource elementClass) {
43 // set "default scale" to no scaling, 1.0, 1.0
44 return SymbolMonitorClass.create(null, null, null, 1.0, 1.0, new StaticObjectAdapter(elementClass));
48 public void load(ReadGraph g, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {
50 Layer0 b = Layer0.getInstance(g);
52 // Must be done here to allow for the relationship manager to work properly.
53 e.setHint(ElementHints.KEY_OBJECT, element);
55 String name = g.getPossibleRelatedValue(element, b.HasName);
56 if(name != null) e.setHint(ElementHints.KEY_SG_NAME, name);
58 AffineTransform at = DiagramGraphUtil.getAffineTransform(g, element);
59 ElementUtils.setTransform(e, at);
61 e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, MonitorSynchronizer.INSTANCE);
66 public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType,
67 AsyncProcedure<ElementClass> procedure) {
69 procedure.execute(graph, createMonitorClass(elementType));