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.diagram.synchronization.graph;
14 import org.simantics.databoard.binding.Binding;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.CommentMetadata;
18 import org.simantics.db.common.utils.NameUtils;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.diagram.synchronization.ModificationAdapter;
23 * @author Tuukka Lehtonen
25 public class RelatedPropertyModification extends ModificationAdapter {
26 private final Resource subject;
27 private final Resource relation;
28 private final Resource propertyRelation;
29 private final Resource type;
30 private final Object value;
31 private final Binding binding;
33 public RelatedPropertyModification(Resource subject, Resource relation, Resource propertyRelation, Resource propertyType, Object value, Binding binding) {
35 this.subject = subject;
36 this.relation = relation;
37 this.propertyRelation = propertyRelation;
38 this.type = propertyType;
40 this.binding = binding;
44 public void perform(WriteGraph g) throws DatabaseException {
45 Resource propertyOwner = g.getPossibleObject(subject, relation);
46 if (propertyOwner != null) {
47 Object existing = g.getPossibleRelatedValue(propertyOwner, propertyRelation, binding);
48 if(!value.equals(existing)) {
50 DiagramGraphUtil.setRelatedValue(g, propertyOwner, propertyRelation, type, value, binding);
51 // Add comment to change set.
52 CommentMetadata cm = g.getMetadata(CommentMetadata.class);
53 g.addMetadata(cm.add("Changed property " + NameUtils.getSafeLabel(g, propertyRelation) + " in " + NameUtils.getSafeName(g, propertyOwner)));