X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fdiagram%2Fhandler%2FRelationshipHandler.java;h=a1002a8af90bc74d62d4f9ba5b86770d608a09cb;hb=refs%2Fchanges%2F38%2F238%2F2;hp=256bd7bb6d9d4f8e40d531079f929320dd34b8e8;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/RelationshipHandler.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/RelationshipHandler.java index 256bd7bb6..a1002a8af 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/RelationshipHandler.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/handler/RelationshipHandler.java @@ -1,130 +1,130 @@ -/******************************************************************************* - * 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.g2d.diagram.handler; - -import java.util.Collection; - -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.utils.ObjectUtils; - -/** - * A diagram handler for managing and querying arbitrary relationships between - * diagram objects. The management is done by claiming and denying relationships - * about the objects. A single relationship can only exist once or not at all - * between two objects, i.e. no duplicate relationships can be added. - * - *

- * There is no pre-defined meaning for a relationship - it is completely - * customizable by implementing your own {@link Relationship} interface. - *

- * - * @author Tuukka Lehtonen - */ -public interface RelationshipHandler extends DiagramHandler { - - /** - * A simple holder class for a single relationship. Holds all the - * ingredients: two elements and the role of the relationship. The - * relationship is either uni- or bi-directional. - */ - public final class Relation { - private final Object subject; - private final Relationship relationship; - private final Object object; - - public Relation(Object subject, Relationship relationship, Object object) { - assert subject != null; - assert relationship != null; - assert object != null; - this.subject = subject; - this.relationship = relationship; - this.object = object; - } - - public Object getSubject() { - return subject; - } - - public Relationship getRelationship() { - return relationship; - } - - public Object getObject() { - return object; - } - - @Override - public int hashCode() { - return ((ObjectUtils.hashCode(subject) * 31) - + ObjectUtils.hashCode(object) * 31) - + ObjectUtils.hashCode(relationship); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (!(obj instanceof Relation)) - return false; - Relation other = (Relation) obj; - return subject.equals(other.subject) && object.equals(other.object) && relationship.equals(other.relationship); - } - - @Override - public String toString() { - return "(" + subject + ", " + relationship + ", " + object + ")"; - } - } - - /** - * Claim a single relationship between the specified subject and object. An - * inverse relation will also be claimed if one exists. - * - * Subject and object should be alive (not destroyed). However it should not - * be enforced to be activated within the specified diagram, at the moment - * of invocation. This is because the relationship may be denied while the - * elements are still in the process of being added to or removed from a - * diagram. - * - * @param diagram the diagram to operate on - * @param subject the subject of the relationship - * @param predicate the relationship itself - * @param object the object of the relationship - */ - void claim(IDiagram diagram, Object subject, Relationship predicate, Object object); - - /** - * Deny a relationship. This will also deny the inverse relationship if one - * exists. - * - * Subject and object should be alive (not destroyed). However it should not - * be enforced to be activated within the specified diagram, at the moment - * of invocation. This is because the relationship may be denied while the - * elements are still in the process of being added to or removed from a - * diagram. - */ - void deny(IDiagram diagram, Object subject, Relationship predicate, Object object); - void deny(IDiagram diagram, Relation relation); - void denyAll(IDiagram diagram, Object element); - - /** - * Get all the relationships that are recorded for the specified element. - * - * @param diagram the diagram to operate on - * @param element the element to get all relations for - * @param result a collection for gathering the result of the query or null - * to create a new collection for the result. - * @return - */ - Collection getRelations(IDiagram diagram, Object element, Collection result); - -} +/******************************************************************************* + * 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.g2d.diagram.handler; + +import java.util.Collection; + +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.utils.ObjectUtils; + +/** + * A diagram handler for managing and querying arbitrary relationships between + * diagram objects. The management is done by claiming and denying relationships + * about the objects. A single relationship can only exist once or not at all + * between two objects, i.e. no duplicate relationships can be added. + * + *

+ * There is no pre-defined meaning for a relationship - it is completely + * customizable by implementing your own {@link Relationship} interface. + *

+ * + * @author Tuukka Lehtonen + */ +public interface RelationshipHandler extends DiagramHandler { + + /** + * A simple holder class for a single relationship. Holds all the + * ingredients: two elements and the role of the relationship. The + * relationship is either uni- or bi-directional. + */ + public final class Relation { + private final Object subject; + private final Relationship relationship; + private final Object object; + + public Relation(Object subject, Relationship relationship, Object object) { + assert subject != null; + assert relationship != null; + assert object != null; + this.subject = subject; + this.relationship = relationship; + this.object = object; + } + + public Object getSubject() { + return subject; + } + + public Relationship getRelationship() { + return relationship; + } + + public Object getObject() { + return object; + } + + @Override + public int hashCode() { + return ((ObjectUtils.hashCode(subject) * 31) + + ObjectUtils.hashCode(object) * 31) + + ObjectUtils.hashCode(relationship); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) + return true; + if (!(obj instanceof Relation)) + return false; + Relation other = (Relation) obj; + return subject.equals(other.subject) && object.equals(other.object) && relationship.equals(other.relationship); + } + + @Override + public String toString() { + return "(" + subject + ", " + relationship + ", " + object + ")"; + } + } + + /** + * Claim a single relationship between the specified subject and object. An + * inverse relation will also be claimed if one exists. + * + * Subject and object should be alive (not destroyed). However it should not + * be enforced to be activated within the specified diagram, at the moment + * of invocation. This is because the relationship may be denied while the + * elements are still in the process of being added to or removed from a + * diagram. + * + * @param diagram the diagram to operate on + * @param subject the subject of the relationship + * @param predicate the relationship itself + * @param object the object of the relationship + */ + void claim(IDiagram diagram, Object subject, Relationship predicate, Object object); + + /** + * Deny a relationship. This will also deny the inverse relationship if one + * exists. + * + * Subject and object should be alive (not destroyed). However it should not + * be enforced to be activated within the specified diagram, at the moment + * of invocation. This is because the relationship may be denied while the + * elements are still in the process of being added to or removed from a + * diagram. + */ + void deny(IDiagram diagram, Object subject, Relationship predicate, Object object); + void deny(IDiagram diagram, Relation relation); + void denyAll(IDiagram diagram, Object element); + + /** + * Get all the relationships that are recorded for the specified element. + * + * @param diagram the diagram to operate on + * @param element the element to get all relations for + * @param result a collection for gathering the result of the query or null + * to create a new collection for the result. + * @return + */ + Collection getRelations(IDiagram diagram, Object element, Collection result); + +}