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

The following examples show how to use javax.swing.event.TableModelEvent#getFirstRow() . 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: SchemaPanel.java    From netbeans with Apache License 2.0 8 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    //System.out.println("TBALE changed");
    //boolean prefixFlag = false;
    int row = e.getFirstRow();
    int column = e.getColumn();
    AbstractTableModel tblModel = (AbstractTableModel) e.getSource();
    Object data = tblModel.getValueAt(row, column);
    if(column == SCHEMA_COL) {
        SchemaObject rowValue = (SchemaObject)data;
        if(rowValue.toString().equals(startString))
            return;
        String genPrefix = (String) tblModel.getValueAt(row, PREFIX_COL);
        if (genPrefix == null || genPrefix.equals(" ")  ) {
            String prefix = generateUniquePrefix();               
            tableModel.setValueAt(prefix, row, PREFIX_COL);                 
        }
        if(row == tableModel.getRowCount() - 1) {
            addRow(startString);
        }
        //if its the first row, then select it as primary
        if(row == 0) {
           // System.out.println("added first row");
            tblModel.setValueAt(new Boolean(true), 0, 0);
        }
    } 
}
 
Example 2
Source File: PropertySheetTable.java    From orbit-image-analysis with GNU General Public License v3.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 3
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 4
Source File: TagTableModel.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent event) {
    tablePanelController.logger.debug(String.format("\"%s\" table changed: %d at %d, %d (INS=1, UPD=0, DEL=-1)", getAssociatedTagTypeName(), event.getType(), event.getFirstRow(), event.getColumn()));

    if (event.getFirstRow() == -1 && event.getColumn() == -1) {
        // ignore changes happened out of table (when initially setting up tables)
        return;
    }
    if (event.getType() == TableModelEvent.UPDATE) {
        // INSERT: listen to insertion is unnecessary, since adding a new tag never happens through table
        // DELETE: since we cannot recover what's already deleted anyway,
        // propagated deletion should be called right before the deletion of a row happens
        // that is, in DeleteTag action, not here, after deletion
        String tid = (String) getValueAt(event.getFirstRow(), TablePanelController.ID_COL);
        List<Integer> oldSpans = Collections.emptyList();
        try {
            oldSpans = tablePanelController.getDriver().getAnchorLocationsByTid(tid);
        } catch (MaeDBException e) {
            tablePanelController.getMainController().showError(e);
        }
        String colName = getColumnName(event.getColumn());
        String value = (String) getValueAt(event.getFirstRow(), event.getColumn());
        // this will return false if update fails
        boolean updated = tablePanelController.getMainController().updateDBFromTableUpdate(tid, colName, value);
        if (!updated) {
            revertChange(event.getFirstRow(), event.getColumn());
        } else {
            propagateChange(event, tid, value, oldSpans);
        }

    }
}
 
Example 5
Source File: ScrollingTableFix.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
        if (scrollPane.getViewport().getWidth() < table.getPreferredSize().getWidth()) {
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        }
        else {
            table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        }
    }
}
 
Example 6
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 7
Source File: TablePanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new {@link TablePanel} instance.
 *
 * @param model
 * @param useScrollPane
 *            if set to <code>true</code>, will add a scrollpane around the GUI.
 * @param hideUnavailableContentAssist
 *            if <code>true</code>, the content assist button will be hidden if no content
 *            assist is available for the given field
 */
public TablePanel(final TablePanelModel model, boolean useScrollPane, boolean hideUnavailableContentAssist) {
	this.mapOfComponents = new HashMap<>();
	this.useScrollPane = useScrollPane;
	this.hideUnavailableContentAssist = hideUnavailableContentAssist;
	this.listener = new TableModelListener() {

		@Override
		public void tableChanged(TableModelEvent e) {
			// table structure changed, re-create it
			if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
				createGUI();
			} else {
				updateComponent(e.getFirstRow(), e.getColumn());
			}
		}
	};

	SwingUtilities.invokeLater(new Runnable() {

		@Override
		public void run() {
			initGUI();
			setModel(model);
		}

	});
}
 
Example 8
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 9
Source File: TableEditor.java    From jdal with Apache License 2.0 5 votes vote down vote up
public void tableChanged(TableModelEvent e) {
	if (e.getType() == TableModelEvent.UPDATE) {
		int row = e.getFirstRow();
		if (row >= 0) {
			setDirtyRow(row);
		}
	}
}
 
Example 10
Source File: EventBroadcaster.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String tableModelEventToString (TableModelEvent e) {
    StringBuilder sb = new StringBuilder();
    sb.append ("TableModelEvent ");
    switch (e.getType()) {
        case TableModelEvent.INSERT : sb.append ("insert ");
             break;
        case TableModelEvent.DELETE : sb.append ("delete ");
             break;
        case TableModelEvent.UPDATE : sb.append ("update ");
             break;
        default : sb.append("Unknown type ").append(e.getType());
    }
    sb.append ("from ");
    switch (e.getFirstRow()) {
        case TableModelEvent.HEADER_ROW : sb.append ("header row ");
            break;
        default : sb.append (e.getFirstRow());
                  sb.append (' ');
    }
    sb.append ("to ");
    sb.append (e.getLastRow());
    sb.append (" column ");
    switch (e.getColumn()) {
        case TableModelEvent.ALL_COLUMNS :
            sb.append ("ALL_COLUMNS");
            break;
        default : sb.append (e.getColumn());
    }
    return sb.toString();
}
 
Example 11
Source File: QueryBuilderGraphFrame.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void tableModelChanged(TableModelEvent e) {
    
    Log.getLogger().entering("QueryBuilderGraphFrame", "tableModelChanged");

    // We have a mouse click inside a graph table node, indicating select/deselect.
    // Propagate the information to the input table
    
    // Extract some information from the event
    int row = e.getFirstRow();   // the first row that changed
    int column = e.getColumn();  // the column for this event
    
    QueryBuilderTableModel model = (QueryBuilderTableModel) e.getSource();
    String tableSpec = model.getTableSpec();
    
    // DB column name
    String columnName = (String) model.getValueAt(row, column+2);
    
    // boolean - Selected/deselected
    Object value = model.getValueAt(row, column);
    
    if (value==Boolean.TRUE) {      // A column has been selected
        
        // Update the query model if appropriate
        // Do this first so that it's available when adding the row
        if (_queryBuilder._updateModel) {
            _queryBuilder.getQueryModel().addColumn(tableSpec, columnName);
            _queryBuilderInputTable.selectColumn(tableSpec, columnName, Boolean.TRUE);
        }
    }
    
    else if (value==Boolean.FALSE) { // A column has been deselected
        
        // Update the query model, if we're not being driven by it
        // Do this before updating the grid, because we use the model to generate sortorder
        if (_queryBuilder._updateModel) {
            _queryBuilder.getQueryModel().removeColumn(tableSpec, columnName); }
        
        // do not remove the whole row, just deselect the output column.
        _queryBuilderInputTable.selectColumn(tableSpec, columnName, Boolean.FALSE);
    }
    
    // We used to update the text query after every event.  That
    // caused degraded performance.  Now, we check whether we've
    // received a real event, or we're generating the graph as a
    // batch operation.  Also, we trigger only on TableModel events,
    // so InputTableMode must explicitly invoke
    if (_queryBuilder._updateText) {
        // An interactive event -- update the text query
        _queryBuilder.generateText();
    }
}
 
Example 12
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 13
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 14
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 15
Source File: TableSorter.java    From Logisim with GNU 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(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 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 17
Source File: SimpleTable.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
public UpdateHandler(TableModelEvent e) {
    firstModelRow = e.getFirstRow();
    lastModelRow = e.getLastRow();
    convert();
}
 
Example 18
Source File: CTableSorter.java    From binnavi with Apache License 2.0 4 votes vote down vote up
@Override
public void tableChanged(final 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.
  final int column = e.getColumn();
  if ((e.getFirstRow() == e.getLastRow()) && (column != TableModelEvent.ALL_COLUMNS)
      && (getSortingStatus(column) == NOT_SORTED) && (modelToView != null)) {
    final int viewIndex = getModelToView()[e.getFirstRow()];
    fireTableChanged(new TableModelEvent(CTableSorter.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 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 20
Source File: SimpleTable.java    From wandora with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Convenience method to detect a structureChanged table event type.
 * @param e the event to examine.
 * @return true if the event is of type structureChanged or null, false else.
 */
protected boolean isStructureChanged(TableModelEvent e) {
    return e == null || e.getFirstRow() == TableModelEvent.HEADER_ROW;
}