Esempio n. 1
0
  @Nonnull
  @Override
  public Connection connect(@Nonnull OutputTerminal output, @Nonnull InputTerminal input) {
    // Locate the correct CanvasItem for the Connection.
    CanvasItem canvas = output.getTerminalHolder().getCanvas();
    if (canvas == input.getTerminalHolder().getCanvas()) {
      if (canvas != this) return canvas.connect(output, input);
    }
    // If the two Terminals are in separate CanvasItems, the connection should
    // be made in the ProjectItem.
    else if (!(this instanceof ProjectItem && canvas.getProject() == this))
      return canvas.getProject().connect(output, input);

    // Make sure an identical Connection doesn't already exist.
    for (Connection connection : output.getConnections())
      if (connection.getInputTerminal().equals(input)) return connection;

    // Create the Connection.
    final Connection connection = createConnection(output, input);
    connectionList.addItem(
        connection,
        new Runnable() {
          @Override
          public void run() {
            connection
                .getOutputTerminal()
                .addEventListener(TerminalConnectionEvent.class, connectionListener);
          }
        });

    return connection;
  }
Esempio n. 2
0
 private void createConnections() {
   for (ConnectionConfig connectionConfig : getConfig().getConnectionList()) {
     try {
       Connection connection = new ConnectionImpl(connectionConfig);
       connection
           .getOutputTerminal()
           .addEventListener(TerminalConnectionEvent.class, connectionListener);
       connectionList.addItem(connection);
     } catch (Exception e) {
       badConnections.add(connectionConfig);
       log.error(
           "Unable to create connection between terminals "
               + connectionConfig.getInputTerminalId()
               + " and "
               + connectionConfig.getOutputTerminalId(),
           e);
     }
   }
 }