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

The following examples show how to use javax.swing.event.TableModelEvent#getType() . 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: ProprietiesListener.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    
    if (e.getType() == TableModelEvent.UPDATE) {
        EditAttributeCommand command = CommandProcessor.getInstance().getCommand(EditAttributeCommand.class);
        RemoveAttributeCommand removecommand = CommandProcessor.getInstance().getCommand(RemoveAttributeCommand.class);
        TableModel mod = (TableModel) e.getSource();
        String proName = (String) mod.getValueAt(e.getLastRow(), 0);
        String proVal = (String) mod.getValueAt(e.getLastRow(), 1);
        if (proName != null && !proName.isEmpty()) {
            try{
            if (proVal == null || proVal.isEmpty()) {
                removecommand.setAttributeKey(proName);
                CommandProcessor.getInstance().excuteCommand(removecommand);
            } else {
               command.setAttribute(proName);
               command.setValue(proVal);
               CommandProcessor.getInstance().excuteCommand(command);
            }
            }catch(Exception ex){
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null,"Can't set the attribute. " + ex.getMessage());
            }
        }
    }
}
 
Example 2
Source File: TailingModeMarkersPanel.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
@Override
public void tableChanged(final TableModelEvent e) {
  final HashSet<AutomaticMarker> selected = defaultTableModel.getSelected();

  if (e.getType() == TableModelEvent.INSERT) {
    SwingUtilities.invokeLater(() -> {
      int firstRow = e.getFirstRow();
      int lastRow = e.getLastRow();
      for (int i = firstRow; i <= lastRow; i++) {
        LogData logData = dataTableModel.getLogData(i);
        for (AutomaticMarker m : selected) {
          if (m.toMark(logData)) {
            dataTableModel.markRows(m.getColors(), i);
          }
        }
      }
    });
  }
}
 
Example 3
Source File: JAutoColumnTable.java    From jeveassets with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void tableChanged(final TableModelEvent e) {
	//XXX - Workaround for Java 7
	if (getTable().isEditing()) {
		getTable().getCellEditor().cancelCellEditing();
	}
	if (e.getType() == TableModelEvent.DELETE) {
		rowsCount = rowsCount - (Math.abs(e.getFirstRow() - e.getLastRow()) + 1);
	}
	if (e.getType() == TableModelEvent.INSERT) {
		rowsCount = rowsCount + (Math.abs(e.getFirstRow() - e.getLastRow()) + 1);
	}
	if (Math.abs(rowsLastTime + rowsCount) == getRowCount() //Last Table Update
			&& (e.getType() != TableModelEvent.UPDATE
			|| (e.getType() == TableModelEvent.UPDATE && e.getFirstRow() >= 0))) {
		rowsLastTime = getRowCount();
		rowsCount = 0;
		autoResizeColumns();
	}
}
 
Example 4
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 5
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 6
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 7
Source File: XJTable.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Overridden for efficiency reasons (provides a better calculation of the 
 * dirty region). See 
 * <a href="http://www.objectdefinitions.com/odblog/2009/jtable-setrowheight-causes-slow-repainting/">this page</a>
 * for a more complete discussion. 
 */
@Override
public void tableChanged(TableModelEvent e) {
  //if just an update, and not a data or structure changed event or an insert or delete, use the fixed row update handling
  //otherwise call super.tableChanged to let the standard JTable update handling manage it
  if ( e != null &&
      e.getType() == TableModelEvent.UPDATE &&
      e.getFirstRow() != TableModelEvent.HEADER_ROW &&
      e.getLastRow() != Integer.MAX_VALUE) {
      handleRowUpdate(e);
  } else {
      super.tableChanged(e);
  }
}
 
Example 8
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 9
Source File: ModelUtils.java    From aurous-app with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void tableChanged(final TableModelEvent evt) {
	if (evt.getType() == TableModelEvent.UPDATE) {
		final int column = evt.getColumn();
		final int row = evt.getFirstRow();
		System.out.println("row: " + row + " column: " + column);
		table.setColumnSelectionInterval(column + 1, column + 1);
		table.setRowSelectionInterval(row, row);

	}
}
 
Example 10
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 11
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 12
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 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: AnnotationSettings.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent evt) {
    if (evt.getType() == TableModelEvent.UPDATE) {
        validateTable(evt.getFirstRow(), evt.getColumn());
    }
}
 
Example 15
Source File: DetailsTable.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    super.tableChanged(e);
    if (e.getType() == TableModelEvent.INSERT) updateColumns(false);
}
 
Example 16
Source File: NameFilterJPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    int type=e.getType();
    updateSelected();
}
 
Example 17
Source File: PlotterQuantityNameFilterJPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    int type=e.getType();
    updateSelected();
}
 
Example 18
Source File: DetailsTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    super.tableChanged(e);
    if (e.getType() == TableModelEvent.INSERT) updateColumns(false);
}
 
Example 19
Source File: PartitionsPanel.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void tableChanged(TableModelEvent ev) {

			if (ev.getType() == TableModelEvent.UPDATE) {
				int row = ev.getFirstRow();
				int column = ev.getColumn();

				if (column == PartitionTableModel.DATA_INDEX) {

					TreesTableRecord value = (TreesTableRecord) partitionTableModel.getValueAt(row,
							column);
					
					dataList.get(row).record = (TreesTableRecord) value;

				}// END: column check

			}// END: event check

//			 frame.collectAllSettings();

		}
 
Example 20
Source File: QuantityNameFilterJPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    int type=e.getType();
    updateSelected();
}