Search in sources :

Example 11 with TableModelEvent

use of javax.swing.event.TableModelEvent in project jmeter by apache.

the class PowerTableModel method moveRow.

@Override
public void moveRow(int start, int end, int to) {
    ArrayList<Object[]> rows = new ArrayList<>();
    for (int i = 0; i < getRowCount(); i++) {
        rows.add(getRowData(i));
    }
    List<Object[]> subList = new ArrayList<>(rows.subList(start, end));
    for (int x = end - 1; x >= start; x--) {
        rows.remove(x);
    }
    rows.addAll(to, subList);
    for (int i = 0; i < rows.size(); i++) {
        setRowValues(i, rows.get(i));
    }
    super.fireTableChanged(new TableModelEvent(this));
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) ArrayList(java.util.ArrayList)

Example 12 with TableModelEvent

use of javax.swing.event.TableModelEvent in project jmeter by apache.

the class TableModelEventBacker method assertEvents.

/**
     * Checks each event assertion against each backed event in order. Event storage is cleared after it.
     * @param assertions a collection if {@link EventAssertion}s to check
     */
public void assertEvents(EventAssertion... assertions) {
    try {
        assertEquals("event count", assertions.length, events.size());
        int i = 0;
        for (TableModelEvent event : events) {
            assertions[i].assertEvent(event, i++);
        }
    } finally {
        events.clear();
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent)

Example 13 with TableModelEvent

use of javax.swing.event.TableModelEvent in project intellij-community by JetBrains.

the class JavaChangeSignatureDialog method customizeParametersTable.

@Override
protected void customizeParametersTable(TableView<ParameterTableModelItemBase<ParameterInfoImpl>> table) {
    final JTable t = table.getComponent();
    final TableColumn defaultValue = t.getColumnModel().getColumn(2);
    final TableColumn varArg = t.getColumnModel().getColumn(3);
    t.removeColumn(defaultValue);
    t.removeColumn(varArg);
    t.getModel().addTableModelListener(new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.INSERT) {
                t.getModel().removeTableModelListener(this);
                final TableColumnAnimator animator = new TableColumnAnimator(t);
                animator.setStep(48);
                animator.addColumn(defaultValue, (t.getWidth() - 48) / 3);
                animator.addColumn(varArg, 48);
                animator.startAndDoWhenDone(() -> t.editCellAt(t.getRowCount() - 1, 0));
                animator.start();
            }
        }
    });
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) TableColumn(javax.swing.table.TableColumn)

Example 14 with TableModelEvent

use of javax.swing.event.TableModelEvent in project intellij-community by JetBrains.

the class ChangeClassSignatureDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    myTable = new JBTable(myTableModel);
    myTable.setStriped(true);
    TableColumn nameColumn = myTable.getColumnModel().getColumn(NAME_COLUMN);
    TableColumn boundColumn = myTable.getColumnModel().getColumn(BOUND_VALUE_COLUMN);
    TableColumn valueColumn = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
    Project project = myClass.getProject();
    nameColumn.setCellRenderer(new MyCellRenderer());
    nameColumn.setCellEditor(new StringTableCellEditor(project));
    boundColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
    boundColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
    valueColumn.setCellRenderer(new MyCodeFragmentTableCellRenderer());
    valueColumn.setCellEditor(new JavaCodeFragmentTableCellEditor(project));
    myTable.setPreferredScrollableViewportSize(new Dimension(210, myTable.getRowHeight() * 4));
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.getSelectionModel().setSelectionInterval(0, 0);
    myTable.setSurrendersFocusOnKeystroke(true);
    myTable.setCellSelectionEnabled(true);
    myTable.setFocusCycleRoot(true);
    if (myHideDefaultValueColumn) {
        final TableColumn defaultValue = myTable.getColumnModel().getColumn(DEFAULT_VALUE_COLUMN);
        myTable.removeColumn(defaultValue);
        myTable.getModel().addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                if (e.getType() == TableModelEvent.INSERT) {
                    myTable.getModel().removeTableModelListener(this);
                    final TableColumnAnimator animator = new TableColumnAnimator(myTable);
                    animator.setStep(20);
                    animator.addColumn(defaultValue, myTable.getWidth() / 2);
                    animator.startAndDoWhenDone(() -> myTable.editCellAt(myTable.getRowCount() - 1, 0));
                    animator.start();
                }
            }
        });
    }
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(SeparatorFactory.createSeparator(RefactoringBundle.message("changeClassSignature.parameters.panel.border.title"), myTable), BorderLayout.NORTH);
    panel.add(ToolbarDecorator.createDecorator(myTable).createPanel(), BorderLayout.CENTER);
    return panel;
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) JBTable(com.intellij.ui.table.JBTable) TableColumn(javax.swing.table.TableColumn) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Project(com.intellij.openapi.project.Project) TableModelListener(javax.swing.event.TableModelListener) StringTableCellEditor(com.intellij.refactoring.ui.StringTableCellEditor)

Example 15 with TableModelEvent

use of javax.swing.event.TableModelEvent in project jdk8u_jdk by JetBrains.

the class TableSorter method sortByColumn.

public void sortByColumn(int column, boolean ascending) {
    this.ascending = ascending;
    sortingColumns.clear();
    sortingColumns.add(column);
    sort(this);
    super.tableChanged(new TableModelEvent(this));
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent)

Aggregations

TableModelEvent (javax.swing.event.TableModelEvent)35 TableModelListener (javax.swing.event.TableModelListener)15 DefaultTableModel (javax.swing.table.DefaultTableModel)6 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 ArrayList (java.util.ArrayList)4 JScrollPane (javax.swing.JScrollPane)4 TableColumn (javax.swing.table.TableColumn)4 JBTable (com.intellij.ui.table.JBTable)3 Dimension (java.awt.Dimension)3 GridBagConstraints (java.awt.GridBagConstraints)3 Insets (java.awt.Insets)3 JButton (javax.swing.JButton)3 JTable (javax.swing.JTable)3 ListSelectionEvent (javax.swing.event.ListSelectionEvent)3 ListSelectionListener (javax.swing.event.ListSelectionListener)3 GridBagLayout (java.awt.GridBagLayout)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 JComboBox (javax.swing.JComboBox)2 JPanel (javax.swing.JPanel)2