modules/controls/src/main/java/javafx/scene/control/skin/TableRowSkin.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 21,44 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package com.sun.javafx.scene.control.skin;
import java.util.ArrayList;
import java.util.List;
import javafx.beans.property.DoubleProperty;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
- import com.sun.javafx.scene.control.behavior.CellBehaviorBase;
import com.sun.javafx.scene.control.behavior.TableRowBehavior;
import javafx.beans.property.ObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
--- 21,46 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package javafx.scene.control.skin;
import java.util.ArrayList;
import java.util.List;
+ import com.sun.javafx.scene.control.behavior.BehaviorBase;
import javafx.beans.property.DoubleProperty;
+ import javafx.scene.control.Accordion;
+ import javafx.scene.control.Button;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import com.sun.javafx.scene.control.behavior.TableRowBehavior;
import javafx.beans.property.ObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
*** 47,178 ****
import javafx.scene.control.Control;
import javafx.scene.control.TableColumnBase;
import javafx.scene.control.TableView.TableViewFocusModel;
/**
*/
! public class TableRowSkin<T> extends TableRowSkinBase<T, TableRow<T>, CellBehaviorBase<TableRow<T>>, TableCell<T,?>> {
- private TableView<T> tableView;
private TableViewSkin<T> tableViewSkin;
- public TableRowSkin(TableRow<T> tableRow) {
- super(tableRow, new TableRowBehavior<T>(tableRow));
- this.tableView = tableRow.getTableView();
- updateTableViewSkin();
! super.init(tableRow);
! registerChangeListener(tableRow.tableViewProperty(), "TABLE_VIEW");
! }
! @Override protected void handleControlPropertyChanged(String p) {
! super.handleControlPropertyChanged(p);
! if ("TABLE_VIEW".equals(p)) {
updateTableViewSkin();
for (int i = 0, max = cells.size(); i < max; i++) {
Node n = cells.get(i);
if (n instanceof TableCell) {
((TableCell)n).updateTableView(getSkinnable().getTableView());
}
}
!
! this.tableView = getSkinnable().getTableView();
! }
}
- @Override protected TableCell<T, ?> getCell(TableColumnBase tcb) {
- TableColumn tableColumn = (TableColumn<T,?>) tcb;
- TableCell cell = (TableCell) tableColumn.getCellFactory().call(tableColumn);
- // we set it's TableColumn, TableView and TableRow
- cell.updateTableColumn(tableColumn);
- cell.updateTableView(tableColumn.getTableView());
- cell.updateTableRow(getSkinnable());
! return cell;
! }
! @Override protected ObservableList<TableColumn<T, ?>> getVisibleLeafColumns() {
! return tableView.getVisibleLeafColumns();
! }
! @Override protected void updateCell(TableCell<T, ?> cell, TableRow<T> row) {
! cell.updateTableRow(row);
}
-
- @Override protected DoubleProperty fixedCellSizeProperty() {
- return tableView.fixedCellSizeProperty();
}
! @Override protected boolean isColumnPartiallyOrFullyVisible(TableColumnBase tc) {
! return tableViewSkin == null ? false : tableViewSkin.isColumnPartiallyOrFullyVisible((TableColumn)tc);
! }
!
! @Override protected TableColumn<T, ?> getTableColumnBase(TableCell<T, ?> cell) {
! return cell.getTableColumn();
! }
!
! @Override protected ObjectProperty<Node> graphicProperty() {
! return null;
! }
!
! @Override protected Control getVirtualFlowOwner() {
! return getSkinnable().getTableView();
! }
!
! private void updateTableViewSkin() {
! TableView<T> tableView = getSkinnable().getTableView();
! if (tableView.getSkin() instanceof TableViewSkin) {
! tableViewSkin = (TableViewSkin)tableView.getSkin();
! }
! }
!
! @Override
! protected Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
switch (attribute) {
case SELECTED_ITEMS: {
// FIXME this could be optimised to iterate over cellsMap only
// (selectedCells could be big, cellsMap is much smaller)
List<Node> selection = new ArrayList<>();
int index = getSkinnable().getIndex();
! for (TablePosition<T,?> pos : tableView.getSelectionModel().getSelectedCells()) {
if (pos.getRow() == index) {
TableColumn<T,?> column = pos.getTableColumn();
if (column == null) {
/* This is the row-based case */
! column = tableView.getVisibleLeafColumn(0);
}
TableCell<T,?> cell = cellsMap.get(column).get();
if (cell != null) selection.add(cell);
}
return FXCollections.observableArrayList(selection);
}
}
case CELL_AT_ROW_COLUMN: {
int colIndex = (Integer)parameters[1];
! TableColumn<T,?> column = tableView.getVisibleLeafColumn(colIndex);
if (cellsMap.containsKey(column)) {
return cellsMap.get(column).get();
}
return null;
}
case FOCUS_ITEM: {
! TableViewFocusModel<T> fm = tableView.getFocusModel();
TablePosition<T,?> focusedCell = fm.getFocusedCell();
TableColumn<T,?> column = focusedCell.getTableColumn();
if (column == null) {
/* This is the row-based case */
! column = tableView.getVisibleLeafColumn(0);
}
if (cellsMap.containsKey(column)) {
return cellsMap.get(column).get();
}
return null;
}
default: return super.queryAccessibleAttribute(attribute, parameters);
}
}
}
--- 49,231 ----
import javafx.scene.control.Control;
import javafx.scene.control.TableColumnBase;
import javafx.scene.control.TableView.TableViewFocusModel;
/**
+ * Default skin implementation for the {@link TableRow} control.
+ *
+ * @see TableRow
+ * @since 9
*/
! public class TableRowSkin<T> extends TableRowSkinBase<T, TableRow<T>, TableCell<T,?>> {
!
! /***************************************************************************
! * *
! * Private fields *
! * *
! **************************************************************************/
private TableViewSkin<T> tableViewSkin;
+ private final BehaviorBase<TableRow<T>> behavior;
! /***************************************************************************
! * *
! * Constructors *
! * *
! **************************************************************************/
!
! /**
! * Creates a new TableRowSkin instance, installing the necessary child
! * nodes into the Control {@link Control#getChildren() children} list, as
! * well as the necessary input mappings for handling key, mouse, etc events.
! *
! * @param control The control that this skin should be installed onto.
! */
! public TableRowSkin(TableRow<T> control) {
! super(control);
! // install default input map for the TableRow control
! behavior = new TableRowBehavior<>(control);
! // control.setInputMap(behavior.getInputMap());
!
! updateTableViewSkin();
! registerChangeListener(control.tableViewProperty(), e -> {
updateTableViewSkin();
for (int i = 0, max = cells.size(); i < max; i++) {
Node n = cells.get(i);
if (n instanceof TableCell) {
((TableCell)n).updateTableView(getSkinnable().getTableView());
}
}
! });
}
! /***************************************************************************
! * *
! * Public API *
! * *
! **************************************************************************/
! /** {@inheritDoc} */
! @Override public void dispose() {
! super.dispose();
! if (behavior != null) {
! behavior.dispose();
}
}
! /** {@inheritDoc} */
! @Override protected Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
switch (attribute) {
case SELECTED_ITEMS: {
// FIXME this could be optimised to iterate over cellsMap only
// (selectedCells could be big, cellsMap is much smaller)
List<Node> selection = new ArrayList<>();
int index = getSkinnable().getIndex();
! for (TablePosition<T,?> pos : getVirtualFlowOwner().getSelectionModel().getSelectedCells()) {
if (pos.getRow() == index) {
TableColumn<T,?> column = pos.getTableColumn();
if (column == null) {
/* This is the row-based case */
! column = getVirtualFlowOwner().getVisibleLeafColumn(0);
}
TableCell<T,?> cell = cellsMap.get(column).get();
if (cell != null) selection.add(cell);
}
return FXCollections.observableArrayList(selection);
}
}
case CELL_AT_ROW_COLUMN: {
int colIndex = (Integer)parameters[1];
! TableColumn<T,?> column = getVirtualFlowOwner().getVisibleLeafColumn(colIndex);
if (cellsMap.containsKey(column)) {
return cellsMap.get(column).get();
}
return null;
}
case FOCUS_ITEM: {
! TableViewFocusModel<T> fm = getVirtualFlowOwner().getFocusModel();
TablePosition<T,?> focusedCell = fm.getFocusedCell();
TableColumn<T,?> column = focusedCell.getTableColumn();
if (column == null) {
/* This is the row-based case */
! column = getVirtualFlowOwner().getVisibleLeafColumn(0);
}
if (cellsMap.containsKey(column)) {
return cellsMap.get(column).get();
}
return null;
}
default: return super.queryAccessibleAttribute(attribute, parameters);
}
}
+
+
+ /***************************************************************************
+ * *
+ * Private implementation *
+ * *
+ **************************************************************************/
+
+ /** {@inheritDoc} */
+ @Override TableCell<T, ?> getCell(TableColumnBase tcb) {
+ TableColumn tableColumn = (TableColumn<T,?>) tcb;
+ TableCell cell = (TableCell) tableColumn.getCellFactory().call(tableColumn);
+
+ // we set it's TableColumn, TableView and TableRow
+ cell.updateTableColumn(tableColumn);
+ cell.updateTableView(tableColumn.getTableView());
+ cell.updateTableRow(getSkinnable());
+
+ return cell;
+ }
+
+ /** {@inheritDoc} */
+ @Override ObservableList<TableColumn<T, ?>> getVisibleLeafColumns() {
+ return getVirtualFlowOwner().getVisibleLeafColumns();
+ }
+
+ /** {@inheritDoc} */
+ @Override void updateCell(TableCell<T, ?> cell, TableRow<T> row) {
+ cell.updateTableRow(row);
+ }
+
+ /** {@inheritDoc} */
+ @Override DoubleProperty fixedCellSizeProperty() {
+ return getVirtualFlowOwner().fixedCellSizeProperty();
+ }
+
+ /** {@inheritDoc} */
+ @Override boolean isColumnPartiallyOrFullyVisible(TableColumnBase tc) {
+ return tableViewSkin == null ? false : tableViewSkin.isColumnPartiallyOrFullyVisible((TableColumn)tc);
+ }
+
+ /** {@inheritDoc} */
+ @Override TableColumn<T, ?> getTableColumnBase(TableCell<T, ?> cell) {
+ return cell.getTableColumn();
+ }
+
+ /** {@inheritDoc} */
+ @Override ObjectProperty<Node> graphicProperty() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override TableView<T> getVirtualFlowOwner() {
+ return getSkinnable().getTableView();
+ }
+
+ private void updateTableViewSkin() {
+ TableView<T> tableView = getSkinnable().getTableView();
+ if (tableView.getSkin() instanceof TableViewSkin) {
+ tableViewSkin = (TableViewSkin)tableView.getSkin();
+ }
+ }
}