< prev index next >

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

Print this page




  66      *
  67      * @return A {@link Callback} that can be inserted into the
  68      *      {@link TreeView#cellFactoryProperty() cell factory property} of a
  69      *      TreeView, that enables textual editing of the content.
  70      */
  71     public static Callback<TreeView<String>, TreeCell<String>> forTreeView() {
  72         return forTreeView(new DefaultStringConverter());
  73     }
  74 
  75     /**
  76      * Provides a {@link TextField} that allows editing of the cell content when
  77      * the cell is double-clicked, or when
  78      * {@link TreeView#edit(javafx.scene.control.TreeItem)} is called. This
  79      * method will work on any {@link TreeView} instance,
  80      * regardless of its generic type. However, to enable this, a
  81      * {@link StringConverter} must be provided that will convert the given String
  82      * (from what the user typed in) into an instance of type T. This item will
  83      * then be passed along to the {@link TreeView#onEditCommitProperty()}
  84      * callback.
  85      *

  86      * @param converter A {@link StringConverter} that can convert the given String
  87      *      (from what the user typed in) into an instance of type T.
  88      * @return A {@link Callback} that can be inserted into the
  89      *      {@link TreeView#cellFactoryProperty() cell factory property} of a
  90      *      TreeView, that enables textual editing of the content.
  91      */
  92     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(
  93             final StringConverter<T> converter) {
  94         return list -> new TextFieldTreeCell<T>(converter);
  95     }
  96 
  97 
  98 
  99     /***************************************************************************
 100      *                                                                         *
 101      * Fields                                                                  *
 102      *                                                                         *
 103      **************************************************************************/
 104 
 105     private TextField textField;


 139      */
 140     public TextFieldTreeCell(StringConverter<T> converter) {
 141         this.getStyleClass().add("text-field-tree-cell");
 142         setConverter(converter);
 143     }
 144 
 145 
 146 
 147     /***************************************************************************
 148      *                                                                         *
 149      * Properties                                                              *
 150      *                                                                         *
 151      **************************************************************************/
 152 
 153     // --- converter
 154     private ObjectProperty<StringConverter<T>> converter =
 155             new SimpleObjectProperty<StringConverter<T>>(this, "converter");
 156 
 157     /**
 158      * The {@link StringConverter} property.

 159      */
 160     public final ObjectProperty<StringConverter<T>> converterProperty() {
 161         return converter;
 162     }
 163 
 164     /**
 165      * Sets the {@link StringConverter} to be used in this cell.

 166      */
 167     public final void setConverter(StringConverter<T> value) {
 168         converterProperty().set(value);
 169     }
 170 
 171     /**
 172      * Returns the {@link StringConverter} used in this cell.

 173      */
 174     public final StringConverter<T> getConverter() {
 175         return converterProperty().get();
 176     }
 177 
 178 
 179 
 180     /***************************************************************************
 181      *                                                                         *
 182      * Public API                                                              *
 183      *                                                                         *
 184      **************************************************************************/
 185 
 186     /** {@inheritDoc} */
 187     @Override public void startEdit() {
 188         if (! isEditable() || ! getTreeView().isEditable()) {
 189             return;
 190         }
 191         super.startEdit();
 192 




  66      *
  67      * @return A {@link Callback} that can be inserted into the
  68      *      {@link TreeView#cellFactoryProperty() cell factory property} of a
  69      *      TreeView, that enables textual editing of the content.
  70      */
  71     public static Callback<TreeView<String>, TreeCell<String>> forTreeView() {
  72         return forTreeView(new DefaultStringConverter());
  73     }
  74 
  75     /**
  76      * Provides a {@link TextField} that allows editing of the cell content when
  77      * the cell is double-clicked, or when
  78      * {@link TreeView#edit(javafx.scene.control.TreeItem)} is called. This
  79      * method will work on any {@link TreeView} instance,
  80      * regardless of its generic type. However, to enable this, a
  81      * {@link StringConverter} must be provided that will convert the given String
  82      * (from what the user typed in) into an instance of type T. This item will
  83      * then be passed along to the {@link TreeView#onEditCommitProperty()}
  84      * callback.
  85      *
  86      * @param <T> The type of the elements contained within the TreeView
  87      * @param converter A {@link StringConverter} that can convert the given String
  88      *      (from what the user typed in) into an instance of type T.
  89      * @return A {@link Callback} that can be inserted into the
  90      *      {@link TreeView#cellFactoryProperty() cell factory property} of a
  91      *      TreeView, that enables textual editing of the content.
  92      */
  93     public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView(
  94             final StringConverter<T> converter) {
  95         return list -> new TextFieldTreeCell<T>(converter);
  96     }
  97 
  98 
  99 
 100     /***************************************************************************
 101      *                                                                         *
 102      * Fields                                                                  *
 103      *                                                                         *
 104      **************************************************************************/
 105 
 106     private TextField textField;


 140      */
 141     public TextFieldTreeCell(StringConverter<T> converter) {
 142         this.getStyleClass().add("text-field-tree-cell");
 143         setConverter(converter);
 144     }
 145 
 146 
 147 
 148     /***************************************************************************
 149      *                                                                         *
 150      * Properties                                                              *
 151      *                                                                         *
 152      **************************************************************************/
 153 
 154     // --- converter
 155     private ObjectProperty<StringConverter<T>> converter =
 156             new SimpleObjectProperty<StringConverter<T>>(this, "converter");
 157 
 158     /**
 159      * The {@link StringConverter} property.
 160      * @return the {@link StringConverter} property
 161      */
 162     public final ObjectProperty<StringConverter<T>> converterProperty() {
 163         return converter;
 164     }
 165 
 166     /**
 167      * Sets the {@link StringConverter} to be used in this cell.
 168      * @param value the {@link StringConverter} to be used in this cell
 169      */
 170     public final void setConverter(StringConverter<T> value) {
 171         converterProperty().set(value);
 172     }
 173 
 174     /**
 175      * Returns the {@link StringConverter} used in this cell.
 176      * @return the {@link StringConverter} used in this cell
 177      */
 178     public final StringConverter<T> getConverter() {
 179         return converterProperty().get();
 180     }
 181 
 182 
 183 
 184     /***************************************************************************
 185      *                                                                         *
 186      * Public API                                                              *
 187      *                                                                         *
 188      **************************************************************************/
 189 
 190     /** {@inheritDoc} */
 191     @Override public void startEdit() {
 192         if (! isEditable() || ! getTreeView().isEditable()) {
 193             return;
 194         }
 195         super.startEdit();
 196 


< prev index next >