]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/TransformElement.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / TransformElement.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2015 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.diagram.synchronization.graph;
13
14 import java.awt.geom.AffineTransform;
15
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.CommentMetadata;
19 import org.simantics.db.common.utils.NameUtils;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.diagram.synchronization.ModificationAdapter;
22 import org.simantics.modeling.ModelingResources;
23
24 /**
25  * @author Tuukka Lehtonen
26  */
27 public class TransformElement extends ModificationAdapter {
28
29     Resource elementResource;
30     AffineTransform tr;
31
32     public TransformElement(Resource element, AffineTransform tr) {
33         super(LOW_PRIORITY);
34         this.elementResource = element;
35         this.tr = tr;
36     }
37
38     @Override
39     public void perform(WriteGraph g) throws DatabaseException {
40         DiagramGraphUtil.setTransform(g, elementResource, tr);
41
42         // Add comment to change set.
43         CommentMetadata cm = g.getMetadata(CommentMetadata.class);
44         ModelingResources MOD = ModelingResources.getInstance(g);
45         Resource component = g.getPossibleObject(elementResource, MOD.ElementToComponent);
46         if (component != null)
47             g.addMetadata(cm.add("Transformed " + NameUtils.getSafeName(g, component)));
48         else
49             g.addMetadata(cm.add("Transformed " + elementResource));
50     }
51
52 }