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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.synchronization.graph;
\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
23 * @author Tuukka Lehtonen
\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
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
40 this.binding = binding;
\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
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