1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.scene.control;
  27 
  28 import javafx.beans.property.BooleanProperty;
  29 import javafx.beans.property.SimpleBooleanProperty;
  30 
  31 /**
  32  * The abstract base class for MultipleSelectionModel implementations that are used within
  33  * table-like controls (most notably {@link TableView} and {@link TreeTableView}.
  34  *
  35  * @param <T> The type of the underlying data model for the UI control.
  36  * @since JavaFX 8.0
  37  */
  38 public abstract class TableSelectionModel<T> extends MultipleSelectionModelBase<T> {
  39 
  40     /**
  41      * Convenience function which tests whether the given row and column index
  42      * is currently selected in this table instance. If the table control is in its
  43      * 'cell selection' mode (where individual cells can be selected, rather than
  44      * entire rows), and if the column argument is null, this method should return
  45      * true only if all cells in the given row are selected.
  46      */
  47     public abstract boolean isSelected(int row, TableColumnBase<T,?> column);
  48 
  49     /**
  50      * Selects the cell at the given row/column intersection. If the table control is in its
  51      * 'cell selection' mode (where individual cells can be selected, rather than
  52      * entire rows), and if the column argument is null, this method should select
  53      * all cells in the given row.
  54      */
  55     public abstract void select(int row, TableColumnBase<T,?> column);
  56 
  57     /**
  58      * Clears all selection, and then selects the cell at the given row/column
  59      * intersection. If the table control is in its
  60      * 'cell selection' mode (where individual cells can be selected, rather than
  61      * entire rows), and if the column argument is null, this method should select
  62      * all cells in the given row.
  63      */
  64     public abstract void clearAndSelect(int row, TableColumnBase<T,?> column);
  65 
  66     /**
  67      * Removes selection from the specified row/column position (in view indexes).
  68      * If this particular cell (or row if the column value is -1) is not selected,
  69      * nothing happens. If the table control is in its
  70      * 'cell selection' mode (where individual cells can be selected, rather than
  71      * entire rows), and if the column argument is null, this method should deselect
  72      * all cells in the given row.
  73      */
  74     public abstract void clearSelection(int row, TableColumnBase<T,?> column);
  75 
  76     /**
  77      * Selects the cell to the left of the currently selected cell.
  78      */
  79     public abstract void selectLeftCell();
  80 
  81     /**
  82      * Selects the cell to the right of the currently selected cell.
  83      */
  84     public abstract void selectRightCell();
  85 
  86     /**
  87      * Selects the cell directly above the currently selected cell.
  88      */
  89     public abstract void selectAboveCell();
  90 
  91     /**
  92      * Selects the cell directly below the currently selected cell.
  93      */
  94     public abstract void selectBelowCell();
  95 
  96     /**
  97      * Selects the cells in the range (minRow, minColumn) to (maxRow, maxColumn),
  98      * inclusive.
  99      */
 100     public abstract void selectRange(int minRow, TableColumnBase<T,?> minColumn,
 101                                      int maxRow, TableColumnBase<T,?> maxColumn);
 102 
 103     /**
 104      * A boolean property used to represent whether the table is in
 105      * row or cell selection modes. By default a table is in row selection
 106      * mode which means that individual cells can not be selected. Setting
 107      * <code>cellSelectionEnabled</code> to be true results in cells being
 108      * able to be selected (but not rows).
 109      */
 110     private BooleanProperty cellSelectionEnabled =
 111            new SimpleBooleanProperty(this, "cellSelectionEnabled");
 112     public final BooleanProperty cellSelectionEnabledProperty() {
 113        return cellSelectionEnabled;
 114     }
 115     public final void setCellSelectionEnabled(boolean value) {
 116        cellSelectionEnabledProperty().set(value);
 117     }
 118     public final boolean isCellSelectionEnabled() {
 119        return cellSelectionEnabled == null ? false : cellSelectionEnabled.get();
 120     }
 121 }