]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/RelatedPropertyModification.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / RelatedPropertyModification.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.synchronization.graph;\r
13 \r
14 import org.simantics.databoard.binding.Binding;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.WriteGraph;\r
17 import org.simantics.db.common.CommentMetadata;\r
18 import org.simantics.db.common.utils.NameUtils;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 import org.simantics.diagram.synchronization.ModificationAdapter;\r
21 \r
22 /**\r
23  * @author Tuukka Lehtonen\r
24  */\r
25 public class RelatedPropertyModification extends ModificationAdapter {\r
26     private final Resource subject;\r
27     private final Resource relation;\r
28     private final Resource propertyRelation;\r
29     private final Resource type;\r
30     private final Object value;\r
31     private final Binding binding;\r
32 \r
33     public RelatedPropertyModification(Resource subject, Resource relation, Resource propertyRelation, Resource propertyType, Object value, Binding binding) {\r
34         super(LOW_PRIORITY);\r
35         this.subject = subject;\r
36         this.relation = relation;\r
37         this.propertyRelation = propertyRelation;\r
38         this.type = propertyType;\r
39         this.value = value;\r
40         this.binding = binding;\r
41     }\r
42 \r
43     @Override\r
44     public void perform(WriteGraph g) throws DatabaseException {\r
45         Resource propertyOwner = g.getPossibleObject(subject, relation);\r
46         if (propertyOwner != null) {\r
47                 Object existing = g.getPossibleRelatedValue(propertyOwner, propertyRelation, binding);\r
48                 if(!value.equals(existing)) {\r
49                 g.markUndoPoint();\r
50                         DiagramGraphUtil.setRelatedValue(g, propertyOwner, propertyRelation, type, value, binding);\r
51                         // Add comment to change set.\r
52                         CommentMetadata cm = g.getMetadata(CommentMetadata.class);\r
53                         g.addMetadata(cm.add("Changed property " + NameUtils.getSafeLabel(g, propertyRelation) + " in " + NameUtils.getSafeName(g, propertyOwner)));\r
54                 }\r
55         }\r
56     }\r
57     \r
58 }