Java Code Examples for javax.swing.event.TableModelEvent#UPDATE

The following examples show how to use javax.swing.event.TableModelEvent#UPDATE . 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: HeaderCheckBoxHandler.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void tableChanged(TableModelEvent e) {
  int vci = table.convertColumnIndexToView(targetColumnIndex);
  TableColumn column = table.getColumnModel().getColumn(vci);
  Object status = column.getHeaderValue();
  TableModel m = table.getModel();
  boolean repaint = false;
  if (e.getType() == TableModelEvent.DELETE) {
    // System.out.println("DELETE");
    // System.out.println(status + ":   " + Status.INDETERMINATE.equals(status));
    repaint = fireDeleteEvent(m, column, status);
  } else if (e.getType() == TableModelEvent.INSERT && status != Status.INDETERMINATE) {
    // System.out.println("INSERT");
    repaint = fireInsertEvent(m, column, status, e);
  } else if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == targetColumnIndex) {
    // System.out.println("UPDATE");
    repaint = fireUpdateEvent(m, column, status);
  }
  if (repaint) {
    JTableHeader h = table.getTableHeader();
    h.repaint(h.getHeaderRect(vci));
  }
}
 
Example 2
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 3
Source File: OrderBookModel.java    From gdax-java with MIT License 6 votes vote down vote up
public void tableChanged(TableModelEvent e) {
    switch (e.getType()) {
        case TableModelEvent.DELETE: {

            fireAllChanged();
            break;
        }
        case TableModelEvent.INSERT: {

            fireAllChanged();
            break;
        }
        case TableModelEvent.UPDATE: {

            fireAllChanged();
            break;
        }
    }
}
 
Example 4
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 5
Source File: TracerSimpleReportFrame.java    From pega-tracerviewer with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent tableModelEvent) {

    if (tableModelEvent.getType() == TableModelEvent.UPDATE) {
        LOG.info("TracerSimpleReportFrame tableChanged");
        rebuildOverview();
    }
}
 
Example 6
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 7
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 8
Source File: ComplexTypePanel.java    From binnavi with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(final TableModelEvent event) {
  if (event.getType() == TableModelEvent.INSERT || event.getType() == TableModelEvent.UPDATE) {
    final MemberTableModel model = members.getModel();
    for (int i = 0; i < model.getRowCount(); i++) {
      final int modelIndex = members.convertRowIndexToModel(i);
      boolean validate = validateTableRow(i);
      model.markRow(modelIndex, validate);
    }
  }
}
 
Example 9
Source File: AbstractSortedTableModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Fires an event to let the listeners (like JTable) know that things have been changed. 
 * This method exists so that subclasses have a way to call the various <code>tableChanged()</code>
 * methods without triggering this class's overridden version.
 * @param dataChanged True signals that the actual data has changed; false signals that the
 *        data is the same, with exception that attributes of that data may be different.
 */
protected void notifyModelSorted(boolean dataChanged) {
	if (dataChanged) {
		super.fireTableChanged(new TableModelEvent(this));
	}
	else {
		super.fireTableChanged(new TableModelEvent(this, 0, getRowCount() - 1,
			TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE));
	}

	for (SortListener listener : listeners) {
		listener.modelSorted(sortState);
	}
}
 
Example 10
Source File: TracerDataView.java    From pega-tracerviewer with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent event) {

    if (event.getType() == TableModelEvent.UPDATE) {
        revalidate();
        repaint();
    }
}
 
Example 11
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 12
Source File: TableCheckBoxColumn.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@Override
public void tableChanged(TableModelEvent e) {
    if (e.getType() == TableModelEvent.UPDATE && e.getColumn() == 0) {
        int mci = 0;
        int vci = table.convertColumnIndexToView(mci);
        TableColumn column = table.getColumnModel().getColumn(vci);
        Object title = column.getHeaderValue();
        if (!Status.INDETERMINATE.equals(title)) {
            column.setHeaderValue(Status.INDETERMINATE);
        } else {
            int selected = 0, deselected = 0;
            TableModel m = table.getModel();
            for (int i = 0; i < m.getRowCount(); i++) {
                if (Boolean.TRUE.equals(m.getValueAt(i, mci))) {
                    selected++;
                } else {
                    deselected++;
                }
            }
            if (selected == 0) {
                column.setHeaderValue(Status.DESELECTED);
            } else if (deselected == 0) {
                column.setHeaderValue(Status.SELECTED);
            } else {
                return;
            }
        }
        table.getTableHeader().repaint();
    }
}
 
Example 13
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 14
Source File: JoiningTableModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.
 */
public void tableChanged( final TableModelEvent e ) {
  if ( e.getType() == TableModelEvent.UPDATE && e.getFirstRow() == TableModelEvent.HEADER_ROW ) {
    updateStructure();
  } else if ( e.getType() == TableModelEvent.INSERT || e.getType() == TableModelEvent.DELETE ) {
    updateRowCount();
  } else {
    updateData();
  }
}
 
Example 15
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 16
Source File: SimpleTable.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convenience method to detect dataChanged table event type.
 * 
 * @param e the event to examine. 
 * @return true if the event is of type dataChanged, false else.
 */
protected boolean isDataChanged(TableModelEvent e) {
    if (e == null) return false;
    return e.getType() == TableModelEvent.UPDATE && 
        e.getFirstRow() == 0 &&
        e.getLastRow() == Integer.MAX_VALUE;
}
 
Example 17
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 18
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 19
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 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;
}