/**
   * Moves the column and heading at <code>columnIndex</code> to <code>newIndex</code>. The old
   * column at <code>columnIndex</code> will now be found at <code>newIndex</code>. The column that
   * used to be at <code>newIndex</code> is shifted left or right to make room. This will not move
   * any columns if <code>columnIndex</code> equals <code>newIndex</code>. This method also posts a
   * <code>columnMoved</code> event to its listeners.
   *
   * @param columnIndex the index of column to be moved
   * @param newIndex new index to move the column
   * @exception IllegalArgumentException if <code>column</code> or <code>newIndex</code> are not in
   *     the valid range
   */
  public void moveColumn(int columnIndex, int newIndex) {
    if ((columnIndex < 0)
        || (columnIndex >= getColumnCount())
        || (newIndex < 0)
        || (newIndex >= getColumnCount()))
      throw new IllegalArgumentException("moveColumn() - Index out of range");

    TableColumn aColumn;

    // If the column has not yet moved far enough to change positions
    // post the event anyway, the "draggedDistance" property of the
    // tableHeader will say how far the column has been dragged.
    // Here we are really trying to get the best out of an
    // API that could do with some rethinking. We preserve backward
    // compatibility by slightly bending the meaning of these methods.
    if (columnIndex == newIndex) {
      fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex));
      return;
    }
    aColumn = (TableColumn) tableColumns.elementAt(columnIndex);

    tableColumns.removeElementAt(columnIndex);
    boolean selected = selectionModel.isSelectedIndex(columnIndex);
    selectionModel.removeIndexInterval(columnIndex, columnIndex);

    tableColumns.insertElementAt(aColumn, newIndex);
    selectionModel.insertIndexInterval(newIndex, 1, true);
    if (selected) {
      selectionModel.addSelectionInterval(newIndex, newIndex);
    } else {
      selectionModel.removeSelectionInterval(newIndex, newIndex);
    }

    fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex));
  }
Ejemplo n.º 2
0
    public void intervalAdded(ListDataEvent e) {
      int minIndex = Math.min(e.getIndex0(), e.getIndex1());
      int maxIndex = Math.max(e.getIndex0(), e.getIndex1());

      /* Sync the SelectionModel with the DataModel.
       */

      ListSelectionModel listSelectionModel = _list.getCheckBoxListSelectionModel();
      if (listSelectionModel != null) {
        listSelectionModel.insertIndexInterval(minIndex, maxIndex - minIndex + 1, true);
      }
    }