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

The following examples show how to use javax.swing.event.TableModelEvent#getColumn() . 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: BarChartTab.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The underlying model has changed.
 */
public void tableChanged(TableModelEvent e) {
 if ((e.getType() == TableModelEvent.INSERT) ||
		 (e.getType() == TableModelEvent.DELETE)) {
	 loadCategories();
	 fireDatasetChanged();
 }
 else if (e.getColumn() == TableModelEvent.ALL_COLUMNS) fireDatasetChanged();
 else {
	 boolean dataChanged = false;
	 for (int column : columns) {
		 if (column == e.getColumn()) dataChanged = true;
	 }
	 if (dataChanged) {
		 long time = System.nanoTime() / 1000000L;
		 if ((time - lastUpdateTime) > MIN_TIME_BETWEEN_UPDATES) {
			 lastUpdateTime = time;
			 fireDatasetChanged();
		 }
	 }
 }
}
 
Example 2
Source File: CustomizerWar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    if (e.getColumn() != 1) {
        return;
    }
    TableModel listModel = uiProperties.WAR_CONTENT_ADDITIONAL_MODEL;
    ClassPathSupport.Item cpItem = (ClassPathSupport.Item) listModel.getValueAt(e.getFirstRow(), 0);
    String newPathInWar = (String) listModel.getValueAt(e.getFirstRow(), 1);
    String message = null;
    if (cpItem.getType() == ClassPathSupport.Item.TYPE_JAR && newPathInWar.startsWith("WEB-INF")) { //NOI18N
        if (newPathInWar.equals("WEB-INF\\lib") || newPathInWar.equals("WEB-INF/lib")) { //NOI18N
            if (cpItem.getResolvedFile().isDirectory()) {
                message = NbBundle.getMessage(CustomizerWar.class,
                    "MSG_NO_FOLDER_IN_WEBINF_LIB", newPathInWar); // NOI18N
            } else {
                message = NbBundle.getMessage(CustomizerWar.class,
                    "MSG_NO_FILE_IN_WEBINF_LIB", newPathInWar); // NOI18N
            }
        } else if (newPathInWar.equals("WEB-INF\\classes") || newPathInWar.equals("WEB-INF/classes")) { //NOI18N
                message = NbBundle.getMessage(CustomizerWar.class,
                    "MSG_NO_FOLDER_IN_WEBINF_CLASSES", newPathInWar); // NOI18N
        }
    }
    if (message != null) {
        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message (message, NotifyDescriptor.WARNING_MESSAGE));
    }
}
 
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: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void tableChanged(TableModelEvent e) {
  if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == targetColumnIndex) {
    int vci = table.convertColumnIndexToView(targetColumnIndex);
    TableColumn column = table.getColumnModel().getColumn(vci);
    Object status = column.getHeaderValue();
    TableModel m = table.getModel();
    if (m instanceof DefaultTableModel && fireUpdateEvent((DefaultTableModel) m, column, status)) {
      JTableHeader h = table.getTableHeader();
      h.repaint(h.getHeaderRect(vci));
    }
  }
}
 
Example 5
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 6
Source File: HeaderCheckBoxHandler.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void tableChanged(TableModelEvent e) {
  if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == targetColumnIndex) {
    int vci = table.convertColumnIndexToView(targetColumnIndex);
    TableColumn column = table.getColumnModel().getColumn(vci);
    Object status = column.getHeaderValue();
    TableModel m = table.getModel();
    if (m instanceof DefaultTableModel && fireUpdateEvent((DefaultTableModel) m, column, status)) {
      JTableHeader h = table.getTableHeader();
      h.repaint(h.getHeaderRect(vci));
    }
  }
}
 
Example 7
Source File: CertificatesManagerSettingsPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
	int row = e.getFirstRow();
    int column = e.getColumn();
    if (column == 2) {
        TableModel model = (TableModel) e.getSource();
        Boolean checked = (Boolean) model.getValueAt(row, column);
		certControll.addOrRemoveFromExceptionList(checked);
	}
}
 
Example 8
Source File: ClassesInfoPanel.java    From hprof-tools with MIT License 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent event) {
    if (event.getFirstRow() == 0 && event.getColumn() == 0) {
        String query = dataTable.getModel().getValueAt(0, 0).toString();
        presenter.onQueryByName(query);
    }
}
 
Example 9
Source File: AdjudicationTableModel.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
@Override
void propagateChange(TableModelEvent event, String tid, String newValue, List<Integer> oldSpans) {
    if (event.getColumn() == TablePanelController.SPANS_COL) {
        try {
            propagateToCurrentTableAndGetNewText(event, newValue, oldSpans);
        } catch (MaeException ignored) {
            // this spanstring is already validated within getMain().updateDB() method
        }
    }
}
 
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: AdminTool.java    From jplag with GNU General Public License v3.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
	if (e.getColumn() == TableModelEvent.ALL_COLUMNS)
		return;
	BackedUserData bud = getUserTableModel().getBackedUserData(e.getFirstRow());
	userDataChanged(bud);
}
 
Example 12
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 13
Source File: XJTable.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This gets events from the source model and forwards them to the UI
 */
@Override
public void tableChanged(TableModelEvent e){
  int type = e.getType();
  int firstRow = e.getFirstRow();
  int lastRow = e.getLastRow();
  int column = e.getColumn();
  
  //deal with the changes in the data
  //we have no way to "repair" the sorting on data updates so we will need
  //to rebuild the order every time
  
  switch(type){
    case TableModelEvent.UPDATE:
      if(firstRow == TableModelEvent.HEADER_ROW){
        //complete structure change -> reallocate the data
        init(sourceModel);
        newColumns();
        fireTableStructureChanged();
        if(isSortable()) sort();
      }else if(lastRow == Integer.MAX_VALUE){
        //all data changed (including the number of rows)
        init(sourceModel);
        if(isSortable()){
          sort();
        } else {
          //this will re-create all rows (which deletes the rowModel in JTable)
          componentSizedProperly = false;
          fireTableDataChanged();
        }
      }else{
        //the rows should have normal values
        //if the sortedColumn is not affected we don't care
        if(isSortable() &&
           (column == sortedColumn || 
            column == TableModelEvent.ALL_COLUMNS)){
            //re-sorting will also fire the event upwards
            sort();
        }else{
          componentSizedProperly = false;
          fireTableChanged(new TableModelEvent(this,  
                  sourceToTarget(firstRow), 
                  sourceToTarget(lastRow), column, type));
          
        }
      }
      break;
    case TableModelEvent.INSERT:
      //rows were inserted -> we need to rebuild
      init(sourceModel);
      if(firstRow != TableModelEvent.HEADER_ROW && firstRow == lastRow){
        //single row insertion
        if(isSortable()) sort();
        else{
          componentSizedProperly = false;
          fireTableChanged(new TableModelEvent(this,  
                sourceToTarget(firstRow), 
                sourceToTarget(lastRow), column, type));
        }
      }else{
        //the real rows are not in sequence
        if(isSortable()) sort();
        else {
          //this will re-create all rows (which deletes the rowModel in JTable)
          componentSizedProperly = false;
          fireTableDataChanged();
        }
      }
      break;
    case TableModelEvent.DELETE:
      //rows were deleted -> we need to rebuild
      init(sourceModel);
      if(isSortable()) sort();
      else {
        //this will re-create all rows (which deletes the rowModel in JTable)
        componentSizedProperly = false;
        fireTableDataChanged();
      }
  }
}
 
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 wandora 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: 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 18
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 19
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 20
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;
}