< prev index next >

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

Print this page




  23  * questions.
  24  */
  25 
  26 package javafx.scene.control.cell;
  27 
  28 import javafx.beans.property.ObjectProperty;
  29 import javafx.beans.property.SimpleObjectProperty;
  30 import javafx.scene.control.*;
  31 import javafx.util.Callback;
  32 import javafx.util.StringConverter;
  33 import javafx.util.converter.DefaultStringConverter;
  34 
  35 /**
  36  * A class containing a {@link TableCell} implementation that draws a
  37  * {@link TextField} node inside the cell.
  38  *
  39  * <p>By default, the TextFieldTableCell is rendered as a {@link Label} when not
  40  * being edited, and as a TextField when in editing mode. The TextField will, by
  41  * default, stretch to fill the entire table cell.
  42  *

  43  * @param <T> The type of the elements contained within the TableColumn.
  44  * @since JavaFX 2.2
  45  */
  46 public class TextFieldTableCell<S,T> extends TableCell<S,T> {
  47 
  48     /***************************************************************************
  49      *                                                                         *
  50      * Static cell factories                                                   *
  51      *                                                                         *
  52      **************************************************************************/
  53 
  54     /**
  55      * Provides a {@link TextField} that allows editing of the cell content when
  56      * the cell is double-clicked, or when
  57      * {@link TableView#edit(int, javafx.scene.control.TableColumn)} is called.
  58      * This method will only  work on {@link TableColumn} instances which are of
  59      * type String.
  60      *

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


  79      * @param converter A {@link StringConverter} that can convert the given String
  80      *      (from what the user typed in) into an instance of type T.
  81      * @return A {@link Callback} that can be inserted into the
  82      *      {@link TableColumn#cellFactoryProperty() cell factory property} of a
  83      *      TableColumn, that enables textual editing of the content.
  84      */
  85     public static <S,T> Callback<TableColumn<S,T>, TableCell<S,T>> forTableColumn(
  86             final StringConverter<T> converter) {
  87         return list -> new TextFieldTableCell<S,T>(converter);
  88     }
  89 
  90 
  91     /***************************************************************************
  92      *                                                                         *
  93      * Fields                                                                  *
  94      *                                                                         *
  95      **************************************************************************/
  96 
  97     private TextField textField;
  98 


 130      */
 131     public TextFieldTableCell(StringConverter<T> converter) {
 132         this.getStyleClass().add("text-field-table-cell");
 133         setConverter(converter);
 134     }
 135 
 136 
 137 
 138     /***************************************************************************
 139      *                                                                         *
 140      * Properties                                                              *
 141      *                                                                         *
 142      **************************************************************************/
 143 
 144     // --- converter
 145     private ObjectProperty<StringConverter<T>> converter =
 146             new SimpleObjectProperty<StringConverter<T>>(this, "converter");
 147 
 148     /**
 149      * The {@link StringConverter} property.

 150      */
 151     public final ObjectProperty<StringConverter<T>> converterProperty() {
 152         return converter;
 153     }
 154 
 155     /**
 156      * Sets the {@link StringConverter} to be used in this cell.

 157      */
 158     public final void setConverter(StringConverter<T> value) {
 159         converterProperty().set(value);
 160     }
 161 
 162     /**
 163      * Returns the {@link StringConverter} used in this cell.

 164      */
 165     public final StringConverter<T> getConverter() {
 166         return converterProperty().get();
 167     }
 168 
 169 
 170 
 171     /***************************************************************************
 172      *                                                                         *
 173      * Public API                                                              *
 174      *                                                                         *
 175      **************************************************************************/
 176 
 177     /** {@inheritDoc} */
 178     @Override public void startEdit() {
 179         if (! isEditable()
 180                 || ! getTableView().isEditable()
 181                 || ! getTableColumn().isEditable()) {
 182             return;
 183         }




  23  * questions.
  24  */
  25 
  26 package javafx.scene.control.cell;
  27 
  28 import javafx.beans.property.ObjectProperty;
  29 import javafx.beans.property.SimpleObjectProperty;
  30 import javafx.scene.control.*;
  31 import javafx.util.Callback;
  32 import javafx.util.StringConverter;
  33 import javafx.util.converter.DefaultStringConverter;
  34 
  35 /**
  36  * A class containing a {@link TableCell} implementation that draws a
  37  * {@link TextField} node inside the cell.
  38  *
  39  * <p>By default, the TextFieldTableCell is rendered as a {@link Label} when not
  40  * being edited, and as a TextField when in editing mode. The TextField will, by
  41  * default, stretch to fill the entire table cell.
  42  *
  43  * @param <S> The type of the TableView generic type
  44  * @param <T> The type of the elements contained within the TableColumn.
  45  * @since JavaFX 2.2
  46  */
  47 public class TextFieldTableCell<S,T> extends TableCell<S,T> {
  48 
  49     /***************************************************************************
  50      *                                                                         *
  51      * Static cell factories                                                   *
  52      *                                                                         *
  53      **************************************************************************/
  54 
  55     /**
  56      * Provides a {@link TextField} that allows editing of the cell content when
  57      * the cell is double-clicked, or when
  58      * {@link TableView#edit(int, javafx.scene.control.TableColumn)} is called.
  59      * This method will only  work on {@link TableColumn} instances which are of
  60      * type String.
  61      *
  62      * @param <S> The type of the TableView generic type
  63      * @return A {@link Callback} that can be inserted into the
  64      *      {@link TableColumn#cellFactoryProperty() cell factory property} of a
  65      *      TableColumn, that enables textual editing of the content.
  66      */
  67     public static <S> Callback<TableColumn<S,String>, TableCell<S,String>> forTableColumn() {
  68         return forTableColumn(new DefaultStringConverter());
  69     }
  70 
  71     /**
  72      * Provides a {@link TextField} that allows editing of the cell content when
  73      * the cell is double-clicked, or when
  74      * {@link TableView#edit(int, javafx.scene.control.TableColumn) } is called.
  75      * This method will work  on any {@link TableColumn} instance, regardless of
  76      * its generic type. However, to enable this, a {@link StringConverter} must
  77      * be provided that will convert the given String (from what the user typed
  78      * in) into an instance of type T. This item will then be passed along to the
  79      * {@link TableColumn#onEditCommitProperty()} callback.
  80      *
  81      * @param <S> The type of the TableView generic type
  82      * @param <T> The type of the elements contained within the TableColumn
  83      * @param converter A {@link StringConverter} that can convert the given String
  84      *      (from what the user typed in) into an instance of type T.
  85      * @return A {@link Callback} that can be inserted into the
  86      *      {@link TableColumn#cellFactoryProperty() cell factory property} of a
  87      *      TableColumn, that enables textual editing of the content.
  88      */
  89     public static <S,T> Callback<TableColumn<S,T>, TableCell<S,T>> forTableColumn(
  90             final StringConverter<T> converter) {
  91         return list -> new TextFieldTableCell<S,T>(converter);
  92     }
  93 
  94 
  95     /***************************************************************************
  96      *                                                                         *
  97      * Fields                                                                  *
  98      *                                                                         *
  99      **************************************************************************/
 100 
 101     private TextField textField;
 102 


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


< prev index next >