Пример #1
0
  private void deleteConnections(Collection<ConnectionFigure> connections) {
    boolean dirty = false;
    List<Connection> connectionsToDelete = new ArrayList<>();
    for (ConnectionFigure connectionFigure : connections) {
      connectionsToDelete.add(connectionFigure.getConnection());
      dirty = true;
    }

    if (editorsCommandStack == null) {
      description.removeConnections(connectionsToDelete);
      targetTreeViewer.refresh();
      sourceTreeViewer.refresh();
    } else {
      ConnectionDeleteCommand connectionDeleteCommand =
          new ConnectionDeleteCommand(description, connectionsToDelete);
      editorsCommandStack.execute(connectionDeleteCommand);
    }

    if (dirty) {
      repaint();
    }
  }
Пример #2
0
 /** Repaints the connections on the canvas. */
 public void repaint() {
   // clear the parent figure
   parentFigure.removeAll();
   // for each connection create a connection figure and add it to the parent figure
   for (Connection c : description.getConnections()) {
     TreeItem outputItem =
         sourceTreeViewer.findEndpoint(c.getSourceNode(), c.getOutput().getName());
     TreeItem inputItem = targetTreeViewer.findEndpoint(c.getTargetNode(), c.getInput().getName());
     // calculate the coordinates of the connection figure (the line) on the canvas
     if (inputItem != null && outputItem != null) {
       int outputY = outputItem.getBounds().y + outputItem.getBounds().height / 2;
       int outputX = 0;
       int inputY = inputItem.getBounds().y + inputItem.getBounds().height / 2;
       int inputX = parentFigure.getBounds().width;
       // create the connection figure (the connection line)
       ConnectionFigure line =
           new ConnectionFigure(c, new Point(outputX, outputY), new Point(inputX, inputY));
       // add the connection figure to the parent figure
       line.setAntialias(SWT.ON);
       parentFigure.add(line);
     }
   }
 }