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.g2d.diagram.handler;
14 import java.util.Collection;
16 import org.simantics.g2d.diagram.handler.impl.TopologyImpl;
17 import org.simantics.g2d.element.IElement;
18 import org.simantics.g2d.element.handler.EdgeVisuals.EdgeEnd;
19 import org.simantics.g2d.element.handler.TerminalTopology;
20 import org.simantics.g2d.element.handler.impl.ObjectTerminal;
24 * TODO Remove Connection. Replace with Individual hints.
26 * @see TopologyImpl Default implementation.
27 * @author Toni Kalajainen
29 public interface Topology extends DiagramHandler {
35 public interface Terminal {}
39 * @param end Begin or End
40 * @return <code>null</code> if the specified end of the specified edge is
43 Connection getConnection(IElement edge, EdgeEnd end);
46 * Get all the connections attached to the specified terminal of the
53 void getConnections(IElement node, Terminal terminal, Collection<Connection> connections);
56 * Connect one end of a connection to an element terminal.
58 * @param edge the edge to connect to the specified node, must belong to the
59 * same diagram as the node
61 * @param node the node to connect to the specified edge, must belong to the
62 * same diagram as the edge
63 * @param terminal a terminal of node, retrieved using {@link TerminalTopology}
65 void connect(IElement edge, EdgeEnd end, IElement node, Terminal terminal);
68 * Disconnect one end of a connection from an element terminal.
70 * @param edge the edge to connect to the specified node, must belong to the
71 * same diagram as the node
72 * @param end the end of the edge to disconnect
73 * @param node the node to disconnect the specified edge from. Must belong to the
74 * same diagram as the edge.
75 * @param terminal a terminal of node, retrieved using {@link TerminalTopology}
77 void disconnect(IElement edge, EdgeEnd end, IElement node, Terminal terminal);
80 * A hint value class for representing a single edge end to node terminal
83 public static class Connection {
84 public final Terminal terminal;
85 public final IElement edge;
86 public final IElement node;
87 public final EdgeEnd end;
88 public Connection(IElement edge, EdgeEnd end, IElement node, Terminal terminal) {
91 assert (terminal == null && node == null) || (node != null && terminal != null);
95 this.terminal = terminal;
98 public boolean equals(Object obj) {
101 if (!(obj instanceof Connection))
103 Connection other = (Connection) obj;
104 return other.terminal == terminal &&
105 other.edge == edge &&
106 other.node == node &&
110 public int hashCode() {
111 final int prime = 31;
113 result = prime * result + edge.hashCode();
114 result = prime * result + end.hashCode();
115 result = prime * result + ((node == null) ? 0 : node.hashCode());
116 result = prime * result + ((terminal == null) ? 0 : terminal.hashCode());
120 public String toString() {
121 return "Topology.Connection[edge=" + edge + ", node=" + node + ", terminal=" + terminal + ", end=" + end + "]";