/** * Creates and returns a RowSorterListener which re-fires received * events. * * @return */ protected RowSorterListener getRowSorterListener() { if (rowSorterListener == null) { RowSorterListener listener = new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { if (RowSorterEvent.Type.SORT_ORDER_CHANGED == e.getType()) { fireSortOrderChanged(); } else if (RowSorterEvent.Type.SORTED == e.getType()) { fireRowSorterChanged(null); } } }; rowSorterListener = listener; } return rowSorterListener; }
/** * Called after notification from RowSorter. * * @param e RowSorter event of type SORTED. */ protected void sortedChanged(RowSorterEvent e) { sorterChanged = true; if (!ignoreSortChange) { prepareForChange(e); processChange(null); // PENDING Jw: this is fix of 1161-swingx - not updated after setting // rowFilter // potentially costly? but how to distinguish a mere sort from a // filterchanged? (only the latter requires a revalidate) // first fix had only revalidate/repaint but was not // good enough, see #1261-swingx - no items visible // after setting rowFilter // need to invalidate the cell size cache which might be needed // even after plain sorting as the indi-sizes are now at different // positions list.invalidateCellSizeCache(); } }
private int convertRowIndexToModel(RowSorterEvent e, int viewIndex) { // JW: the event is null if the selection is cached in prepareChange // after model notification. Then the conversion from the // sorter is still valid as the prepare is called before // notifying the sorter. if (e != null) { if (e.getPreviousRowCount() == 0) { return viewIndex; } // range checking handled by RowSorterEvent return e.convertPreviousRowIndexToModel(viewIndex); } // Make sure the viewIndex is valid if (viewIndex < 0 || viewIndex >= sorter.getViewRowCount()) { return -1; } return sorter.convertRowIndexToModel(viewIndex); }
/** * */ private void maybeRepaintOnSorterChanged(RowSorterEvent e) { if (beforeSort == null) return; if ((e == null) || (e.getType() != RowSorterEvent.Type.SORTED)) return; UpdateHandler afterSort = new UpdateHandler(beforeSort); if (afterSort.allHidden(beforeSort)) { return; } else if (afterSort.complex(beforeSort)) { repaint(); return; } int firstRow = afterSort.getFirstCombined(beforeSort); int lastRow = afterSort.getLastCombined(beforeSort); Rectangle first = getCellRect(firstRow, 0, false); first.width = getWidth(); Rectangle last = getCellRect(lastRow, 0, false); repaint(first.union(last)); }
@Override public void sorterChanged(RowSorterEvent e) { if (e.getType() == Type.SORT_ORDER_CHANGED) { @SuppressWarnings("unchecked") List<? extends SortKey> sortKeys = e.getSource().getSortKeys(); Object[] keys = new Object[sortKeys.size()]; boolean[] directions = new boolean[sortKeys.size()]; int index = 0; for (SortKey s : sortKeys) { keys[index] = SwingTable.this.keys[s.getColumn()]; directions[index] = s.getSortOrder() == SortOrder.ASCENDING; index++; } if (list instanceof Sortable) { ((Sortable) list).sort(keys, directions); } setOffset(0); } }
@Override public void sorterChanged(final RowSorterEvent e) { if (e == null || e.getType() == RowSorterEvent.Type.SORT_ORDER_CHANGED) { if (this.getTable().getCellEditor() != null) { this.getTable().getCellEditor().stopCellEditing(); } } if (e == null || e.getType() == RowSorterEvent.Type.SORTED) { //System.out.println("SORTED"); /* if (this.getSelectedRow() >= 0) { System.out.println(this.getTable().convertRowIndexToModel(this.getSelectedRow()) + "\t" + this.getTable().convertRowIndexToView(this.getSelectedRow()) + "\t" + this.getSelectedRow()); } */ if (myDBPanel1 != null) { //myDBPanel1.handleSuchfeldChange(null, false); // handleSuchfeldChange hier oben stehen lassen??? Oder lieber runter?? doFilter = false, weil sonst StackOverflow! syncTableRowHeights(); int selID = this.getSelectedID(); this.setSelectedID(selID, true); myDBPanel1.handleSuchfeldChange(null, false); // doFilter = false, weil sonst StackOverflow! } } }
@Override public void sorterChanged(RowSorterEvent e) { if (inputTable.isEditing()) { inputTable.getCellEditor().stopCellEditing(); } if (e.getSource() == table.getRowSorter()) { int idColumn = UI.findColumn(table, TracingColumns.ID); for (int row = 0; row < table.getRowCount(); row++) { String id = (String) table.getValueAt(row, idColumn); inputTable.setValueAt(values.get(id), row, 0); } } }
private void maybeRepaintOnSorterChanged(RowSorterEvent e) { if (beforeSort == null) return; if ((e == null) || (e.getType() != RowSorterEvent.Type.SORTED)) return; UpdateHandler afterSort = new UpdateHandler(beforeSort); if (afterSort.allHidden(beforeSort)) { return; } else if (afterSort.complex(beforeSort)) { repaint(); return; } int firstRow = afterSort.getFirstCombined(beforeSort); int lastRow = afterSort.getLastCombined(beforeSort); Rectangle first = getCellRect(firstRow, 0, false); first.width = getWidth(); Rectangle last = getCellRect(lastRow, 0, false); repaint(first.union(last)); }
@Override public synchronized void sorterChanged(RowSorterEvent e) { //the sort listener waits for changes on the sorted columns //if the first sort key is the stock_name or the open_price column //(that are fields that never change) it disable the dynamic sort if (e.getType().equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) { List<RowSorter.SortKey> keys = e.getSource().getSortKeys(); if(!keys.isEmpty()) { int y = keys.get(0).getColumn(); if (y != 0 && y != 11) { enableDynamicSort(true); } else { enableDynamicSort(false); } } } }
@Override public void sorterChanged(RowSorterEvent e) { String aid = selectedActionId; int colIndex = getSelectedColumn(); super.sorterChanged(e); restoreSelection(aid, colIndex); }
void fireRowSorterChanged(RowSorterEvent event) { Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == RowSorterListener.class) { ((RowSorterListener) listeners[i + 1]).sorterChanged(event); } } }
/** * Creates a new instance of <code>AbstractInstrumentsDbTable</code> */ public AbstractInstrumentsDbTable(InstrumentsDbTableModel model, String tablePrefix) { super(model); setView(CC.getViewConfig().getInstrumentsDbTableView()); this.tablePrefix = tablePrefix; loadColumnsVisibleState(); loadColumnWidths(); setAutoResizeMode(AUTO_RESIZE_OFF); rowSorter = new InstrumentsDbTableRowSorter(getModel()); setRowSorter(rowSorter); loadSortOrder(); RowSorterListener l = new RowSorterListener() { public void sorterChanged(RowSorterEvent e) { if(e.getType() != SORT_ORDER_CHANGED) return; rowSorterChanged(); } }; getRowSorter().addRowSorterListener(l); putClientProperty("JTable.autoStartsEdit", false); nameEditor = new DefaultCellEditor(tfEditor); nameEditor.setClickCountToStart(5); if( getModel().getShowDummyColumn()) { TableColumn dummy; dummy = getColumnModel().getColumn(getModel().getDummyColumnIndex()); dummy.setPreferredWidth(10); } }
/** * Hack around core issue 6791934: sets the sorter changed flag if appropriate. * Called after processing the event. * @param e the sorter event received from the sorter */ protected void postprocessSorterChanged(RowSorterEvent e) { filteredRowCountChanged = false; if (forceRevalidate && e.getType() == RowSorterEvent.Type.SORTED) { filteredRowCountChanged = e.getPreviousRowCount() != getRowCount(); } }
/** * Converts the selection to model coordinates. This is used when * the model changes or the sorter changes. */ private int[] convertSelectionToModel(RowSorterEvent e) { int[] selection = list.getSelectedIndices(); for (int i = selection.length - 1; i >= 0; i--) { selection[i] = convertRowIndexToModel(e, selection[i]); } return selection; }
/** * Creates and returns a RowSorterListener. This implementation * calls sortedChanged if the event is of type SORTED. * * @return rowSorterListener to install on sorter. */ protected RowSorterListener createRowSorterListener() { RowSorterListener l = new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { if (e.getType() == RowSorterEvent.Type.SORTED) { sortedChanged(e); } } }; return l; }
/** * When user sorts the table, we have to cancel current combobox for * identity selection. Unfortunately, this doesn't happen automatically. */ public void sorterChanged(RowSorterEvent e) { if (currentEditor != null) { currentEditor.stopCellEditing(); } super.sorterChanged(e); }
@SuppressWarnings("unchecked") @Override public void sorterChanged(RowSorterEvent e) { RowSorter<TableModel> rowSorter = e.getSource(); if (e.getSource() == scrollableTable.getRowSorter()) { fixedTable.setRowSorter(rowSorter); } else if (e.getSource() == fixedTable.getRowSorter()) { scrollableTable.setRowSorter(rowSorter); } }
@Override public void sorterChanged(RowSorterEvent e) { if (gridContainer != null) { gridContainer.try2CancelAnyEditing(); } super.sorterChanged(e); }
protected void fireSortOrderChanged() { RowSorterEvent event = new RowSorterEvent(this); RowSorterListener[] listenerArray = (RowSorterListener[]) listeners.toArray(); for (int i=0; i<listenerArray.length; i++) { listenerArray[i].sorterChanged(event); } }
protected void fireRowSorterChanged(int[] lastRowIndexToModel) { RowSorterEvent event = new RowSorterEvent(this, RowSorterEvent.Type.SORTED, lastRowIndexToModel); RowSorterListener[] listenerArray = (RowSorterListener[]) listeners.toArray(); for (int i=0; i<listenerArray.length; i++) { listenerArray[i].sorterChanged(event); } }
@Override public void sorterChanged(RowSorterEvent e) { if (e.getSource() instanceof AnnotatingRowSorter) { AnnotatingRowSorter<?, ?> sorter = (org.andork.swing.AnnotatingRowSorter<?, ?>) e.getSource(); if (sorter.isSortingInBackground()) { busySorters.add(sorter); } else { busySorters.remove(sorter); } target.setCursor(busySorters.isEmpty() ? null : Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } }
@Override public void sorterChanged(RowSorterEvent e) { ignoreViewSelectionChanges = true; try { super.sorterChanged(e); } finally { ignoreViewSelectionChanges = false; } updateViewSelectionModel(e); }
@Override public void sorterChanged(RowSorterEvent e) { if (inputTable.isEditing()) { inputTable.getCellEditor().stopCellEditing(); } applyValues(); }
/** * Handle sort changes in model sorter. * Query PageableDataSource for new page with the sort changes * @see javax.swing.event.RowSorterListener#sorterChanged(javax.swing.event.RowSorterEvent) */ public void sorterChanged(RowSorterEvent e) { if (sorter.getSortKeys().size() > 0 && tableModel.isPropertyColumn(sorter.getSortKeys().get(0).getColumn())) { // set first page configurePage(); page.firstPage(); } }
@Override public void sorterChanged(RowSorterEvent rse) { tableDataChanged(); }
public void sorterChanged(RowSorterEvent e) { AndroidClassUtil.callEmptyMethod(); }
protected void fireSortOrderChanged() { fireRowSorterChanged(new RowSorterEvent(this)); }
protected void fireRowSorterChanged(int[] lastRowIndexToModel) { fireRowSorterChanged(new RowSorterEvent(this, RowSorterEvent.Type.SORTED, lastRowIndexToModel)); }
/** * Overridden to hack around core bug * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6791934 * */ @Override public void sorterChanged(RowSorterEvent e) { super.sorterChanged(e); postprocessSorterChanged(e); }
private void cacheModelSelection(RowSorterEvent sortEvent) { lastModelSelection = convertSelectionToModel(sortEvent); modelLeadIndex = convertRowIndexToModel(sortEvent, getViewSelectionModel().getLeadSelectionIndex()); }
@Override public void sorterChanged(RowSorterEvent e) { super.sorterChanged(e); maybeRepaintOnSorterChanged(e); }
private void createTablePanel(JPanel tablePanel) { tablePanel.setLayout(new GridBagLayout()); keyTable = new JTable(keyDefTableModel); JScrollPane scrollPane = new JScrollPane(keyTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); enableSorting(keyTable); keyTable.getTableHeader().setReorderingAllowed(false); keyTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); keyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); keyTable.getColumnModel().getColumn(0).setPreferredWidth(25); keyTable.getColumnModel().getColumn(0).setMaxWidth(30); keyTable.getColumnModel().getColumn(0).setResizable(false); keyTable.getColumnModel().getColumn(1).setPreferredWidth(150); keyTable.getColumnModel().getColumn(2).setPreferredWidth(150); keyTable.getColumnModel().getColumn(3).setPreferredWidth(150); keyTable.getColumnModel().getColumn(4).setPreferredWidth(150); GridBagConstraints localConstr = new GridBagConstraints(); localConstr.insets = new Insets(2, 2, 2, 2); localConstr.anchor = GridBagConstraints.WEST; localConstr.fill = GridBagConstraints.BOTH; localConstr.gridx = 0; localConstr.gridy = 0; localConstr.weightx = 1; localConstr.weighty = 1; DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(JLabel.CENTER); keyTable.getColumnModel().getColumn(0).setCellRenderer(centerRenderer); tablePanel.add(scrollPane, localConstr); sorter = new TableRowSorter<>(keyDefTableModel); sorter.toggleSortOrder(0); sorter.toggleSortOrder(0); // initial sorting be priority descending sorter.addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged (RowSorterEvent e) { if (e.getType () == RowSorterEvent.Type.SORTED) { int selection = keyTable.getSelectedRow(); if (selection >= 0) { boxAction = false; reloadBoxItems(); updateComboBoxes(); boxAction = true; keyTable.setRowSelectionInterval(selection, selection); Rectangle selectRect = keyTable.getCellRect(selection, 0, true); selectRect.height = (keyTable.getParent().getHeight() / 2); keyTable.scrollRectToVisible(selectRect); } else { if (keyTable.getRowCount() > 0) { keyTable.changeSelection(0, 0, false, false); boxAction = false; reloadBoxItems(); updateComboBoxes(); boxAction = true; } } } } }); keyTable.setRowSorter(sorter); }
@Override public void sorterChanged( RowSorterEvent e ) { if ( getTableHeader() != null && getTableHeader().getUI() != null ) getTableHeader().getUI().clearCellImagesCache(); super.sorterChanged( e ); }
public void sorterChanged(RowSorterEvent e) { header.repaint(); }
@Override public void sorterChanged(RowSorterEvent e) { fireRowSorterChanged(null); }
@Override public void sorterChanged(RowSorterEvent e) { fireContentsChanged(0, table.getRowCount()); }
protected void updateViewSelectionModel(RowSorterEvent e) { if (e.getType() == Type.SORTED) { rebuildViewSelectionModel(); } }