Class SJTable

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.grid.Grid<Integer>
com.vaadin.swingbridge.surrogates.SJTable
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.grid.Grid<Integer>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.grid.Grid<Integer>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.grid.Grid<Integer>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.data.event.SortEvent.SortNotifier<com.vaadin.flow.component.grid.Grid<Integer>, com.vaadin.flow.component.grid.GridSortOrder<Integer>>, com.vaadin.flow.data.provider.HasDataGenerators<Integer>, com.vaadin.flow.data.provider.HasDataView<Integer, Void, com.vaadin.flow.component.grid.dataview.GridDataView<Integer>>, com.vaadin.flow.data.provider.HasLazyDataView<Integer, Void, com.vaadin.flow.component.grid.dataview.GridLazyDataView<Integer>>, com.vaadin.flow.data.provider.HasListDataView<Integer, com.vaadin.flow.component.grid.dataview.GridListDataView<Integer>>, ComponentMixin, ContainerMixin, JComponentMixin, Serializable, EventListener, ListSelectionListener, TableColumnModelListener, TableModelListener

public class SJTable extends com.vaadin.flow.component.grid.Grid<Integer> implements JComponentMixin, TableModelListener, TableColumnModelListener, ListSelectionListener
Surrogate for JTable (SD_sjtable). Extends Vaadin Grid<Integer> — row indices are the Grid's items, which keeps the installed TableModel as the single source of truth (R_swing_is_truth) and lets setValueAt updates reflect on next render without snapshot rebuilds.

Vaadin-first rendering (R_vaadin_first)

Surrogate-layer code uses Vaadin's Renderer surface for column rendering — install via setRenderer(int, Renderer). The JDK TableCellRenderer surface (return type java.awt.Component clashes with our hierarchy per D_event_port_policy) lives only on the emulator layer (:emulators.JTable); the emulator translates its ported vaadinx.swing.table.TableCellRenderer registry into Vaadin renderers and installs via setRenderer(int, Renderer). Pure-surrogate users without setRenderer(int, Renderer) get a default value.toString() Span renderer for every column — matches the SJComboBox precedent (default setItemLabelGenerator with String.valueOf).

Row-index identity

Each Vaadin row carries the boxed Integer index into the model. Per-cell renderer reads model.getValueAt(row, modelCol) live, so fireTableRowsUpdated just calls dataProvider.refreshItem(row) — no array-snapshot resync. The ListSelectionModel is index-based already, so the bridge to Vaadin Grid's selection (which carries the same Integer keys) is direct.

Listener-list architecture

SJTable IS-A TableModelListener / TableColumnModelListener / ListSelectionListener — JDK JTable's pattern. The surrogate subscribes itself to the installed model, column model, and selection model on install/swap; user code subscribes directly to those models (no surrogate-level convenience listener registration). The internal subscriptions handle (a) column rebuild on structure change, (b) Grid data refresh on row change, (c) Grid selection push on selection-model change. Vaadin → us flows via a addSelectionListener subscription wrapped in SHelper.callSwing(Runnable) (R_callswing_envelope) and writes through to ListSelectionModel, closing the loop.

R_vaadin_first drop-and-WARN surface

Cell-editor surface (R_match_swing_errors sub-bucket (b)), TableRowSorter / RowFilter (deferred), dragEnabled / dropMode (cross-cutting DnD), column-cell selection (Vaadin Grid is row-only), intercellSpacing / gridColor / showHorizontalLines (Vaadin theme owns chrome), rowHeight on push (Vaadin auto- heights), printing (permanent sub-bucket (b)).
See Also:
  • Field Details

    • AUTO_RESIZE_OFF

      public static final int AUTO_RESIZE_OFF
      See Also:
    • AUTO_RESIZE_NEXT_COLUMN

      public static final int AUTO_RESIZE_NEXT_COLUMN
      See Also:
    • AUTO_RESIZE_SUBSEQUENT_COLUMNS

      public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS
      See Also:
    • AUTO_RESIZE_LAST_COLUMN

      public static final int AUTO_RESIZE_LAST_COLUMN
      See Also:
    • AUTO_RESIZE_ALL_COLUMNS

      public static final int AUTO_RESIZE_ALL_COLUMNS
      See Also:
  • Constructor Details

  • Method Details

    • createDefaultDataModel

      protected TableModel createDefaultDataModel()
    • createDefaultColumnModel

      protected TableColumnModel createDefaultColumnModel()
    • createDefaultSelectionModel

      protected ListSelectionModel createDefaultSelectionModel()
    • getModel

      public TableModel getModel()
    • setModel

      public void setModel(TableModel newModel)
    • getColumnModel

      public TableColumnModel getColumnModel()
    • setColumnModel

      public void setColumnModel(TableColumnModel newModel)
    • getListSelectionModel

      public ListSelectionModel getListSelectionModel()
      JDK getSelectionModel(): ListSelectionModel can't coexist with Vaadin Grid's same-named getSelectionModel(): GridSelectionModel<T> (different return types, can't override). Per R_vaadin_first the Vaadin shape wins at the surrogate layer; pure-surrogate code reads selection via setSelectionMode(int) / setRowSelectionInterval(int, int) / getSelectedRow() instead. The emulator layer (:emulators.JTable) keeps the JDK-shaped getter for stage-2 import-swap compatibility — and reaches the JDK model through getListSelectionModel() below.
    • getJdkSelectionMode

      public int getJdkSelectionMode()
      Accessor for the current JDK selection mode (one of ListSelectionModel.SINGLE_SELECTION / SINGLE_INTERVAL_SELECTION / MULTIPLE_INTERVAL_SELECTION). Distinct name from any Vaadin Grid getter (Vaadin Grid 25 has no public getSelectionMode(), but the differing name future-proofs). Used by the emulator layer to read the previous mode for PCE delivery on setSelectionMode(int) swaps.
    • setSelectionModel

      public void setSelectionModel(ListSelectionModel newModel)
    • getRowCount

      public int getRowCount()
    • getColumnCount

      public int getColumnCount()
    • getColumnName

      public String getColumnName(int column)
    • getColumnClass

      public Class<?> getColumnClass(int column)
    • getValueAt

      public Object getValueAt(int row, int column)
    • setValueAt

      public void setValueAt(Object aValue, int row, int column)
    • isCellEditable

      public boolean isCellEditable(int row, int column)
    • convertColumnIndexToView

      public int convertColumnIndexToView(int modelColumnIndex)
    • convertColumnIndexToModel

      public int convertColumnIndexToModel(int viewColumnIndex)
    • convertRowIndexToView

      public int convertRowIndexToView(int modelRowIndex)
      Routes through the installed RowSorter when present; identity otherwise.
    • convertRowIndexToModel

      public int convertRowIndexToModel(int viewRowIndex)
      Routes through the installed RowSorter when present; identity otherwise.
    • setRenderer

      public void setRenderer(int viewColumnIndex, com.vaadin.flow.data.renderer.Renderer<Integer> renderer)
      Vaadin-first cell renderer install per R_vaadin_first. Replaces the column at viewColumnIndex with one driven by the supplied Vaadin Renderer<Integer>. The header text and key are preserved across the swap. Migrated code at the surrogate stage uses this rather than the JDK TableCellRenderer surface (which lives only on the emulator layer per D_event_port_policy + R_vaadin_first).

      Throws IndexOutOfBoundsException when viewColumnIndex is out of range — matches Vaadin's column accessors.

      Swaps the renderer in place via Grid.Column.setRenderer(Renderer): the Grid.Column instance persists, so header / key / sortability / sort property / column order — and any setEditorComponent — are all preserved automatically, and the swap is churn-free (safe to call repeatedly, e.g. the emulator re-installs renderers on every setDefaultRenderer / per-column renderer change).

    • createDefaultColumnsFromModel

      public void createDefaultColumnsFromModel()
      Rebuild the TableColumnModel from the current TableModel's structure. Called when autoCreateColumnsFromModel is true and the model fires a HEADER_ROW TableModelEvent.
    • tableChanged

      public void tableChanged(TableModelEvent e)
      Applies a model change to the sorter, the selection and the Grid, in that order.

      The installed RowSorter hears the change first, because nothing else tells it: TableRowSorter does not listen to its model, it is the table's job to forward every event. Until told, it keeps answering getViewRowCount() and the index conversions from the rows it last saw, and count(Query) and fetch(Query) read through it. An owner that tells the sorter itself, and only then forwards the event here, says so through setSorterNotifiedByOwner(boolean).

      The selection needs no re-mapping across the change: it holds model rows (D_jtable_cell_editing), so a re-sort leaves it valid, and inserts and deletes shift it here in model coordinates.

      Hops onto the owner's UI thread, since a worker filling the model is the ordinary Swing pattern (SD_background_model_hop).

      Specified by:
      tableChanged in interface TableModelListener
    • setRefreshProtectedRow

      public void setRefreshProtectedRow(Integer modelRow)
      Protect (or, with null, un-protect) a model row from refreshItem on UPDATE events. The emulator's cell-editing lifecycle drives this so an external setValueAt can't re-render the row hosting an open editor (D_jtable_cell_editing Task 2). Machinery, not editing API.
    • isEditorClosingForDataChange

      public boolean isEditorClosingForDataChange()
      Whether an EditorCloseListener running now was fired because the Grid's data changed — Vaadin closes an open editor on every data change, refreshAll() included — rather than because the user left the cell. Machinery for the emulator, whose JDK contract keeps an edit open across a model change; not editing API.
    • onDataProviderChange

      protected void onDataProviderChange()
      Overrides:
      onDataProviderChange in class com.vaadin.flow.component.grid.Grid<Integer>
    • columnAdded

      public void columnAdded(TableColumnModelEvent e)
      Specified by:
      columnAdded in interface TableColumnModelListener
    • columnRemoved

      public void columnRemoved(TableColumnModelEvent e)
      Specified by:
      columnRemoved in interface TableColumnModelListener
    • columnMoved

      public void columnMoved(TableColumnModelEvent e)
      Specified by:
      columnMoved in interface TableColumnModelListener
    • columnMarginChanged

      public void columnMarginChanged(ChangeEvent e)
      Specified by:
      columnMarginChanged in interface TableColumnModelListener
    • columnSelectionChanged

      public void columnSelectionChanged(ListSelectionEvent e)
      Specified by:
      columnSelectionChanged in interface TableColumnModelListener
    • valueChanged

      public void valueChanged(ListSelectionEvent e)
      Specified by:
      valueChanged in interface ListSelectionListener
    • setRowSelectionInterval

      public void setRowSelectionInterval(int index0, int index1)
    • addRowSelectionInterval

      public void addRowSelectionInterval(int index0, int index1)
    • removeRowSelectionInterval

      public void removeRowSelectionInterval(int index0, int index1)
    • clearSelection

      public void clearSelection()
    • getSelectedRow

      public int getSelectedRow()
    • getSelectedRows

      public int[] getSelectedRows()
    • getSelectedRowCount

      public int getSelectedRowCount()
    • isRowSelected

      public boolean isRowSelected(int row)
    • selectAll

      public void selectAll()
    • setSelectionMode

      public void setSelectionMode(int selectionMode)
      JDK selection-mode setter. Validates per JDK contract (throws IAE on unrecognised mode), updates the underlying ListSelectionModel, and maps to Vaadin Grid's Grid.SelectionMode: SINGLE → SINGLE; the two interval modes both map to MULTI since Vaadin Grid has no single-interval analog. The ListSelectionModel still enforces the JDK contract; the divergence is browser-side ctrl-click extending past the interval — the model rejects the second selection so the UI reverts.
    • getRowSelectionAllowed

      public boolean getRowSelectionAllowed()
    • setRowSelectionAllowed

      public void setRowSelectionAllowed(boolean rowSelectionAllowed)
    • getColumnSelectionAllowed

      public boolean getColumnSelectionAllowed()
    • setColumnSelectionAllowed

      public void setColumnSelectionAllowed(boolean columnSelectionAllowed)
    • getCellSelectionEnabled

      public boolean getCellSelectionEnabled()
    • setCellSelectionEnabled

      public void setCellSelectionEnabled(boolean cellSelectionEnabled)
    • addColumn

      public void addColumn(TableColumn aColumn)
    • removeColumn

      public void removeColumn(TableColumn aColumn)
    • moveColumn

      public void moveColumn(int columnIndex, int newIndex)
    • getColumn

      public TableColumn getColumn(Object identifier)
    • getAutoCreateColumnsFromModel

      public boolean getAutoCreateColumnsFromModel()
    • setAutoCreateColumnsFromModel

      public void setAutoCreateColumnsFromModel(boolean autoCreate)
    • getAutoCreateRowSorter

      public boolean getAutoCreateRowSorter()
    • setSorterNotifiedByOwner

      public void setSorterNotifiedByOwner(boolean sorterNotifiedByOwner)
      Whether the code forwarding model events to tableChanged(TableModelEvent) has already told the installed RowSorter about each one, so this table does not tell it again. false by default: a table listening to its own model tells its sorter itself. An owner that tells the sorter on the thread the model fired on, as a JDK JTable does, and forwards the event afterwards, sets it.
    • setAutoCreateRowSorter

      public void setAutoCreateRowSorter(boolean autoCreateRowSorter)
    • getRowSorter

      public RowSorter<? extends TableModel> getRowSorter()
      Returns the currently installed JDK RowSorter, or null when no sort is active. Migrators read this to inspect getSortKeys() or to call toggleSortOrder(column) programmatically.
    • setRowSorter

      public void setRowSorter(RowSorter<? extends TableModel> newRowSorter)
      Install a JDK RowSorter on this table. null clears sort entirely (subsequent Vaadin Grid header clicks fall back to model order). Detaches our RowSorterListener from the old sorter and attaches a fresh one to the new — programmatic rowSorter.setSortKeys(...) calls are bridged back to Vaadin via the listener (which calls grid.sort(translated) so the Grid's sort indicator stays in sync).
    • getRowHeight

      public int getRowHeight()
    • setRowHeight

      public void setRowHeight(int rowHeight)
    • getRowHeight

      public int getRowHeight(int row)
    • setRowHeight

      public void setRowHeight(int row, int rowHeight)
    • getRowMargin

      public int getRowMargin()
    • setRowMargin

      public void setRowMargin(int rowMargin)
    • getIntercellSpacing

      public Dimension getIntercellSpacing()
    • setIntercellSpacing

      public void setIntercellSpacing(Dimension intercellSpacing)
    • getGridColor

      public Color getGridColor()
    • setGridColor

      public void setGridColor(Color gridColor)
    • getShowHorizontalLines

      public boolean getShowHorizontalLines()
    • setShowHorizontalLines

      public void setShowHorizontalLines(boolean showHorizontalLines)
    • getShowVerticalLines

      public boolean getShowVerticalLines()
    • setShowVerticalLines

      public void setShowVerticalLines(boolean showVerticalLines)
    • getShowGrid

      public boolean getShowGrid()
    • setShowGrid

      public void setShowGrid(boolean showGrid)
    • getAutoResizeMode

      public int getAutoResizeMode()
    • setAutoResizeMode

      public void setAutoResizeMode(int mode)
    • getSelectionForeground

      public Color getSelectionForeground()
    • setSelectionForeground

      public void setSelectionForeground(Color selectionForeground)
    • getSelectionBackground

      public Color getSelectionBackground()
    • setSelectionBackground

      public void setSelectionBackground(Color selectionBackground)
    • getCellRect

      public Rectangle getCellRect(int row, int column, boolean includeSpacing)
    • getDragEnabled

      public boolean getDragEnabled()
    • setDragEnabled

      public void setDragEnabled(boolean dragEnabled)
    • getFillsViewportHeight

      public boolean getFillsViewportHeight()
    • setFillsViewportHeight

      public void setFillsViewportHeight(boolean fillsViewportHeight)
    • getPreferredScrollableViewportSize

      public Dimension getPreferredScrollableViewportSize()
    • setPreferredScrollableViewportSize

      public void setPreferredScrollableViewportSize(Dimension size)
    • editCellAt

      public void editCellAt(int row, int column)
    • editCellAt

      public boolean editCellAt(int row, int column, EventObject e)
    • isEditing

      public boolean isEditing()
    • getEditingRow

      public int getEditingRow()
    • getEditingColumn

      public int getEditingColumn()
    • getEditorComponent

      public com.vaadin.flow.component.Component getEditorComponent()
    • removeEditor

      public void removeEditor()
    • addMouseListener

      public void addMouseListener(SMouseListener l)
      Overrides the inherited ComponentMixin wire — Grid dispatches item clicks carrying the row item + clicked column, not generic component clicks. Each SMouseListener gets two Grid subscriptions combined into one Registration: addItemClickListener fires SMouseEvent.MOUSE_CLICKED with the browser click count, addItemDoubleClickListener fires it with clickCount == 2 — the double-click-to-edit/open idiom. The clicked row (the Grid item, consistent with getSelectedRow() / getValueAt(int, int)) and the view-column index are stashed around the fan-out so rowAtPoint(Point) / columnAtPoint(Point) resolve during the user's mouseClicked handler (R_layouts_close_enough — no pixel→cell map). Mirrors SJList (SD_sjlist); columnAtPoint is the bonus Grid's item-click column affords that SJList didn't need.
      Specified by:
      addMouseListener in interface ComponentMixin
    • rowAtPoint

      public int rowAtPoint(Point point)
      Row index of the cell currently being click-dispatched (stashed by addMouseListener(SMouseListener)'s item-click wire), or -1 outside a dispatch. Consistent with getSelectedRow() / getValueAt(int, int) — there is no server-side pixel→row map (R_layouts_close_enough). Graduates from the pre-(b) drop-and-WARN.
    • columnAtPoint

      public int columnAtPoint(Point point)
      View-column index of the cell currently being click-dispatched, or -1 (outside a dispatch, or a row-only click that carries no column). Resolved from the Grid's clicked column (R_layouts_close_enough).
    • getUIClassID

      public String getUIClassID()
      Description copied from interface: JComponentMixin
      Deliberate no-op — L&F key.
      Specified by:
      getUIClassID in interface JComponentMixin