modules/controls/src/main/java/javafx/scene/control/TreeTableColumn.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 javafx.css.CssMetaData;
  29 import java.util.Collections;
  30 import java.util.List;
  31 import java.util.Map;
  32 import javafx.beans.property.ObjectProperty;
  33 import javafx.beans.property.ReadOnlyObjectProperty;
  34 import javafx.beans.property.ReadOnlyObjectWrapper;
  35 import javafx.beans.property.SimpleObjectProperty;
  36 import javafx.beans.value.ObservableValue;
  37 import javafx.beans.value.WritableValue;
  38 import javafx.collections.FXCollections;
  39 import javafx.collections.ListChangeListener;
  40 import javafx.collections.ObservableList;
  41 import javafx.collections.WeakListChangeListener;
  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.util.Callback;
  48 import javafx.css.Styleable;
  49 import com.sun.javafx.scene.control.skin.TableViewSkinBase;
  50 /**
  51  * A {@link TreeTableView} is made up of a number of TreeTableColumn instances. Each
  52  * TreeTableColumn in a {@link TreeTableView} is responsible for displaying
  53  * (and editing) the contents of that column. As well as being responsible for
  54  * displaying and editing data for a single column, a TreeTableColumn also
  55  * contains the necessary properties to:
  56  * <ul>
  57  *    <li>Be resized (using {@link #minWidthProperty() minWidth}/
  58  *    {@link #prefWidthProperty() prefWidth}/
  59  *    {@link #maxWidthProperty() maxWidth} and {@link #widthProperty() width} properties)
  60  *    <li>Have its {@link #visibleProperty() visibility} toggled
  61  *    <li>Display {@link #textProperty() header text}
  62  *    <li>Display any {@link #getColumns() nested columns} it may contain
  63  *    <li>Have a {@link #contextMenuProperty() context menu} when the user 
  64  *      right-clicks the column header area
  65  *    <li>Have the contents of the table be sorted (using 
  66  *      {@link #comparatorProperty() comparator}, {@link #sortable sortable} and
  67  *      {@link #sortTypeProperty() sortType})
  68  * </ul>
  69  * </p>


 394      * is responsible for rendering the data contained within each TreeTableCell 
 395      * for a single TreeTableColumn.
 396      * 
 397      * <p>By default TreeTableColumn uses a {@link #DEFAULT_CELL_FACTORY default cell
 398      * factory}, but this can be replaced with a custom implementation, for 
 399      * example to show data in a different way or to support editing. There is a 
 400      * lot of documentation on creating custom cell factories
 401      * elsewhere (see {@link Cell} and {@link TreeTableView} for example).</p>
 402      * 
 403      * <p>Finally, there are a number of pre-built cell factories available in the
 404      * {@link javafx.scene.control.cell} package.
 405      *
 406      */
 407     private final ObjectProperty<Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>> cellFactory =
 408         new SimpleObjectProperty<Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>>(
 409             this, "cellFactory", (Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>) ((Callback) DEFAULT_CELL_FACTORY)) {
 410                 @Override protected void invalidated() {
 411                     TreeTableView<S> table = getTreeTableView();
 412                     if (table == null) return;
 413                     Map<Object,Object> properties = table.getProperties();
 414                     if (properties.containsKey(TableViewSkinBase.RECREATE)) {
 415                         properties.remove(TableViewSkinBase.RECREATE);
 416                     }
 417                     properties.put(TableViewSkinBase.RECREATE, Boolean.TRUE);
 418                 }
 419             };
 420     public final void setCellFactory(Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>> value) {
 421         cellFactory.set(value);
 422     }
 423     public final Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>> getCellFactory() {
 424         return cellFactory.get();
 425     }
 426     public final ObjectProperty<Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>> cellFactoryProperty() {
 427         return cellFactory;
 428     }
 429     
 430     
 431     // --- Sort Type
 432     /**
 433      * Used to state whether this column, if it is part of a sort order (see
 434      * {@link TreeTableView#getSortOrder()} for more details), should be sorted 
 435      * in ascending or descending order. 
 436      * Simply toggling this property will result in the sort order changing in 
 437      * the TreeTableView, assuming of course that this column is in the 




   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.css.CssMetaData;
  30 import java.util.Collections;
  31 import java.util.List;
  32 import java.util.Map;
  33 import javafx.beans.property.ObjectProperty;
  34 import javafx.beans.property.ReadOnlyObjectProperty;
  35 import javafx.beans.property.ReadOnlyObjectWrapper;
  36 import javafx.beans.property.SimpleObjectProperty;
  37 import javafx.beans.value.ObservableValue;
  38 import javafx.beans.value.WritableValue;
  39 import javafx.collections.FXCollections;
  40 import javafx.collections.ListChangeListener;
  41 import javafx.collections.ObservableList;
  42 import javafx.collections.WeakListChangeListener;
  43 import javafx.event.Event;
  44 import javafx.event.EventHandler;
  45 import javafx.event.EventTarget;
  46 import javafx.event.EventType;
  47 import javafx.scene.Node;
  48 import javafx.util.Callback;
  49 import javafx.css.Styleable;
  50 import javafx.scene.control.skin.TableViewSkinBase;
  51 /**
  52  * A {@link TreeTableView} is made up of a number of TreeTableColumn instances. Each
  53  * TreeTableColumn in a {@link TreeTableView} is responsible for displaying
  54  * (and editing) the contents of that column. As well as being responsible for
  55  * displaying and editing data for a single column, a TreeTableColumn also
  56  * contains the necessary properties to:
  57  * <ul>
  58  *    <li>Be resized (using {@link #minWidthProperty() minWidth}/
  59  *    {@link #prefWidthProperty() prefWidth}/
  60  *    {@link #maxWidthProperty() maxWidth} and {@link #widthProperty() width} properties)
  61  *    <li>Have its {@link #visibleProperty() visibility} toggled
  62  *    <li>Display {@link #textProperty() header text}
  63  *    <li>Display any {@link #getColumns() nested columns} it may contain
  64  *    <li>Have a {@link #contextMenuProperty() context menu} when the user 
  65  *      right-clicks the column header area
  66  *    <li>Have the contents of the table be sorted (using 
  67  *      {@link #comparatorProperty() comparator}, {@link #sortable sortable} and
  68  *      {@link #sortTypeProperty() sortType})
  69  * </ul>
  70  * </p>


 395      * is responsible for rendering the data contained within each TreeTableCell 
 396      * for a single TreeTableColumn.
 397      * 
 398      * <p>By default TreeTableColumn uses a {@link #DEFAULT_CELL_FACTORY default cell
 399      * factory}, but this can be replaced with a custom implementation, for 
 400      * example to show data in a different way or to support editing. There is a 
 401      * lot of documentation on creating custom cell factories
 402      * elsewhere (see {@link Cell} and {@link TreeTableView} for example).</p>
 403      * 
 404      * <p>Finally, there are a number of pre-built cell factories available in the
 405      * {@link javafx.scene.control.cell} package.
 406      *
 407      */
 408     private final ObjectProperty<Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>> cellFactory =
 409         new SimpleObjectProperty<Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>>(
 410             this, "cellFactory", (Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>) ((Callback) DEFAULT_CELL_FACTORY)) {
 411                 @Override protected void invalidated() {
 412                     TreeTableView<S> table = getTreeTableView();
 413                     if (table == null) return;
 414                     Map<Object,Object> properties = table.getProperties();
 415                     if (properties.containsKey(Properties.RECREATE)) {
 416                         properties.remove(Properties.RECREATE);
 417                     }
 418                     properties.put(Properties.RECREATE, Boolean.TRUE);
 419                 }
 420             };
 421     public final void setCellFactory(Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>> value) {
 422         cellFactory.set(value);
 423     }
 424     public final Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>> getCellFactory() {
 425         return cellFactory.get();
 426     }
 427     public final ObjectProperty<Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>>> cellFactoryProperty() {
 428         return cellFactory;
 429     }
 430     
 431     
 432     // --- Sort Type
 433     /**
 434      * Used to state whether this column, if it is part of a sort order (see
 435      * {@link TreeTableView#getSortOrder()} for more details), should be sorted 
 436      * in ascending or descending order. 
 437      * Simply toggling this property will result in the sort order changing in 
 438      * the TreeTableView, assuming of course that this column is in the