modules/controls/src/main/java/javafx/scene/control/TableColumn.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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 com.sun.javafx.scene.control.skin.NestedTableColumnHeader;
  29 import com.sun.javafx.scene.control.skin.TableColumnHeader;
  30 import com.sun.javafx.scene.control.skin.TableHeaderRow;
  31 import com.sun.javafx.scene.control.skin.TableViewSkin;
  32 import com.sun.javafx.scene.control.skin.TableViewSkinBase;

  33 
  34 import javafx.beans.property.ObjectProperty;
  35 import javafx.beans.property.SimpleObjectProperty;
  36 import javafx.collections.FXCollections;
  37 import javafx.collections.ListChangeListener;
  38 import javafx.collections.ObservableList;
  39 import javafx.css.CssMetaData;
  40 import javafx.css.Styleable;
  41 import javafx.event.Event;
  42 import javafx.event.EventHandler;
  43 import javafx.event.EventTarget;
  44 import javafx.event.EventType;
  45 import javafx.scene.Node;
  46 import javafx.scene.control.cell.PropertyValueFactory;
  47 import javafx.util.Callback;
  48 
  49 import javafx.collections.WeakListChangeListener;
  50 import java.util.Collections;
  51 
  52 import java.util.List;


 401      * The cell factory for all cells in this column. The cell factory
 402      * is responsible for rendering the data contained within each TableCell for
 403      * a single table column.
 404      * 
 405      * <p>By default TableColumn uses the {@link #DEFAULT_CELL_FACTORY default cell
 406      * factory}, but this can be replaced with a custom implementation, for 
 407      * example to show data in a different way or to support editing.There is a 
 408      * lot of documentation on creating custom cell factories
 409      * elsewhere (see {@link Cell} and {@link TableView} for example).</p>
 410      *
 411      * <p>Finally, there are a number of pre-built cell factories available in the
 412      * {@link javafx.scene.control.cell} package.
 413      */
 414     private final ObjectProperty<Callback<TableColumn<S,T>, TableCell<S,T>>> cellFactory =
 415         new SimpleObjectProperty<Callback<TableColumn<S,T>, TableCell<S,T>>>(
 416             this, "cellFactory", (Callback<TableColumn<S,T>, TableCell<S,T>>) ((Callback) DEFAULT_CELL_FACTORY)) {
 417                 @Override protected void invalidated() {
 418                     TableView<S> table = getTableView();
 419                     if (table == null) return;
 420                     Map<Object,Object> properties = table.getProperties();
 421                     if (properties.containsKey(TableViewSkinBase.RECREATE)) {
 422                         properties.remove(TableViewSkinBase.RECREATE);
 423                     }
 424                     properties.put(TableViewSkinBase.RECREATE, Boolean.TRUE);
 425                 }
 426             };
 427 
 428     public final void setCellFactory(Callback<TableColumn<S,T>, TableCell<S,T>> value) {
 429         cellFactory.set(value);
 430     }
 431 
 432     public final Callback<TableColumn<S,T>, TableCell<S,T>> getCellFactory() {
 433         return cellFactory.get();
 434     }
 435 
 436     public final ObjectProperty<Callback<TableColumn<S,T>, TableCell<S,T>>> cellFactoryProperty() {
 437         return cellFactory;
 438     }
 439 
 440     
 441     
 442     // --- Sort Type
 443     /**
 444      * Used to state whether this column, if it is part of a sort order (see


 619 
 620     /**
 621      * @return The CssMetaData associated with this class, which may include the
 622      * CssMetaData of its super classes.
 623      * @since JavaFX 8.0
 624      */
 625     public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
 626         return Collections.emptyList();
 627     }                
 628    
 629     /**
 630      * @treatAsPrivate implementation detail
 631      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 632      */
 633     @Deprecated    
 634     // SB-dependency: RT-21094 has been filed to track this   
 635    public Node impl_styleableGetNode() {
 636         if (! (getTableView().getSkin() instanceof TableViewSkin)) return null;
 637         TableViewSkin<?> skin = (TableViewSkin<?>) getTableView().getSkin();
 638 
 639         TableHeaderRow tableHeader = skin.getTableHeaderRow();
 640         NestedTableColumnHeader rootHeader = tableHeader.getRootHeader();











 641 
 642         // we now need to do a search for the header. We'll go depth-first.
 643         return scan(rootHeader);
 644     }
 645 
 646     private TableColumnHeader scan(TableColumnHeader header) {
 647         // firstly test that the parent isn't what we are looking for
 648         if (TableColumn.this.equals(header.getTableColumn())) {
 649             return header;
 650         }
 651 
 652         if (header instanceof NestedTableColumnHeader) {
 653             NestedTableColumnHeader parent = (NestedTableColumnHeader) header;
 654             for (int i = 0; i < parent.getColumnHeaders().size(); i++) {
 655                 TableColumnHeader result = scan(parent.getColumnHeaders().get(i));
 656                 if (result != null) {
 657                     return result;
 658                 }
 659             }
 660         }




   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 com.sun.javafx.scene.control.Properties;
  29 import javafx.scene.control.skin.NestedTableColumnHeader;
  30 import javafx.scene.control.skin.TableColumnHeader;
  31 import javafx.scene.control.skin.TableHeaderRow;
  32 import javafx.scene.control.skin.TableViewSkin;
  33 import javafx.scene.control.skin.TableViewSkinBase;
  34 
  35 import javafx.beans.property.ObjectProperty;
  36 import javafx.beans.property.SimpleObjectProperty;
  37 import javafx.collections.FXCollections;
  38 import javafx.collections.ListChangeListener;
  39 import javafx.collections.ObservableList;
  40 import javafx.css.CssMetaData;
  41 import javafx.css.Styleable;
  42 import javafx.event.Event;
  43 import javafx.event.EventHandler;
  44 import javafx.event.EventTarget;
  45 import javafx.event.EventType;
  46 import javafx.scene.Node;
  47 import javafx.scene.control.cell.PropertyValueFactory;
  48 import javafx.util.Callback;
  49 
  50 import javafx.collections.WeakListChangeListener;
  51 import java.util.Collections;
  52 
  53 import java.util.List;


 402      * The cell factory for all cells in this column. The cell factory
 403      * is responsible for rendering the data contained within each TableCell for
 404      * a single table column.
 405      * 
 406      * <p>By default TableColumn uses the {@link #DEFAULT_CELL_FACTORY default cell
 407      * factory}, but this can be replaced with a custom implementation, for 
 408      * example to show data in a different way or to support editing.There is a 
 409      * lot of documentation on creating custom cell factories
 410      * elsewhere (see {@link Cell} and {@link TableView} for example).</p>
 411      *
 412      * <p>Finally, there are a number of pre-built cell factories available in the
 413      * {@link javafx.scene.control.cell} package.
 414      */
 415     private final ObjectProperty<Callback<TableColumn<S,T>, TableCell<S,T>>> cellFactory =
 416         new SimpleObjectProperty<Callback<TableColumn<S,T>, TableCell<S,T>>>(
 417             this, "cellFactory", (Callback<TableColumn<S,T>, TableCell<S,T>>) ((Callback) DEFAULT_CELL_FACTORY)) {
 418                 @Override protected void invalidated() {
 419                     TableView<S> table = getTableView();
 420                     if (table == null) return;
 421                     Map<Object,Object> properties = table.getProperties();
 422                     if (properties.containsKey(Properties.RECREATE)) {
 423                         properties.remove(Properties.RECREATE);
 424                     }
 425                     properties.put(Properties.RECREATE, Boolean.TRUE);
 426                 }
 427             };
 428 
 429     public final void setCellFactory(Callback<TableColumn<S,T>, TableCell<S,T>> value) {
 430         cellFactory.set(value);
 431     }
 432 
 433     public final Callback<TableColumn<S,T>, TableCell<S,T>> getCellFactory() {
 434         return cellFactory.get();
 435     }
 436 
 437     public final ObjectProperty<Callback<TableColumn<S,T>, TableCell<S,T>>> cellFactoryProperty() {
 438         return cellFactory;
 439     }
 440 
 441     
 442     
 443     // --- Sort Type
 444     /**
 445      * Used to state whether this column, if it is part of a sort order (see


 620 
 621     /**
 622      * @return The CssMetaData associated with this class, which may include the
 623      * CssMetaData of its super classes.
 624      * @since JavaFX 8.0
 625      */
 626     public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
 627         return Collections.emptyList();
 628     }                
 629    
 630     /**
 631      * @treatAsPrivate implementation detail
 632      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 633      */
 634     @Deprecated    
 635     // SB-dependency: RT-21094 has been filed to track this   
 636    public Node impl_styleableGetNode() {
 637         if (! (getTableView().getSkin() instanceof TableViewSkin)) return null;
 638         TableViewSkin<?> skin = (TableViewSkin<?>) getTableView().getSkin();
 639 
 640         TableHeaderRow tableHeader = null;
 641         for (Node n : skin.getChildren()) {
 642             if (n instanceof TableHeaderRow) {
 643                 tableHeader = (TableHeaderRow)n;
 644             }
 645         }
 646 
 647         NestedTableColumnHeader rootHeader = null;
 648         for (Node n : tableHeader.getChildren()) {
 649             if (n instanceof NestedTableColumnHeader) {
 650                 rootHeader = (NestedTableColumnHeader) n;
 651             }
 652         }
 653 
 654         // we now need to do a search for the header. We'll go depth-first.
 655         return scan(rootHeader);
 656     }
 657 
 658     private TableColumnHeader scan(TableColumnHeader header) {
 659         // firstly test that the parent isn't what we are looking for
 660         if (TableColumn.this.equals(header.getTableColumn())) {
 661             return header;
 662         }
 663 
 664         if (header instanceof NestedTableColumnHeader) {
 665             NestedTableColumnHeader parent = (NestedTableColumnHeader) header;
 666             for (int i = 0; i < parent.getColumnHeaders().size(); i++) {
 667                 TableColumnHeader result = scan(parent.getColumnHeaders().get(i));
 668                 if (result != null) {
 669                     return result;
 670                 }
 671             }
 672         }