X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2Fgraph%2FPropertyModification.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2Fgraph%2FPropertyModification.java;h=6f0171f1b8d8d9206f4bbe65ba4094eec3fe7e92;hp=6bcf9fc3a1ee204ad458603d62301a063542be77;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/PropertyModification.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/PropertyModification.java index 6bcf9fc3a..6f0171f1b 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/PropertyModification.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/PropertyModification.java @@ -1,92 +1,92 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.synchronization.graph; - -import java.util.Arrays; - -import org.simantics.databoard.binding.Binding; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.CommentMetadata; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.synchronization.ModificationAdapter; - -/** - * @author Tuukka Lehtonen - */ -public class PropertyModification extends ModificationAdapter { - private final Resource owner; - private final Resource relation; - private final Resource type; - private final Object value; - private final Binding binding; - - public PropertyModification(Resource propertyOwner, Resource propertyRelation, Resource propertyType, Object value, Binding binding) { - super(LOW_PRIORITY); - this.owner = propertyOwner; - this.relation = propertyRelation; - this.type = propertyType; - this.value = value; - this.binding = binding; - } - - private final boolean arrayEquals(Object av1, Object av2) { - if (av2 == null) - return false; - Class c1 = av1.getClass().getComponentType(); - Class c2 = av2.getClass().getComponentType(); - if (c2 == null || !c1.equals(c2)) - return false; - boolean p1 = c1.isPrimitive(); - boolean p2 = c2.isPrimitive(); - if (p1 != p2) - return false; - if (!p1) - return Arrays.equals((Object[]) av1, (Object[]) av2); - if (boolean.class.equals(c1)) - return Arrays.equals((boolean[]) av1, (boolean[]) av2); - else if (byte.class.equals(c1)) - return Arrays.equals((byte[]) av1, (byte[]) av2); - else if (int.class.equals(c1)) - return Arrays.equals((int[]) av1, (int[]) av2); - else if (long.class.equals(c1)) - return Arrays.equals((long[]) av1, (long[]) av2); - else if (float.class.equals(c1)) - return Arrays.equals((float[]) av1, (float[]) av2); - else if (double.class.equals(c1)) - return Arrays.equals((double[]) av1, (double[]) av2); - throw new RuntimeException("??? Contact application querySupport."); - } - - private boolean sameValue(Object oldValue, Object newValue) { - if (newValue.getClass().isArray()) { - return arrayEquals(newValue, oldValue); - } else { - return newValue.equals(oldValue); - } - } - - @Override - public void perform(WriteGraph g) throws DatabaseException { - - Object existing = g.getPossibleRelatedValue(owner, relation, binding); - if(!sameValue(existing, value)) { - g.markUndoPoint(); - DiagramGraphUtil.setRelatedValue(g, owner, relation, type, value, binding); - // Add comment to change set. - CommentMetadata cm = g.getMetadata(CommentMetadata.class); - g.addMetadata(cm.add("Changed property " + NameUtils.getSafeName(g, relation))); - } - - } +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.synchronization.graph; + +import java.util.Arrays; + +import org.simantics.databoard.binding.Binding; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.synchronization.ModificationAdapter; + +/** + * @author Tuukka Lehtonen + */ +public class PropertyModification extends ModificationAdapter { + private final Resource owner; + private final Resource relation; + private final Resource type; + private final Object value; + private final Binding binding; + + public PropertyModification(Resource propertyOwner, Resource propertyRelation, Resource propertyType, Object value, Binding binding) { + super(LOW_PRIORITY); + this.owner = propertyOwner; + this.relation = propertyRelation; + this.type = propertyType; + this.value = value; + this.binding = binding; + } + + private final boolean arrayEquals(Object av1, Object av2) { + if (av2 == null) + return false; + Class c1 = av1.getClass().getComponentType(); + Class c2 = av2.getClass().getComponentType(); + if (c2 == null || !c1.equals(c2)) + return false; + boolean p1 = c1.isPrimitive(); + boolean p2 = c2.isPrimitive(); + if (p1 != p2) + return false; + if (!p1) + return Arrays.equals((Object[]) av1, (Object[]) av2); + if (boolean.class.equals(c1)) + return Arrays.equals((boolean[]) av1, (boolean[]) av2); + else if (byte.class.equals(c1)) + return Arrays.equals((byte[]) av1, (byte[]) av2); + else if (int.class.equals(c1)) + return Arrays.equals((int[]) av1, (int[]) av2); + else if (long.class.equals(c1)) + return Arrays.equals((long[]) av1, (long[]) av2); + else if (float.class.equals(c1)) + return Arrays.equals((float[]) av1, (float[]) av2); + else if (double.class.equals(c1)) + return Arrays.equals((double[]) av1, (double[]) av2); + throw new RuntimeException("??? Contact application querySupport."); + } + + private boolean sameValue(Object oldValue, Object newValue) { + if (newValue.getClass().isArray()) { + return arrayEquals(newValue, oldValue); + } else { + return newValue.equals(oldValue); + } + } + + @Override + public void perform(WriteGraph g) throws DatabaseException { + + Object existing = g.getPossibleRelatedValue(owner, relation, binding); + if(!sameValue(existing, value)) { + g.markUndoPoint(); + DiagramGraphUtil.setRelatedValue(g, owner, relation, type, value, binding); + // Add comment to change set. + CommentMetadata cm = g.getMetadata(CommentMetadata.class); + g.addMetadata(cm.add("Changed property " + NameUtils.getSafeName(g, relation))); + } + + } } \ No newline at end of file