@Test public void testMoveColumn() { final TableColumn nameColumn = createColumn("name"); EventList<TableColumn> columns = new BasicEventList<>(); columns.add(nameColumn); columns.add(createColumn("age")); DefaultTableColumnModel defaultModel = watcher.createDefaultModel(columns); EventTableColumnModel eventModel1 = watcher.createEventModel(columns); EventTableColumnModel eventModel2 = watcher.createEventModel(GlazedLists.eventList(columns)); assertModelEquals(eventModel1, defaultModel); assertModelEquals(eventModel2, defaultModel); assertModelEquals(eventModel1, eventModel2); assertEquals(3, nameColumn.getPropertyChangeListeners().length); columns.remove(0); columns.add(nameColumn); defaultModel.removeColumn(nameColumn); defaultModel.addColumn(nameColumn); eventModel2.moveColumn(0, 1); assertModelEquals(eventModel1, defaultModel); assertModelEquals(eventModel2, defaultModel); assertModelEquals(eventModel1, eventModel2); assertEquals(3, nameColumn.getPropertyChangeListeners().length); columns.set(0, columns.get(0)); defaultModel.moveColumn(0, 0); eventModel2.moveColumn(0, 0); watcher.assertFiredEventsAgreeAndClear(); }
@Override public void moveColumn(int columnIndex, int newIndex) { if (columnIndex < 0 || columnIndex >= getColumnCount()) throw new IllegalArgumentException("columnIndex out of range"); if (newIndex < 0 || newIndex >= getColumnCount()) throw new IllegalArgumentException("newIndex out of range"); if (columnIndex == newIndex) { fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex)); return; } swingThreadSource.getReadWriteLock().writeLock().lock(); try { final boolean selected = selectionModel.isSelectedIndex(columnIndex); swingThreadSource.add(newIndex, swingThreadSource.remove(columnIndex)); if (selected) selectionModel.addSelectionInterval(newIndex, newIndex); } finally { swingThreadSource.getReadWriteLock().writeLock().unlock(); } }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public void moveColumn(int columnIndex, int newIndex) { if (columnIndex < 0 || columnIndex >= getColumnCount()) throw new IllegalArgumentException("columnIndex out of range"); if (newIndex < 0 || newIndex >= getColumnCount()) throw new IllegalArgumentException("newIndex out of range"); if (columnIndex == newIndex) { fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex)); return; } swingThreadSource.getReadWriteLock().writeLock().lock(); try { final boolean selected = selectionModel.isSelectedIndex(columnIndex); swingThreadSource.add(newIndex, swingThreadSource.remove(columnIndex)); if (selected) selectionModel.addSelectionInterval(newIndex, newIndex); } finally { swingThreadSource.getReadWriteLock().writeLock().unlock(); } } }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public void moveColumn(int columnIndex, int newIndex) { if (columnIndex < 0 || columnIndex >= getColumnCount()) throw new IllegalArgumentException("columnIndex out of range"); if (newIndex < 0 || newIndex >= getColumnCount()) throw new IllegalArgumentException("newIndex out of range"); if (columnIndex == newIndex) { fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex)); return; } swingThreadSource.getReadWriteLock().writeLock().lock(); try { final boolean selected = selectionModel.isSelectedIndex(columnIndex); swingThreadSource.add(newIndex, swingThreadSource.remove(columnIndex)); if (selected) selectionModel.addSelectionInterval(newIndex, newIndex); } finally { swingThreadSource.getReadWriteLock().writeLock().unlock(); } } EventTableColumnModel(EventList<T> source); }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public void moveColumn(int columnIndex, int newIndex) { if (columnIndex < 0 || columnIndex >= getColumnCount()) throw new IllegalArgumentException("columnIndex out of range"); if (newIndex < 0 || newIndex >= getColumnCount()) throw new IllegalArgumentException("newIndex out of range"); if (columnIndex == newIndex) { fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex)); return; } swingThreadSource.getReadWriteLock().writeLock().lock(); try { final boolean selected = selectionModel.isSelectedIndex(columnIndex); swingThreadSource.add(newIndex, swingThreadSource.remove(columnIndex)); if (selected) selectionModel.addSelectionInterval(newIndex, newIndex); } finally { swingThreadSource.getReadWriteLock().writeLock().unlock(); } } EventTableColumnModel(EventList<T> source); @Override void addColumn(TableColumn column); @Override void removeColumn(TableColumn column); @Override void moveColumn(int columnIndex, int newIndex); @Override void setColumnMargin(int newMargin); @Override int getColumnMargin(); @Override int getColumnCount(); @Override Enumeration<TableColumn> getColumns(); @Override int getColumnIndex(Object identifier); @Override TableColumn getColumn(int columnIndex); @Override int getColumnIndexAtX(int x); @Override int getTotalColumnWidth(); @Override void setColumnSelectionAllowed(boolean flag); @Override boolean getColumnSelectionAllowed(); @Override int[] getSelectedColumns(); @Override int getSelectedColumnCount(); @Override void setSelectionModel(ListSelectionModel newModel); @Override ListSelectionModel getSelectionModel(); @Override void addColumnModelListener(TableColumnModelListener listener); @Override void removeColumnModelListener(TableColumnModelListener listener); @Override void propertyChange(PropertyChangeEvent evt); @Override void valueChanged(ListSelectionEvent e); @Override void listChanged(ListEvent<T> listChanges); void dispose(); }
EventTableColumnModel implements TableColumnModel, PropertyChangeListener, ListSelectionListener, ListEventListener<T> { @Override public void moveColumn(int columnIndex, int newIndex) { if (columnIndex < 0 || columnIndex >= getColumnCount()) throw new IllegalArgumentException("columnIndex out of range"); if (newIndex < 0 || newIndex >= getColumnCount()) throw new IllegalArgumentException("newIndex out of range"); if (columnIndex == newIndex) { fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex)); return; } swingThreadSource.getReadWriteLock().writeLock().lock(); try { final boolean selected = selectionModel.isSelectedIndex(columnIndex); swingThreadSource.add(newIndex, swingThreadSource.remove(columnIndex)); if (selected) selectionModel.addSelectionInterval(newIndex, newIndex); } finally { swingThreadSource.getReadWriteLock().writeLock().unlock(); } } EventTableColumnModel(EventList<T> source); @Override void addColumn(TableColumn column); @Override void removeColumn(TableColumn column); @Override void moveColumn(int columnIndex, int newIndex); @Override void setColumnMargin(int newMargin); @Override int getColumnMargin(); @Override int getColumnCount(); @Override Enumeration<TableColumn> getColumns(); @Override int getColumnIndex(Object identifier); @Override TableColumn getColumn(int columnIndex); @Override int getColumnIndexAtX(int x); @Override int getTotalColumnWidth(); @Override void setColumnSelectionAllowed(boolean flag); @Override boolean getColumnSelectionAllowed(); @Override int[] getSelectedColumns(); @Override int getSelectedColumnCount(); @Override void setSelectionModel(ListSelectionModel newModel); @Override ListSelectionModel getSelectionModel(); @Override void addColumnModelListener(TableColumnModelListener listener); @Override void removeColumnModelListener(TableColumnModelListener listener); @Override void propertyChange(PropertyChangeEvent evt); @Override void valueChanged(ListSelectionEvent e); @Override void listChanged(ListEvent<T> listChanges); void dispose();  }