- java.lang.Object
-
- com.iamsoft.util.ui.javafx.table.TableViewUtil
-
public final class TableViewUtil extends Object
Miscellaneous utility methods related to TableView.- See Also:
TableView
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addCtrlShiftSelectionRangeMode(javafx.scene.control.TableView<?> pTableView)
Support Ctrl-Shift selection.static <T> void
addItemsListener(javafx.scene.control.TableView<T> pTable, javafx.beans.value.ChangeListener<? super javafx.collections.ObservableList<T>> pListener)
Using a change listener for TableView.itemsProperty() may result in an unexpected behavior, because when the value of items property is replaced and both old and new lists are empty or have equal elements and size, they will be considered as equal and change event will not be fired.static <T> void
bindColumns(javafx.scene.control.TableView<T> pDestTableView, javafx.scene.control.TableView<T> pSrcTableView)
static <S> void
checkPositions(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pFromPos, javafx.scene.control.TablePosition<S,?> pToPos)
static int
compare(javafx.scene.control.TablePositionBase<?> pPos1, javafx.scene.control.TablePositionBase<?> pPos2)
static Object
configureColumnReordering(javafx.scene.control.TableView<?> pTable, javafx.scene.control.TableView<?> pReorderingTable)
Keep reordering line and reordering region in sync when the user is reordering columns.static List<org.controlsfx.control.action.Action>
configureCopyAccelerators(javafx.scene.control.TableView<?> pTableView)
Configure Ctrl-C and Ctrl-Shift-C keyboard shortcuts.static List<org.controlsfx.control.action.Action>
configureCopyAccelerators(javafx.scene.control.TableView<?> pTableView, Consumer<javafx.event.ActionEvent> pCopySelectedRowHandler)
Configure Ctrl-C and Ctrl-Shift-C keyboard shortcuts.static void
copyFocusedCell(javafx.scene.control.TableView<?> pTableView)
Copy selected cell to clipboard.static void
copySelectedRows(javafx.scene.control.TableView<?> pTableView)
Copy selected table rows to clipboard.static void
copySelection(javafx.scene.control.TableView<?> pTableView)
static void
copySelection(javafx.stage.Window pParent, javafx.scene.control.TableView<?> pTableView, BiFunction<Integer,Integer,Object> pCellTextProvider)
static <R> void
copySelection(javafx.stage.Window pParent, javafx.scene.control.TableView<?> pTableView, List<Map.Entry<R,Integer>> pCellInfoList, List<R> pRowInfoList, BiFunction<R,Integer,Object> pCellTextProvider)
static <S,T>
javafx.scene.control.cell.ComboBoxTableCell<S,T>createComboBoxTableCell(javafx.scene.control.TableView<S> pTable, javafx.util.StringConverter<T> pConverter, javafx.collections.ObservableList<T> pItems)
Use this method as a workaround for the following bugs: Clicking outside of the edited cell, node, or entry should commit the value [TableCell] commit on focus lost not possible in every case .static javafx.beans.property.ReadOnlyProperty<Double>
createHeaderHeightProperty(javafx.scene.control.TableView<?> pTable)
Creates a read-only property providing the height of the header of the specified table.static javafx.beans.value.ObservableValue<javafx.scene.control.skin.TableHeaderRow>
createHeaderRowProperty(javafx.scene.control.TableView<?> pTable)
Creates a read-only property providing the header row of the specified table.static <S> javafx.beans.property.ReadOnlyProperty<Double>
createMaxRowHeightProperty(javafx.scene.control.TableView<S> pTable)
Creates a read-only property providing the height of the 'tallest' row in the table.static <N extends javafx.scene.Node>
javafx.beans.property.ReadOnlyProperty<N>createNodeProperty(javafx.scene.control.Control pParent, String pCssSelector)
static <S,T>
javafx.scene.control.cell.TextFieldTableCell<S,T>createTextFieldTableCell(javafx.scene.control.TableView<S> pTable, javafx.util.StringConverter<T> pConverter)
Use this method as a workaround for the following bugs: Clicking outside of the edited cell, node, or entry should commit the value [TableCell] commit on focus lost not possible in every case .static void
embedContent(javafx.collections.ObservableList<? extends javafx.scene.control.TableColumn<?,?>> pColumns, javafx.scene.control.TableView<?> pTable)
Display table contents of the specified table within TableColumn2 headers.static void
ensureRowIsVisible(javafx.scene.control.TableView<?> pTable, int pRow)
static String
focusedCellToString(javafx.scene.control.TableView<?> pTableView)
static <S> javafx.scene.control.TableCell<S,?>
getCellByScenePosition(javafx.scene.control.TableView<S> pTable, double pSceneX, double pSceneY)
static <S> javafx.scene.control.TablePosition<S,?>
getCellPositionByScenePosition(javafx.scene.control.TableView<S> pTable, double pSceneX, double pSceneY)
static Map.Entry<Integer,Integer>
getColumnIndexPair(javafx.scene.control.TableView<?> pTableView, int pColumnIdx)
If the table contains nested columns, the returned entry's key contains the corresponding table column index and the entry's value the corresponding nested column index or-1
if the column dosn't have nested columns.static <S> javafx.scene.control.TablePosition<S,?>
getFirstCellPos(javafx.scene.control.TableView<S> pTable)
Returns the first cell or row position, depending on whether cell selection is enabled, ornull
if the table is empty or has no columns.static <S> javafx.scene.control.TablePosition<S,?>
getLastCellPos(javafx.scene.control.TableView<S> pTable)
Returns the last cell or row position, depending on whether cell selection is enabled, ornull
if the table is empty or has no columns.static <T> javafx.collections.ObservableList<T>
getSelectedItems(javafx.scene.control.TableView<T> pTable)
static javafx.scene.control.skin.TableHeaderRow
getTableHeaderRow(javafx.scene.control.TableView<?> pTable)
static javafx.scene.control.skin.TableViewSkinBase
getTableSkin(javafx.scene.control.TableView<?> pTable)
static void
hideHeader(javafx.scene.control.TableView<?> pTableView)
static void
hideHorizontalScrollBar(javafx.scene.control.TableView<?> pTableView)
static void
hideRegion(javafx.beans.value.ObservableValue<? extends javafx.scene.layout.Region> pRegion)
static void
hideRegion(javafx.scene.layout.Region pRegion)
static <T> void
linkSort(javafx.scene.control.TableView<?> pSrcTable, javafx.scene.control.TableView<T> pTargetTable)
static <S> javafx.scene.control.TablePosition<S,?>
nextPosition(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pPos)
Returns the position of the next cell ornull
if there is no next cell.static <S> Stream<javafx.scene.control.TablePosition<S,?>>
positionStream(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pFromPos, javafx.scene.control.TablePosition<S,?> pToPos)
Returns a stream of positions frompFromPos
(inclusive) topToPos
(inclusive).static javafx.beans.property.ReadOnlyBooleanProperty
preserveTableSelection(javafx.scene.control.TableView<?> pTable)
Use this method to preserve the table selection on item updates whenObservableSortedList
orSimpleLazyObservableList
is used as item list in the table.static <S> javafx.scene.control.TablePosition<S,?>
prevPosition(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pPos)
Returns the position of the previous cell ornull
if there is no previous cell or if the specified position isnull
.static <T> String[]
rowToStrings(javafx.scene.control.TableView<?> pTableView, T pRowInfo, BiFunction<T,Integer,Object> pCellTextProvider)
static String
selectedCellsToString(javafx.scene.control.TableView<?> pTableView, BiFunction<Integer,Integer,Object> pCellTextProvider)
static String
selectedRowsToString(javafx.scene.control.TableView<?> pTableView)
Export selected table rows to String.static void
selectIndices(javafx.scene.control.TableView<?> pTable, List<Integer> pIndices)
Efficient way to select indices.static String
selectionToString(javafx.scene.control.TableView<?> pTableView)
static String
selectionToString(javafx.scene.control.TableView<?> pTableView, BiFunction<Integer,Integer,Object> pCellTextProvider)
static <T> void
selectPosition(javafx.scene.control.TableView<T> pTable, javafx.scene.control.TablePosition<T,?> pPos)
Selects the specified cell/row and ensures that it's visible.static void
selectRow(javafx.scene.control.TableView<?> pTable, int pRow)
Selects the specified row and ensures that it's visible.static void
setEmptyPlaceholder(javafx.scene.control.TableView<?> pTable)
void
syncAllColWidths(javafx.collections.ObservableList<javafx.collections.ObservableList<javafx.scene.control.TableColumn<?,?>>> pColLists)
Keep column widths in sync for a list of column lists.static <I,O>
Collection<Object>syncColumnArrangement(javafx.collections.ObservableList<javafx.scene.control.TableColumn<I,?>> pSrcColumns, Function<javafx.scene.control.TableColumn<I,?>,javafx.scene.control.TableColumn<O,?>> pFunction, javafx.scene.control.TableView<O> pDestTableView)
Synchronize ordering and width of columns.static Object
syncHorizontalScroll(javafx.collections.ObservableList<? extends javafx.scene.control.TableView<?>> pTables)
static <T> void
syncSort(javafx.scene.control.TableView<?> pSrcTable, javafx.scene.control.TableView<T> pTargetTable)
static void
updateFocusedCellOnRightClick(javafx.scene.control.TableView<?> pTable)
-
-
-
Method Detail
-
selectedRowsToString
public static String selectedRowsToString(javafx.scene.control.TableView<?> pTableView)
Export selected table rows to String. If necessary, this method could be adjusted to facilitate copying selected cells, the entire table, etc. Returns null if selection is empty. TODO: consider using CSV util to handle escapes, etc.
-
rowToStrings
public static <T> String[] rowToStrings(javafx.scene.control.TableView<?> pTableView, T pRowInfo, BiFunction<T,Integer,Object> pCellTextProvider)
-
selectionToString
public static String selectionToString(javafx.scene.control.TableView<?> pTableView) throws InterruptedException
- Throws:
InterruptedException
-
selectionToString
public static String selectionToString(javafx.scene.control.TableView<?> pTableView, BiFunction<Integer,Integer,Object> pCellTextProvider) throws InterruptedException
- Throws:
InterruptedException
-
selectedCellsToString
public static String selectedCellsToString(javafx.scene.control.TableView<?> pTableView, BiFunction<Integer,Integer,Object> pCellTextProvider) throws InterruptedException
- Throws:
InterruptedException
-
copySelectedRows
public static void copySelectedRows(javafx.scene.control.TableView<?> pTableView)
Copy selected table rows to clipboard.- See Also:
selectedRowsToString(TableView)
-
copySelection
public static void copySelection(javafx.scene.control.TableView<?> pTableView)
-
copySelection
public static void copySelection(javafx.stage.Window pParent, javafx.scene.control.TableView<?> pTableView, BiFunction<Integer,Integer,Object> pCellTextProvider)
-
copySelection
public static <R> void copySelection(javafx.stage.Window pParent, javafx.scene.control.TableView<?> pTableView, List<Map.Entry<R,Integer>> pCellInfoList, List<R> pRowInfoList, BiFunction<R,Integer,Object> pCellTextProvider)
- Type Parameters:
R
- Row info.
-
configureCopyAccelerators
public static List<org.controlsfx.control.action.Action> configureCopyAccelerators(javafx.scene.control.TableView<?> pTableView)
Configure Ctrl-C and Ctrl-Shift-C keyboard shortcuts.
-
configureCopyAccelerators
public static List<org.controlsfx.control.action.Action> configureCopyAccelerators(javafx.scene.control.TableView<?> pTableView, Consumer<javafx.event.ActionEvent> pCopySelectedRowHandler)
Configure Ctrl-C and Ctrl-Shift-C keyboard shortcuts.
-
focusedCellToString
public static String focusedCellToString(javafx.scene.control.TableView<?> pTableView)
-
copyFocusedCell
public static void copyFocusedCell(javafx.scene.control.TableView<?> pTableView)
Copy selected cell to clipboard.
-
getColumnIndexPair
public static Map.Entry<Integer,Integer> getColumnIndexPair(javafx.scene.control.TableView<?> pTableView, int pColumnIdx)
If the table contains nested columns, the returned entry's key contains the corresponding table column index and the entry's value the corresponding nested column index or-1
if the column dosn't have nested columns. If the table does not contain nested columns, the returned entry's value is-1
and the entry's key ispColumnIdx
.
-
bindColumns
public static <T> void bindColumns(javafx.scene.control.TableView<T> pDestTableView, javafx.scene.control.TableView<T> pSrcTableView)
-
syncAllColWidths
public void syncAllColWidths(javafx.collections.ObservableList<javafx.collections.ObservableList<javafx.scene.control.TableColumn<?,?>>> pColLists)
Keep column widths in sync for a list of column lists.
-
createHeaderRowProperty
public static javafx.beans.value.ObservableValue<javafx.scene.control.skin.TableHeaderRow> createHeaderRowProperty(javafx.scene.control.TableView<?> pTable)
Creates a read-only property providing the header row of the specified table.
-
createHeaderHeightProperty
public static javafx.beans.property.ReadOnlyProperty<Double> createHeaderHeightProperty(javafx.scene.control.TableView<?> pTable)
Creates a read-only property providing the height of the header of the specified table.
-
createMaxRowHeightProperty
public static <S> javafx.beans.property.ReadOnlyProperty<Double> createMaxRowHeightProperty(javafx.scene.control.TableView<S> pTable)
Creates a read-only property providing the height of the 'tallest' row in the table. Note that this method wraps the table's row factory, so, if a custom row factory is used, it should be set before invoking this method.
-
setEmptyPlaceholder
public static void setEmptyPlaceholder(javafx.scene.control.TableView<?> pTable)
-
createNodeProperty
public static <N extends javafx.scene.Node> javafx.beans.property.ReadOnlyProperty<N> createNodeProperty(javafx.scene.control.Control pParent, String pCssSelector)
-
hideHeader
public static void hideHeader(javafx.scene.control.TableView<?> pTableView)
-
hideHorizontalScrollBar
public static void hideHorizontalScrollBar(javafx.scene.control.TableView<?> pTableView)
-
hideRegion
public static void hideRegion(javafx.beans.value.ObservableValue<? extends javafx.scene.layout.Region> pRegion)
-
hideRegion
public static void hideRegion(javafx.scene.layout.Region pRegion)
-
syncColumnArrangement
public static <I,O> Collection<Object> syncColumnArrangement(javafx.collections.ObservableList<javafx.scene.control.TableColumn<I,?>> pSrcColumns, Function<javafx.scene.control.TableColumn<I,?>,javafx.scene.control.TableColumn<O,?>> pFunction, javafx.scene.control.TableView<O> pDestTableView)
Synchronize ordering and width of columns.- Returns:
- Collection of weak listeners that must be retained lest they be garbage collected.
-
configureColumnReordering
public static Object configureColumnReordering(javafx.scene.control.TableView<?> pTable, javafx.scene.control.TableView<?> pReorderingTable)
Keep reordering line and reordering region in sync when the user is reordering columns.- Parameters:
pTable
- The table which should be kept in sync.pReorderingTable
- The table for which the user will be able to reorder columns.- Returns:
- Weak reference that mustn't be garbage collected.
-
linkSort
public static <T> void linkSort(javafx.scene.control.TableView<?> pSrcTable, javafx.scene.control.TableView<T> pTargetTable)
-
syncSort
public static <T> void syncSort(javafx.scene.control.TableView<?> pSrcTable, javafx.scene.control.TableView<T> pTargetTable)
-
getTableSkin
public static javafx.scene.control.skin.TableViewSkinBase getTableSkin(javafx.scene.control.TableView<?> pTable)
-
syncHorizontalScroll
public static Object syncHorizontalScroll(javafx.collections.ObservableList<? extends javafx.scene.control.TableView<?>> pTables)
- Returns:
- Weak reference that mustn't be garbage collected.
-
ensureRowIsVisible
public static void ensureRowIsVisible(javafx.scene.control.TableView<?> pTable, int pRow)
-
selectPosition
public static <T> void selectPosition(javafx.scene.control.TableView<T> pTable, javafx.scene.control.TablePosition<T,?> pPos)
Selects the specified cell/row and ensures that it's visible. The method does nothing if any of the arguments isnull
.
-
selectRow
public static void selectRow(javafx.scene.control.TableView<?> pTable, int pRow)
Selects the specified row and ensures that it's visible.
-
checkPositions
public static <S> void checkPositions(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pFromPos, javafx.scene.control.TablePosition<S,?> pToPos)
- Throws:
IllegalArgumentException
- if any of the specified positions isnull
, or if an invalid position is specified as an argument, or if one of the specified positions is row based and the other is not.
-
positionStream
public static <S> Stream<javafx.scene.control.TablePosition<S,?>> positionStream(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pFromPos, javafx.scene.control.TablePosition<S,?> pToPos)
Returns a stream of positions frompFromPos
(inclusive) topToPos
(inclusive). IfpFromPos
is greater thanpToPos
, the elements in the stream are provided in backward order.- Throws:
IllegalArgumentException
- if any of the specified positions isnull
, or if an invalid position is specified as an argument, or if one of the specified positions is row based and the other is not.
-
getFirstCellPos
public static <S> javafx.scene.control.TablePosition<S,?> getFirstCellPos(javafx.scene.control.TableView<S> pTable)
Returns the first cell or row position, depending on whether cell selection is enabled, ornull
if the table is empty or has no columns.
-
getLastCellPos
public static <S> javafx.scene.control.TablePosition<S,?> getLastCellPos(javafx.scene.control.TableView<S> pTable)
Returns the last cell or row position, depending on whether cell selection is enabled, ornull
if the table is empty or has no columns.
-
prevPosition
public static <S> javafx.scene.control.TablePosition<S,?> prevPosition(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pPos)
Returns the position of the previous cell ornull
if there is no previous cell or if the specified position isnull
.
-
nextPosition
public static <S> javafx.scene.control.TablePosition<S,?> nextPosition(javafx.scene.control.TableView<S> pTable, javafx.scene.control.TablePosition<S,?> pPos)
Returns the position of the next cell ornull
if there is no next cell. If the specified position isnull
and the table is not empty and there is at least one column in the table, the first cell is returned.
-
compare
public static int compare(javafx.scene.control.TablePositionBase<?> pPos1, javafx.scene.control.TablePositionBase<?> pPos2)
-
embedContent
public static void embedContent(javafx.collections.ObservableList<? extends javafx.scene.control.TableColumn<?,?>> pColumns, javafx.scene.control.TableView<?> pTable)
Display table contents of the specified table within TableColumn2 headers. A VBox is used for the embedded table column and Label for the embedded table cell. The following style classes can be used to tweak the visual appearance of the embedded columns and cells - embedded-table-column, embedded-table-cell.
-
updateFocusedCellOnRightClick
public static void updateFocusedCellOnRightClick(javafx.scene.control.TableView<?> pTable)
-
getCellPositionByScenePosition
public static <S> javafx.scene.control.TablePosition<S,?> getCellPositionByScenePosition(javafx.scene.control.TableView<S> pTable, double pSceneX, double pSceneY)
-
getCellByScenePosition
public static <S> javafx.scene.control.TableCell<S,?> getCellByScenePosition(javafx.scene.control.TableView<S> pTable, double pSceneX, double pSceneY)
-
addItemsListener
public static <T> void addItemsListener(javafx.scene.control.TableView<T> pTable, javafx.beans.value.ChangeListener<? super javafx.collections.ObservableList<T>> pListener)
Using a change listener for TableView.itemsProperty() may result in an unexpected behavior, because when the value of items property is replaced and both old and new lists are empty or have equal elements and size, they will be considered as equal and change event will not be fired. Use this method to add change listeners to items property of a table to prevent such issues.
-
createTextFieldTableCell
public static <S,T> javafx.scene.control.cell.TextFieldTableCell<S,T> createTextFieldTableCell(javafx.scene.control.TableView<S> pTable, javafx.util.StringConverter<T> pConverter)
Use this method as a workaround for the following bugs: Clicking outside of the edited cell, node, or entry should commit the value [TableCell] commit on focus lost not possible in every case .
-
createComboBoxTableCell
public static <S,T> javafx.scene.control.cell.ComboBoxTableCell<S,T> createComboBoxTableCell(javafx.scene.control.TableView<S> pTable, javafx.util.StringConverter<T> pConverter, javafx.collections.ObservableList<T> pItems)
Use this method as a workaround for the following bugs: Clicking outside of the edited cell, node, or entry should commit the value [TableCell] commit on focus lost not possible in every case .
-
addCtrlShiftSelectionRangeMode
public static void addCtrlShiftSelectionRangeMode(javafx.scene.control.TableView<?> pTableView)
Support Ctrl-Shift selection.
-
preserveTableSelection
public static javafx.beans.property.ReadOnlyBooleanProperty preserveTableSelection(javafx.scene.control.TableView<?> pTable)
Use this method to preserve the table selection on item updates whenObservableSortedList
orSimpleLazyObservableList
is used as item list in the table.- Returns:
- A property which can be used to determine whether table selection enters/exits
bogus state. Entering a bogus state (a value of
true
) means that any changes to table selection during this state can be considered irrelevant, because table selection will restore back before exiting the bogus state. In other words, the table selection when exiting the bogus state will be the same as it was when entering the bogus state. - See Also:
ObservableSortedList
,SimpleLazyObservableList
-
getSelectedItems
public static <T> javafx.collections.ObservableList<T> getSelectedItems(javafx.scene.control.TableView<T> pTable)
-
selectIndices
public static void selectIndices(javafx.scene.control.TableView<?> pTable, List<Integer> pIndices)
Efficient way to select indices.
-
getTableHeaderRow
public static javafx.scene.control.skin.TableHeaderRow getTableHeaderRow(javafx.scene.control.TableView<?> pTable)
-
-