Java Code Examples for javax.swing.event.TableModelEvent#getLastRow()

The following examples show how to use javax.swing.event.TableModelEvent#getLastRow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertySheetTable.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void tableChanged(TableModelEvent e) {
  // in case the table changes for the following reasons:
  // * the editing row has changed
  // * the editing row was removed
  // * all rows were changed
  // * rows were added
  //
  // it is better to cancel the editing of the row as our editor
  // may no longer be the right one. It happens when you play with
  // the sorting while having the focus in one editor.
  if (e.getType() == TableModelEvent.UPDATE) {
    int first = e.getFirstRow();
    int last = e.getLastRow();
    int editingRow = PropertySheetTable.this.getEditingRow();

    TableCellEditor editor = PropertySheetTable.this.getCellEditor();
    if (editor != null && first <= editingRow && editingRow <= last) {
      editor.cancelCellEditing();
    }
  }
}
 
Example 2
Source File: HeaderCheckBoxHandler.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean fireInsertEvent(TableModel m, TableColumn column, Object status, TableModelEvent e) {
  boolean selected = status == Status.DESELECTED;
  boolean deselected = status == Status.SELECTED;
  for (int i = e.getFirstRow(); i <= e.getLastRow(); i++) {
    Boolean b = (Boolean) m.getValueAt(i, targetColumnIndex);
    selected &= b;
    deselected &= !b;
  }
  if (selected && m.getRowCount() == 1) {
    column.setHeaderValue(Status.SELECTED);
  } else if (selected || deselected) {
    column.setHeaderValue(Status.INDETERMINATE);
  } else {
    return false;
  }
  return true;
}
 
Example 3
Source File: SubSetTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This fine grain notification tells listeners the exact range of cells, rows, or columns that changed. The
 * received rows are translated to fit the external tablemodel size.
 *
 * @param e
 *          the event, that should be translated.
 */
public void tableChanged( final TableModelEvent e ) {
  int firstRow = e.getFirstRow();
  if ( e.getFirstRow() > 0 ) {
    firstRow -= getStart();
  }

  int lastRow = e.getLastRow();
  if ( lastRow > 0 ) {
    lastRow -= getStart();
    lastRow -= ( getEnclosedModel().getRowCount() - getEnd() );
  }
  final int type = e.getType();
  final int column = e.getColumn();

  final TableModelEvent event = new TableModelEvent( SubSetTableModel.this, firstRow, lastRow, column, type );

  for ( int i = 0; i < listeners.size(); i++ ) {
    final TableModelListener l = (TableModelListener) listeners.get( i );
    l.tableChanged( event );
  }
}
 
Example 4
Source File: CsvTableEditorSwing.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void updateRowHeights(TableModelEvent e) {
    final int first;
    final int last;
    if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        first = 0;
        last = this.getTable().getRowCount();
    } else {
        first = e.getFirstRow();
        last = e.getLastRow() + 1;
    }

    SwingUtilities.invokeLater(() -> {
        updateRowHeights(first, last);
    });
}
 
Example 5
Source File: GroupedTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void tableChanged( final TableModelEvent e ) {
  recomputeRowCount();
  if ( e.getFirstRow() == 0 && e.getLastRow() == Integer.MAX_VALUE ) {
    fireTableModelEvent( new TableModelEvent( GroupedTableModel.this,
      e.getFirstRow(), e.getLastRow(), e.getColumn(), e.getType() ) );
    return;
  }

  final TableModelEvent event = new TableModelEvent( GroupedTableModel.this,
    mapFromModel( e.getFirstRow() ), mapFromModel( e.getLastRow() ), e.getColumn(), e.getType() );
  fireTableModelEvent( event );
}
 
Example 6
Source File: DefaultFilterTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void tableChanged( final TableModelEvent e ) {
  recomputeRowCount();
  if ( e.getFirstRow() == 0 && e.getLastRow() == Integer.MAX_VALUE ) {
    // a table-data-changed event..
    applyFilter();
    fireTableModelEvent( new TableModelEvent( DefaultFilterTableModel.this,
      e.getFirstRow(), e.getLastRow(), e.getColumn(), e.getType() ) );
    return;
  }

  final TableModelEvent event = new TableModelEvent( DefaultFilterTableModel.this,
    mapFromModel( e.getFirstRow() ), mapFromModel( e.getLastRow() ), e.getColumn(), e.getType() );
  fireTableModelEvent( event );
}
 
Example 7
Source File: RowMapperTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void tableChanged( final TableModelEvent e ) {
  recomputeRowCount();
  if ( e.getFirstRow() == 0 && e.getLastRow() == Integer.MAX_VALUE ) {
    fireTableModelEvent( new TableModelEvent( RowMapperTableModel.this,
      e.getFirstRow(), e.getLastRow(), e.getColumn(), e.getType() ) );
    return;
  }

  final TableModelEvent event = new TableModelEvent( RowMapperTableModel.this,
    mapFromModel( e.getFirstRow() ), mapFromModel( e.getLastRow() ), e.getColumn(), e.getType() );
  fireTableModelEvent( event );
}
 
Example 8
Source File: TableSorter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.             
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }
    // If the table structure has changed, cancel the sorting; the             
    // sorting columns may have been either moved or deleted from             
    // the model. 
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }
    // We can map a cell event through to the view without widening             
    // when the following conditions apply: 
    // 
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, 
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and, 
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    // 
    // The last check, for (modelToView != null) is to see if modelToView 
    // is already allocated. If we don't do this check; sorting can become 
    // a performance bottleneck for applications where cells  
    // change rapidly in different parts of the table. If cells 
    // change alternately in the sorting column and then outside of             
    // it this class can end up re-sorting on alternate cell updates - 
    // which can be a performance problem for large tables. The last 
    // clause avoids this problem. 
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow() && column != TableModelEvent.ALL_COLUMNS && getSortingStatus(column) == NOT_SORTED && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this,
                viewIndex, viewIndex,
                column, e.getType()));
        return;
    }
    // Something has happened to the data that may have invalidated the row order. 
    clearSortingState();
    fireTableDataChanged();
    return;
}
 
Example 9
Source File: TableSorter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.             
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }
        
    // If the table structure has changed, cancel the sorting; the             
    // sorting columns may have been either moved or deleted from             
    // the model. 
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }

    // We can map a cell event through to the view without widening             
    // when the following conditions apply: 
    // 
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, 
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and, 
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    // 
    // The last check, for (modelToView != null) is to see if modelToView 
    // is already allocated. If we don't do this check; sorting can become 
    // a performance bottleneck for applications where cells  
    // change rapidly in different parts of the table. If cells 
    // change alternately in the sorting column and then outside of             
    // it this class can end up re-sorting on alternate cell updates - 
    // which can be a performance problem for large tables. The last 
    // clause avoids this problem. 
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow()
            && column != TableModelEvent.ALL_COLUMNS
            && getSortingStatus(column) == NOT_SORTED
            && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this, 
                                             viewIndex, viewIndex, 
                                             column, e.getType()));
        return;
    }

    // Something has happened to the data that may have invalidated the row order. 
    clearSortingState();
    fireTableDataChanged();
}
 
Example 10
Source File: TableSorter.java    From evosql with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {

            // If we're not sorting by anything, just pass the event along.
            if (!isSorting()) {
                clearSortingState();
                fireTableChanged(e);

                return;
            }

            // If the table structure has changed, cancel the sorting; the
            // sorting columns may have been either moved or deleted from
            // the model.
            if (e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW) {
                cancelSorting();
                fireTableChanged(e);

                return;
            }

            // We can map a cell event through to the view without widening
            // when the following conditions apply:
            //
            // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
            // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
            // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
            // d) a reverse lookup will not trigger a sort (modelToView != null)
            //
            // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
            //
            // The last check, for (modelToView != null) is to see if modelToView
            // is already allocated. If we don't do this check; sorting can become
            // a performance bottleneck for applications where cells
            // change rapidly in different parts of the table. If cells
            // change alternately in the sorting column and then outside of
            // it this class can end up re-sorting on alternate cell updates -
            // which can be a performance problem for large tables. The last
            // clause avoids this problem.
            int column = e.getColumn();

            if (e.getFirstRow() == e.getLastRow()
                    && column != TableModelEvent.ALL_COLUMNS
                    && getSortingStatus(column) == NOT_SORTED
                    && modelToView != null) {
                int viewIndex = getModelToView()[e.getFirstRow()];

                fireTableChanged(new TableModelEvent(TableSorter.this,
                                                     viewIndex, viewIndex,
                                                     column, e.getType()));

                return;
            }

            // Something has happened to the data that may have invalidated the row order.
            clearSortingState();
            fireTableDataChanged();

            return;
        }
 
Example 11
Source File: TableSorter.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }

    // If the table structure has changed, cancel the sorting; the
    // sorting columns may have been either moved or deleted from
    // the model.
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }

    // We can map a cell event through to the view without widening
    // when the following conditions apply:
    //
    // a) all the changes are on one row (e.getFirstRow() ==
    // e.getLastRow()) and,
    // b) all the changes are in one column (column !=
    // TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) ==
    // NOT_SORTED) and,
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column
    // == ALL_COLUMNS.
    //
    // The last check, for (modelToView != null) is to see if
    // modelToView
    // is already allocated. If we don't do this check; sorting can
    // become
    // a performance bottleneck for applications where cells
    // change rapidly in different parts of the table. If cells
    // change alternately in the sorting column and then outside of
    // it this class can end up re-sorting on alternate cell updates -
    // which can be a performance problem for large tables. The last
    // clause avoids this problem.
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow() && column != TableModelEvent.ALL_COLUMNS && getSortingStatus(column) == NOT_SORTED
            && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this, viewIndex, viewIndex, column, e.getType()));
        return;
    }

    // Something has happened to the data that may have invalidated the
    // row order.
    clearSortingState();
    fireTableDataChanged();
    return;
}
 
Example 12
Source File: TableSorter.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public void tableChanged(TableModelEvent e) {
  // If we're not sorting by anything, just pass the event along.
  if (!isSorting()) {
    clearSortingState();
    fireTableChanged(e);
    return;
  }

  // If the table structure has changed, cancel the sorting; the
  // sorting columns may have been either moved or deleted from
  // the model.
  if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
    cancelSorting();
    fireTableChanged(e);
    return;
  }

  // We can map a cell event through to the view without widening
  // when the following conditions apply:
  //
  // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
  // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
  // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
  // d) a reverse lookup will not trigger a sort (modelToView != null)
  //
  // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
  //
  // The last check, for (modelToView != null) is to see if modelToView
  // is already allocated. If we don't do this check; sorting can become
  // a performance bottleneck for applications where cells
  // change rapidly in different parts of the table. If cells
  // change alternately in the sorting column and then outside of
  // it this class can end up re-sorting on alternate cell updates -
  // which can be a performance problem for large tables. The last
  // clause avoids this problem.
  int column = e.getColumn();
  int fr = e.getFirstRow();
  int lr = e.getLastRow();
  if (fr == lr && column != TableModelEvent.ALL_COLUMNS && getSortingStatus(column) == NOT_SORTED) {
    int viewIndex = getModelToView().get(fr);
    fireTableChanged(new TableModelEvent(TableSorter.this, viewIndex, viewIndex, column, e.getType()));
    return;
  }

  // Something has happened to the data that may have invalidated the row order.
  clearSortingState();
  fireTableDataChanged();
  // return;
}
 
Example 13
Source File: TableSorter.java    From tda with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.             
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }
        
    // If the table structure has changed, cancel the sorting; the             
    // sorting columns may have been either moved or deleted from             
    // the model. 
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }

    // We can map a cell event through to the view without widening             
    // when the following conditions apply: 
    // 
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, 
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and, 
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    // 
    // The last check, for (modelToView != null) is to see if modelToView 
    // is already allocated. If we don't do this check; sorting can become 
    // a performance bottleneck for applications where cells  
    // change rapidly in different parts of the table. If cells 
    // change alternately in the sorting column and then outside of             
    // it this class can end up re-sorting on alternate cell updates - 
    // which can be a performance problem for large tables. The last 
    // clause avoids this problem. 
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow()
            && column != TableModelEvent.ALL_COLUMNS
            && getSortingStatus(column) == NOT_SORTED
            && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this, 
                                             viewIndex, viewIndex, 
                                             column, e.getType()));
        return;
    }

    // Something has happened to the data that may have invalidated the row order. 
    clearSortingState();
    fireTableDataChanged();
    return;
}
 
Example 14
Source File: ExtendedJTableSorterModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
	// If we're not sorting by anything, just pass the event along.
	if (!isSorting()) {
		clearSortingState();
		fireTableChanged(e);
		return;
	}

	// If the table structure has changed, cancel the sorting; the
	// sorting columns may have been either moved or deleted from
	// the model.
	if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
		cancelSorting();
		fireTableChanged(e);
		return;
	}

	// We can map a cell event through to the view without widening
	// when the following conditions apply:
	//
	// a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
	// b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
	// c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
	// d) a reverse lookup will not trigger a sort (modelToView != null)
	//
	// Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
	//
	// The last check, for (modelToView != null) is to see if modelToView
	// is already allocated. If we don't do this check; sorting can become
	// a performance bottleneck for applications where cells
	// change rapidly in different parts of the table. If cells
	// change alternately in the sorting column and then outside of
	// it this class can end up re-sorting on alternate cell updates -
	// which can be a performance problem for large tables. The last
	// clause avoids this problem.
	int column = e.getColumn();
	if (e.getFirstRow() == e.getLastRow() && column != TableModelEvent.ALL_COLUMNS
			&& getSortingStatus(column) == NOT_SORTED && modelToView != null) {
		int viewIndex = getModelToView()[e.getFirstRow()];
		fireTableChanged(new TableModelEvent(ExtendedJTableSorterModel.this, viewIndex, viewIndex, column,
				e.getType()));
		return;
	}

	// Something has happened to the data that may have invalidated the row order.
	clearSortingState();
	fireTableDataChanged();
	return;
}
 
Example 15
Source File: TableSorter.java    From cropplanning with GNU General Public License v3.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.             
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }
        
    // If the table structure has changed, cancel the sorting; the             
    // sorting columns may have been either moved or deleted from             
    // the model. 
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }

    // We can map a cell event through to the view without widening             
    // when the following conditions apply: 
    // 
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, 
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and, 
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    // 
    // The last check, for (modelToView != null) is to see if modelToView 
    // is already allocated. If we don't do this check; sorting can become 
    // a performance bottleneck for applications where cells  
    // change rapidly in different parts of the table. If cells 
    // change alternately in the sorting column and then outside of             
    // it this class can end up re-sorting on alternate cell updates - 
    // which can be a performance problem for large tables. The last 
    // clause avoids this problem. 
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow()
            && column != TableModelEvent.ALL_COLUMNS
            && getSortingStatus(column) == NOT_SORTED
            && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this, 
                                             viewIndex, viewIndex, 
                                             column, e.getType()));
        return;
    }

    // Something has happened to the data that may have invalidated the row order. 
    clearSortingState();
    fireTableDataChanged();
    return;
}
 
Example 16
Source File: TableSorter.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }

    // If the table structure has changed, cancel the sorting; the
    // sorting columns may have been either moved or deleted from
    // the model.
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }

    // We can map a cell event through to the view without widening
    // when the following conditions apply:
    //
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    //
    // The last check, for (modelToView != null) is to see if modelToView
    // is already allocated. If we don't do this check; sorting can become
    // a performance bottleneck for applications where cells
    // change rapidly in different parts of the table. If cells
    // change alternately in the sorting column and then outside of
    // it this class can end up re-sorting on alternate cell updates -
    // which can be a performance problem for large tables. The last
    // clause avoids this problem.
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow()
            && column != TableModelEvent.ALL_COLUMNS
            && getSortingStatus(column) == NOT_SORTED
            && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this,
                                             viewIndex, viewIndex,
                                             column, e.getType()));
        return;
    }

    // Something has happened to the data that may have invalidated the row order.
    clearSortingState();
    fireTableDataChanged();
    return;
}
 
Example 17
Source File: TableSorter.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }

    // If the table structure has changed, cancel the sorting; the
    // sorting columns may have been either moved or deleted from
    // the model.
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }

    // We can map a cell event through to the view without widening
    // when the following conditions apply:
    //
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    //
    // The last check, for (modelToView != null) is to see if modelToView
    // is already allocated. If we don't do this check; sorting can become
    // a performance bottleneck for applications where cells
    // change rapidly in different parts of the table. If cells
    // change alternately in the sorting column and then outside of
    // it this class can end up re-sorting on alternate cell updates -
    // which can be a performance problem for large tables. The last
    // clause avoids this problem.
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow()
            && column != TableModelEvent.ALL_COLUMNS
            && getSortingStatus(column) == NOT_SORTED
            && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this,
                                             viewIndex, viewIndex,
                                             column, e.getType()));
        return;
    }

    // Something has happened to the data that may have invalidated the row order.
    clearSortingState();
    fireTableDataChanged();
}
 
Example 18
Source File: TableSorter.java    From jplag with GNU General Public License v3.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.             
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }
        
    // If the table structure has changed, cancel the sorting; the             
    // sorting columns may have been either moved or deleted from             
    // the model. 
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }

    // We can map a cell event through to the view without widening             
    // when the following conditions apply: 
    // 
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, 
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and, 
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    // 
    // The last check, for (modelToView != null) is to see if modelToView 
    // is already allocated. If we don't do this check; sorting can become 
    // a performance bottleneck for applications where cells  
    // change rapidly in different parts of the table. If cells 
    // change alternately in the sorting column and then outside of             
    // it this class can end up re-sorting on alternate cell updates - 
    // which can be a performance problem for large tables. The last 
    // clause avoids this problem. 
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow()
            && column != TableModelEvent.ALL_COLUMNS
            && getSortingStatus(column) == NOT_SORTED
            && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this, 
                                             viewIndex, viewIndex, 
                                             column, e.getType()));
        return;
    }

    // Something has happened to the data that may have invalidated the row order. 
    clearSortingState();
    fireTableDataChanged();
    return;
}
 
Example 19
Source File: TableSorter.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    // If we're not sorting by anything, just pass the event along.             
    if (!isSorting()) {
        clearSortingState();
        fireTableChanged(e);
        return;
    }
    // If the table structure has changed, cancel the sorting; the             
    // sorting columns may have been either moved or deleted from             
    // the model. 
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        cancelSorting();
        fireTableChanged(e);
        return;
    }
    // We can map a cell event through to the view without widening             
    // when the following conditions apply: 
    // 
    // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, 
    // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
    // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and, 
    // d) a reverse lookup will not trigger a sort (modelToView != null)
    //
    // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
    // 
    // The last check, for (modelToView != null) is to see if modelToView 
    // is already allocated. If we don't do this check; sorting can become 
    // a performance bottleneck for applications where cells  
    // change rapidly in different parts of the table. If cells 
    // change alternately in the sorting column and then outside of             
    // it this class can end up re-sorting on alternate cell updates - 
    // which can be a performance problem for large tables. The last 
    // clause avoids this problem. 
    int column = e.getColumn();
    if (e.getFirstRow() == e.getLastRow() && column != TableModelEvent.ALL_COLUMNS && getSortingStatus(column) == NOT_SORTED && modelToView != null) {
        int viewIndex = getModelToView()[e.getFirstRow()];
        fireTableChanged(new TableModelEvent(TableSorter.this,
                viewIndex, viewIndex,
                column, e.getType()));
        return;
    }
    // Something has happened to the data that may have invalidated the row order. 
    clearSortingState();
    fireTableDataChanged();
    return;
}
 
Example 20
Source File: SimpleTable.java    From wandora with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Convenience method to detect update table event type.
 * 
 * @param e the event to examine. 
 * @return true if the event is of type update and not dataChanged, false else.
 */
protected boolean isUpdate(TableModelEvent e) {
    if (isStructureChanged(e)) return false;
    return e.getType() == TableModelEvent.UPDATE && 
        e.getLastRow() < Integer.MAX_VALUE;
}