1 /*
   2  * Copyright (c) 2011, 2014, 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 com.sun.javafx.scene.control.behavior;
  27 
  28 import javafx.scene.control.TableCell;
  29 import javafx.scene.control.TableColumn;
  30 import javafx.scene.control.TableColumnBase;
  31 import javafx.scene.control.TablePositionBase;
  32 import javafx.scene.control.TableView;
  33 
  34 import javafx.scene.control.TableView.TableViewFocusModel;
  35 
  36 /**
  37  */
  38 public class TableCellBehavior<S,T> extends TableCellBehaviorBase<S, T, TableColumn<S,?>, TableCell<S, T>> {
  39     
  40     /***************************************************************************
  41      *                                                                         *
  42      * Constructors                                                            *
  43      *                                                                         *
  44      **************************************************************************/    
  45 
  46     public TableCellBehavior(TableCell<S,T> control) {
  47         super(control);
  48     }
  49     
  50     
  51     
  52     /***************************************************************************
  53      *                                                                         *
  54      * Implement TableCellBehaviorBase Abstract API                            *
  55      *                                                                         *
  56      **************************************************************************/          
  57 
  58     /** @{@inheritDoc} */
  59     @Override protected TableView<S> getCellContainer() {
  60         return getControl().getTableView();
  61     }
  62 
  63     /** @{@inheritDoc} */
  64     @Override protected TableColumn<S,T> getTableColumn() {
  65         return getControl().getTableColumn();
  66     }
  67 
  68     /** @{@inheritDoc} */
  69     @Override protected int getItemCount() {
  70         return getCellContainer().getItems().size();
  71     }
  72 
  73     /** @{@inheritDoc} */
  74     @Override protected TableView.TableViewSelectionModel<S> getSelectionModel() {
  75         return getCellContainer().getSelectionModel();
  76     }
  77 
  78     /** @{@inheritDoc} */
  79     @Override protected TableViewFocusModel<S> getFocusModel() {
  80         return getCellContainer().getFocusModel();
  81     }
  82 
  83     /** @{@inheritDoc} */
  84     @Override protected TablePositionBase getFocusedCell() {
  85         return getCellContainer().getFocusModel().getFocusedCell();
  86     }
  87 
  88     /** @{@inheritDoc} */
  89     @Override protected boolean isTableRowSelected() {
  90         return getControl().getTableRow().isSelected();
  91     }
  92 
  93     /** @{@inheritDoc} */
  94     @Override protected int getVisibleLeafIndex(TableColumnBase tc) {
  95         return getCellContainer().getVisibleLeafIndex((TableColumn) tc);
  96     }
  97 
  98     /** @{@inheritDoc} */
  99     @Override protected void focus(int row, TableColumnBase tc) {
 100         getFocusModel().focus(row, (TableColumn)tc);
 101     }
 102 
 103     /** @{@inheritDoc} */
 104     @Override protected void edit(TableCell<S,T> cell) {
 105         if (cell == null) {
 106             getCellContainer().edit(-1, null);
 107         } else {
 108             getCellContainer().edit(cell.getIndex(), cell.getTableColumn());
 109         }
 110     }
 111 }