]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/SymbolMonitorClassFactory.java
Improved usability of shared library export wizard
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / diagram / SymbolMonitorClassFactory.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.diagram;
13
14 import java.awt.geom.AffineTransform;
15
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;
34
35
36 /**
37  * TODO: recognize experiment disposal and reset monitor contents at that point
38  * FIXME: SymbolMonitorClass is not properly implemented equals/hashCode-wise
39  */
40 public class SymbolMonitorClassFactory extends SyncElementFactory {
41
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));
45     }
46
47     @Override
48     public void load(ReadGraph g, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {
49         
50         Layer0 b = Layer0.getInstance(g);
51
52         // Must be done here to allow for the relationship manager to work properly.
53         e.setHint(ElementHints.KEY_OBJECT, element);
54         
55         String name = g.getPossibleRelatedValue(element, b.HasName);
56         if(name != null) e.setHint(ElementHints.KEY_SG_NAME, name);
57
58         AffineTransform at = DiagramGraphUtil.getAffineTransform(g, element);
59         ElementUtils.setTransform(e, at);
60
61         e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, MonitorSynchronizer.INSTANCE);
62         
63     }
64
65     @Override
66     public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType,
67             AsyncProcedure<ElementClass> procedure) {
68         
69         procedure.execute(graph, createMonitorClass(elementType));
70         
71     }
72
73 }