@Override public void handleEvent(Event e) { updatedConnections.add(((GraphEvent) e).getConnection()); } }, EventTypes.CHANGE_CONNECTION_DATA);
@Override public void removeNode(Point node) { // collect data of removed connections but only if there is a listener final List<Connection<?>> removedConnections = newArrayList(); if (eventDispatcher.hasListenerFor(EventTypes.REMOVE_CONNECTION)) { for (final Point p : delegate.getIncomingConnections(node)) { removedConnections.add(delegate.getConnection(p, node)); } for (final Point p : delegate.getOutgoingConnections(node)) { removedConnections.add(delegate.getConnection(node, p)); } } delegate.removeNode(node); // notify listeners for (final Connection<?> c : removedConnections) { eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.REMOVE_CONNECTION, this, c)); } }
@Override public int hashCode() { return Objects.hash(eventType, getIssuer(), connection); }
final GraphEvent ge = (GraphEvent) e; if (isCheckingEnabled && (ge.getEventType() == EventTypes.REMOVE_CONNECTION || ge.getEventType() == EventTypes.CHANGE_CONNECTION_DATA)) { final Connection<?> conn = ge.getConnection(); checkState( !model.registry().hasObjectOn(conn), + " or removed: %s.", conn.from(), conn.to(), model.registry().getObjectsOn(conn), ge.getEventType()); ge.getGraph().containsNode(conn.from()), UNMODIFIABLE_MSG, conn.from(), conn.from(), conn.to(), ge.getEventType()); ge.getGraph().containsNode(conn.to()), UNMODIFIABLE_MSG, conn.to(), conn.from(), conn.to(), ge.getEventType());
new GraphEvent(ADD_CONNECTION, graph1, Connection.create(a, c, Optional.<ConnectionData>absent())), history .getHistory().get(0)); assertEquals( new GraphEvent(ADD_CONNECTION, graph1, Connection.create(c, a, Optional.<ConnectionData>absent())), history
@Override public void handleEvent(Event e) { GraphEvent ge = (GraphEvent) e; if (e.getEventType() == ADD_CONNECTION) { assertTrue(ge.getGraph().hasConnection(ge.getConnection())); assertEquals( ge.getConnection(), ge.getGraph().getConnection(ge.getConnection().from(), ge.getConnection().to())); } else if (e.getEventType() == REMOVE_CONNECTION) { assertFalse(ge.getGraph().hasConnection(ge.getConnection().from(), ge.getConnection().to())); } else if (e.getEventType() == CHANGE_CONNECTION_DATA) { assertTrue(ge.getGraph().hasConnection(ge.getConnection().from(), ge.getConnection().to())); assertEquals( ge.getConnection().data(), ge.getGraph() .getConnection(ge.getConnection().from(), ge.getConnection().to()) .data()); } } }
@Override public void removeNode(Point node) { // collect data of removed connections but only if there is a listener final List<Connection<?>> removedConnections = newArrayList(); if (eventDispatcher.hasListenerFor(EventTypes.REMOVE_CONNECTION)) { for (final Point p : delegate.getIncomingConnections(node)) { removedConnections.add(delegate.getConnection(p, node)); } for (final Point p : delegate.getOutgoingConnections(node)) { removedConnections.add(delegate.getConnection(node, p)); } } delegate.removeNode(node); // notify listeners for (final Connection<?> c : removedConnections) { eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.REMOVE_CONNECTION, this, c)); } }
@Override public Optional<E> setConnectionData(Point from, Point to, E connectionData) { final Optional<E> val = delegate.setConnectionData(from, to, connectionData); eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.CHANGE_CONNECTION_DATA, this, getConnection(from, to))); return val; }
@Override public boolean equals(@Nullable Object other) { if (null == other || other.getClass() != this.getClass()) { return false; } final GraphEvent o = (GraphEvent) other; return Objects.equals(o.eventType, eventType) && Objects.equals(o.getIssuer(), getIssuer()) && Objects.equals(o.connection, connection); }
@Override public int hashCode() { return Objects.hash(eventType, getIssuer(), connection); }
@Override public void removeConnection(Point from, Point to) { final Connection<?> conn = delegate.getConnection(from, to); delegate.removeConnection(from, to); eventDispatcher .dispatchEvent(new GraphEvent( EventTypes.REMOVE_CONNECTION, this, conn)); }
@Override public void addConnection(Point from, Point to, E connData) { delegate.addConnection(from, to, connData); eventDispatcher.dispatchEvent(new GraphEvent(EventTypes.ADD_CONNECTION, this, getConnection(from, to))); }
@Override public void removeConnection(Point from, Point to) { final Connection<?> conn = delegate.getConnection(from, to); delegate.removeConnection(from, to); eventDispatcher .dispatchEvent(new GraphEvent( EventTypes.REMOVE_CONNECTION, this, conn)); }
@Override public Optional<E> removeConnectionData(Point from, Point to) { final Optional<E> val = delegate.removeConnectionData(from, to); eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.CHANGE_CONNECTION_DATA, this, getConnection(from, to))); return val; }
@Override public void addConnection(Connection<E> connection) { delegate.addConnection(connection); eventDispatcher.dispatchEvent(new GraphEvent(EventTypes.ADD_CONNECTION, this, connection)); }
@Override public void addConnection(Point from, Point to) { delegate.addConnection(from, to); eventDispatcher.dispatchEvent(new GraphEvent(EventTypes.ADD_CONNECTION, this, getConnection(from, to))); }
@Override public void handleEvent(Event e) { verify(e instanceof GraphEvent); final GraphEvent event = (GraphEvent) e; checkConnectionLength(minConnLength, event.getConnection()); } }
@Override public String toString() { return MoreObjects.toStringHelper("GraphEvent") .add("type", this.eventType) .add("issuer", this.getIssuer()) .add("connection", connection) .toString(); } }
@Override public boolean equals(@Nullable Object other) { if (null == other || other.getClass() != this.getClass()) { return false; } final GraphEvent o = (GraphEvent) other; return Objects.equals(o.eventType, eventType) && Objects.equals(o.getIssuer(), getIssuer()) && Objects.equals(o.connection, connection); }
@Override public Optional<E> setConnectionData(Point from, Point to, E connectionData) { final Optional<E> val = delegate.setConnectionData(from, to, connectionData); eventDispatcher.dispatchEvent(new GraphEvent( EventTypes.CHANGE_CONNECTION_DATA, this, getConnection(from, to))); return val; }