< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTreeCell.java

Print this page




  53  * @param <T> The type of the TreeItems contained within the TreeView.
  54  * @since JavaFX 2.2
  55  */
  56 public class ChoiceBoxTreeCell<T> extends DefaultTreeCell<T> {
  57 
  58     /***************************************************************************
  59      *                                                                         *
  60      * Static cell factories                                                   *
  61      *                                                                         *
  62      **************************************************************************/
  63 
  64     /**
  65      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
  66      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
  67      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
  68      * default, stretch to fill the entire tree cell.
  69      *
  70      * @param <T> The type of the elements contained within the TreeView.
  71      * @param items Zero or more items that will be shown to the user when the
  72      *      {@link ChoiceBox} menu is showing. These items must be of the same
  73      *      type as the TreeView<T>, such that upon selection, they replace the
  74      *      existing value in the TreeItem {@link TreeItem#valueProperty() value}
  75      *      property.
  76      * @return A {@link Callback} that will return a TreeCell that is able to
  77      *      work on the type of element contained within the TreeView.
  78      */
  79     @SafeVarargs
  80     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(T... items) {
  81         return forTreeView(FXCollections.observableArrayList(items));
  82     }
  83 
  84     /**
  85      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
  86      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
  87      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
  88      * default, stretch to fill the entire tree cell, excluding the space
  89      * allocated to the tree cell indentation and disclosure node (i.e. the
  90      * arrow).
  91      *
  92      * @param <T> The type of the {@link TreeItem} elements contained within the
  93      *      TreeView.


  99      *      {@link TreeView#editingItemProperty()}.
 100      * @return A {@link Callback} that will return a TreeCell that is able to
 101      *      work on the type of element contained within the TreeView.
 102      */
 103     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(
 104             final ObservableList<T> items) {
 105         return forTreeView(null, items);
 106     }
 107 
 108     /**
 109      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
 110      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
 111      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
 112      * default, stretch to fill the entire tree cell.
 113      *
 114      * @param <T> The type of the elements contained within the TreeView.
 115      * @param converter A {@link StringConverter} to convert the given item (of type T)
 116      *      to a String for displaying to the user.
 117      * @param items Zero or more items that will be shown to the user when the
 118      *      {@link ChoiceBox} menu is showing. These items must be of the same
 119      *      type as the TreeView<T>, such that upon selection, they replace the
 120      *      existing value in the TreeItem {@link TreeItem#valueProperty() value}
 121      *      property.
 122      * @return A {@link Callback} that will return a TreeCell that is able to
 123      *      work on the type of element contained within the TreeView.
 124      */
 125     @SafeVarargs
 126     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(
 127             final StringConverter<T> converter,
 128             final T... items) {
 129         return forTreeView(converter, FXCollections.observableArrayList(items));
 130     }
 131 
 132     /**
 133      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
 134      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
 135      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
 136      * default, stretch to fill the entire tree cell.
 137      *
 138      * @param <T> The type of the elements contained within the TreeView.
 139      * @param converter A {@link StringConverter} to convert the given item (of type T)


 237     public ChoiceBoxTreeCell(StringConverter<T> converter, ObservableList<T> items) {
 238         this.getStyleClass().add("choice-box-tree-cell");
 239         this.items = items;
 240         setConverter(converter != null ? converter : CellUtils.<T>defaultStringConverter());
 241     }
 242 
 243 
 244 
 245     /***************************************************************************
 246      *                                                                         *
 247      * Properties                                                              *
 248      *                                                                         *
 249      **************************************************************************/
 250 
 251     // --- converter
 252     private ObjectProperty<StringConverter<T>> converter =
 253             new SimpleObjectProperty<StringConverter<T>>(this, "converter");
 254 
 255     /**
 256      * The {@link StringConverter} property.

 257      */
 258     public final ObjectProperty<StringConverter<T>> converterProperty() {
 259         return converter;
 260     }
 261 
 262     /**
 263      * Sets the {@link StringConverter} to be used in this cell.

 264      */
 265     public final void setConverter(StringConverter<T> value) {
 266         converterProperty().set(value);
 267     }
 268 
 269     /**
 270      * Returns the {@link StringConverter} used in this cell.

 271      */
 272     public final StringConverter<T> getConverter() {
 273         return converterProperty().get();
 274     }
 275 
 276 
 277 
 278     /***************************************************************************
 279      *                                                                         *
 280      * Public API                                                              *
 281      *                                                                         *
 282      **************************************************************************/
 283 
 284     /**
 285      * Returns the items to be displayed in the ChoiceBox when it is showing.

 286      */
 287     public ObservableList<T> getItems() {
 288         return items;
 289     }
 290 
 291     /** {@inheritDoc} */
 292     @Override public void startEdit() {
 293         if (! isEditable() || ! getTreeView().isEditable()) {
 294             return;
 295         }
 296 
 297         TreeItem<T> treeItem = getTreeItem();
 298         if (treeItem == null) {
 299             return;
 300         }
 301 
 302         if (choiceBox == null) {
 303             choiceBox = createChoiceBox(this, items, converterProperty());
 304         }
 305         if (hbox == null) {




  53  * @param <T> The type of the TreeItems contained within the TreeView.
  54  * @since JavaFX 2.2
  55  */
  56 public class ChoiceBoxTreeCell<T> extends DefaultTreeCell<T> {
  57 
  58     /***************************************************************************
  59      *                                                                         *
  60      * Static cell factories                                                   *
  61      *                                                                         *
  62      **************************************************************************/
  63 
  64     /**
  65      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
  66      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
  67      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
  68      * default, stretch to fill the entire tree cell.
  69      *
  70      * @param <T> The type of the elements contained within the TreeView.
  71      * @param items Zero or more items that will be shown to the user when the
  72      *      {@link ChoiceBox} menu is showing. These items must be of the same
  73      *      type as the {@literal TreeView<T>}, such that upon selection, they replace the
  74      *      existing value in the TreeItem {@link TreeItem#valueProperty() value}
  75      *      property.
  76      * @return A {@link Callback} that will return a TreeCell that is able to
  77      *      work on the type of element contained within the TreeView.
  78      */
  79     @SafeVarargs
  80     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(T... items) {
  81         return forTreeView(FXCollections.observableArrayList(items));
  82     }
  83 
  84     /**
  85      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
  86      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
  87      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
  88      * default, stretch to fill the entire tree cell, excluding the space
  89      * allocated to the tree cell indentation and disclosure node (i.e. the
  90      * arrow).
  91      *
  92      * @param <T> The type of the {@link TreeItem} elements contained within the
  93      *      TreeView.


  99      *      {@link TreeView#editingItemProperty()}.
 100      * @return A {@link Callback} that will return a TreeCell that is able to
 101      *      work on the type of element contained within the TreeView.
 102      */
 103     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(
 104             final ObservableList<T> items) {
 105         return forTreeView(null, items);
 106     }
 107 
 108     /**
 109      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
 110      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
 111      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
 112      * default, stretch to fill the entire tree cell.
 113      *
 114      * @param <T> The type of the elements contained within the TreeView.
 115      * @param converter A {@link StringConverter} to convert the given item (of type T)
 116      *      to a String for displaying to the user.
 117      * @param items Zero or more items that will be shown to the user when the
 118      *      {@link ChoiceBox} menu is showing. These items must be of the same
 119      *      type as the {@literal TreeView<T>}, such that upon selection, they replace the
 120      *      existing value in the TreeItem {@link TreeItem#valueProperty() value}
 121      *      property.
 122      * @return A {@link Callback} that will return a TreeCell that is able to
 123      *      work on the type of element contained within the TreeView.
 124      */
 125     @SafeVarargs
 126     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(
 127             final StringConverter<T> converter,
 128             final T... items) {
 129         return forTreeView(converter, FXCollections.observableArrayList(items));
 130     }
 131 
 132     /**
 133      * Creates a ChoiceBox cell factory for use in {@link TreeView} controls. By
 134      * default, the ChoiceBoxCell is rendered as a {@link Label} when not being
 135      * edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
 136      * default, stretch to fill the entire tree cell.
 137      *
 138      * @param <T> The type of the elements contained within the TreeView.
 139      * @param converter A {@link StringConverter} to convert the given item (of type T)


 237     public ChoiceBoxTreeCell(StringConverter<T> converter, ObservableList<T> items) {
 238         this.getStyleClass().add("choice-box-tree-cell");
 239         this.items = items;
 240         setConverter(converter != null ? converter : CellUtils.<T>defaultStringConverter());
 241     }
 242 
 243 
 244 
 245     /***************************************************************************
 246      *                                                                         *
 247      * Properties                                                              *
 248      *                                                                         *
 249      **************************************************************************/
 250 
 251     // --- converter
 252     private ObjectProperty<StringConverter<T>> converter =
 253             new SimpleObjectProperty<StringConverter<T>>(this, "converter");
 254 
 255     /**
 256      * The {@link StringConverter} property.
 257      * @return the {@link StringConverter} property
 258      */
 259     public final ObjectProperty<StringConverter<T>> converterProperty() {
 260         return converter;
 261     }
 262 
 263     /**
 264      * Sets the {@link StringConverter} to be used in this cell.
 265      * @param value the {@link StringConverter} to be used in this cell
 266      */
 267     public final void setConverter(StringConverter<T> value) {
 268         converterProperty().set(value);
 269     }
 270 
 271     /**
 272      * Returns the {@link StringConverter} used in this cell.
 273      * @return the {@link StringConverter} used in this cell
 274      */
 275     public final StringConverter<T> getConverter() {
 276         return converterProperty().get();
 277     }
 278 
 279 
 280 
 281     /***************************************************************************
 282      *                                                                         *
 283      * Public API                                                              *
 284      *                                                                         *
 285      **************************************************************************/
 286 
 287     /**
 288      * Returns the items to be displayed in the ChoiceBox when it is showing.
 289      * @return the items to be displayed in the ChoiceBox when it is showing
 290      */
 291     public ObservableList<T> getItems() {
 292         return items;
 293     }
 294 
 295     /** {@inheritDoc} */
 296     @Override public void startEdit() {
 297         if (! isEditable() || ! getTreeView().isEditable()) {
 298             return;
 299         }
 300 
 301         TreeItem<T> treeItem = getTreeItem();
 302         if (treeItem == null) {
 303             return;
 304         }
 305 
 306         if (choiceBox == null) {
 307             choiceBox = createChoiceBox(this, items, converterProperty());
 308         }
 309         if (hbox == null) {


< prev index next >