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.cell; 27 28 import javafx.beans.property.ObjectProperty; 29 import javafx.beans.property.SimpleObjectProperty; 30 import javafx.scene.control.TextField; 31 import javafx.scene.control.TreeTableCell; 32 import javafx.scene.control.TreeTableColumn; 33 import javafx.util.Callback; 34 import javafx.util.StringConverter; 35 import javafx.util.converter.DefaultStringConverter; 36 37 /** 38 * A class containing a {@link TableCell} implementation that draws a 39 * {@link TextField} node inside the cell. 40 * 41 * <p>By default, the TextFieldTableCell is rendered as a {@link Label} when not 42 * being edited, and as a TextField when in editing mode. The TextField will, by 43 * default, stretch to fill the entire table cell. 44 * 45 * @param <T> The type of the elements contained within the TreeTableColumn. 46 * @since JavaFX 8.0 47 */ 48 public class TextFieldTreeTableCell<S,T> extends TreeTableCell<S,T> { 49 50 /*************************************************************************** 51 * * 52 * Static cell factories * 53 * * 54 **************************************************************************/ 55 56 /** 57 * Provides a {@link TextField} that allows editing of the cell content when 58 * the cell is double-clicked, or when 59 * {@link javafx.scene.control.TreeTableView#edit(int, javafx.scene.control.TreeTableColumn)} is called. 60 * This method will only work on {@link TreeTableColumn} instances which are of 61 * type String. 62 * 63 * @return A {@link Callback} that can be inserted into the 64 * {@link TreeTableColumn#cellFactoryProperty() cell factory property} of a 65 * TreeTableColumn, that enables textual editing of the content. 66 */ 67 public static <S> Callback<TreeTableColumn<S,String>, TreeTableCell<S,String>> forTreeTableColumn() { 68 return forTreeTableColumn(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 javafx.scene.control.TreeTableView#edit(int, javafx.scene.control.TreeTableColumn) } is called. 75 * This method will work on any {@link TreeTableColumn} 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 TreeTableColumn#onEditCommitProperty()} callback. 80 * 81 * @param converter A {@link StringConverter} that can convert the given String 82 * (from what the user typed in) into an instance of type T. 83 * @return A {@link Callback} that can be inserted into the 84 * {@link TreeTableColumn#cellFactoryProperty() cell factory property} of a 85 * TreeTableColumn, that enables textual editing of the content. 86 */ 87 public static <S,T> Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>> forTreeTableColumn( 88 final StringConverter<T> converter) { 89 return list -> new TextFieldTreeTableCell<S,T>(converter); 90 } 91 92 93 /*************************************************************************** 94 * * 95 * Fields * 96 * * 97 **************************************************************************/ 98 99 private TextField textField; 100 132 */ 133 public TextFieldTreeTableCell(StringConverter<T> converter) { 134 this.getStyleClass().add("text-field-tree-table-cell"); 135 setConverter(converter); 136 } 137 138 139 140 /*************************************************************************** 141 * * 142 * Properties * 143 * * 144 **************************************************************************/ 145 146 // --- converter 147 private ObjectProperty<StringConverter<T>> converter = 148 new SimpleObjectProperty<StringConverter<T>>(this, "converter"); 149 150 /** 151 * The {@link StringConverter} property. 152 */ 153 public final ObjectProperty<StringConverter<T>> converterProperty() { 154 return converter; 155 } 156 157 /** 158 * Sets the {@link StringConverter} to be used in this cell. 159 */ 160 public final void setConverter(StringConverter<T> value) { 161 converterProperty().set(value); 162 } 163 164 /** 165 * Returns the {@link StringConverter} used in this cell. 166 */ 167 public final StringConverter<T> getConverter() { 168 return converterProperty().get(); 169 } 170 171 172 173 /*************************************************************************** 174 * * 175 * Public API * 176 * * 177 **************************************************************************/ 178 179 /** {@inheritDoc} */ 180 @Override public void startEdit() { 181 if (! isEditable() 182 || ! getTreeTableView().isEditable() 183 || ! getTableColumn().isEditable()) { 184 return; 185 } | 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.cell; 27 28 import javafx.beans.property.ObjectProperty; 29 import javafx.beans.property.SimpleObjectProperty; 30 import javafx.scene.control.TextField; 31 import javafx.scene.control.TreeTableCell; 32 import javafx.scene.control.TreeTableColumn; 33 import javafx.util.Callback; 34 import javafx.util.StringConverter; 35 import javafx.util.converter.DefaultStringConverter; 36 37 /** 38 * A class containing a {@link javafx.scene.control.TableCell} implementation that draws a 39 * {@link TextField} node inside the cell. 40 * 41 * <p>By default, the TextFieldTableCell is rendered as a {@link javafx.scene.control.Label} when not 42 * being edited, and as a TextField when in editing mode. The TextField will, by 43 * default, stretch to fill the entire table cell. 44 * 45 * @param <S> The type of the TableView generic type 46 * @param <T> The type of the elements contained within the TreeTableColumn. 47 * @since JavaFX 8.0 48 */ 49 public class TextFieldTreeTableCell<S,T> extends TreeTableCell<S,T> { 50 51 /*************************************************************************** 52 * * 53 * Static cell factories * 54 * * 55 **************************************************************************/ 56 57 /** 58 * Provides a {@link TextField} that allows editing of the cell content when 59 * the cell is double-clicked, or when 60 * {@link javafx.scene.control.TreeTableView#edit(int, javafx.scene.control.TreeTableColumn)} is called. 61 * This method will only work on {@link TreeTableColumn} instances which are of 62 * type String. 63 * 64 * @param <S> The type of the TableView generic type 65 * @return A {@link Callback} that can be inserted into the 66 * {@link TreeTableColumn#cellFactoryProperty() cell factory property} of a 67 * TreeTableColumn, that enables textual editing of the content. 68 */ 69 public static <S> Callback<TreeTableColumn<S,String>, TreeTableCell<S,String>> forTreeTableColumn() { 70 return forTreeTableColumn(new DefaultStringConverter()); 71 } 72 73 /** 74 * Provides a {@link TextField} that allows editing of the cell content when 75 * the cell is double-clicked, or when 76 * {@link javafx.scene.control.TreeTableView#edit(int, javafx.scene.control.TreeTableColumn) } is called. 77 * This method will work on any {@link TreeTableColumn} instance, regardless of 78 * its generic type. However, to enable this, a {@link StringConverter} must 79 * be provided that will convert the given String (from what the user typed 80 * in) into an instance of type T. This item will then be passed along to the 81 * {@link TreeTableColumn#onEditCommitProperty()} callback. 82 * 83 * @param <S> The type of the TableView generic type 84 * @param <T> The type of the elements contained within the TreeTableColumn 85 * @param converter A {@link StringConverter} that can convert the given String 86 * (from what the user typed in) into an instance of type T. 87 * @return A {@link Callback} that can be inserted into the 88 * {@link TreeTableColumn#cellFactoryProperty() cell factory property} of a 89 * TreeTableColumn, that enables textual editing of the content. 90 */ 91 public static <S,T> Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>> forTreeTableColumn( 92 final StringConverter<T> converter) { 93 return list -> new TextFieldTreeTableCell<S,T>(converter); 94 } 95 96 97 /*************************************************************************** 98 * * 99 * Fields * 100 * * 101 **************************************************************************/ 102 103 private TextField textField; 104 136 */ 137 public TextFieldTreeTableCell(StringConverter<T> converter) { 138 this.getStyleClass().add("text-field-tree-table-cell"); 139 setConverter(converter); 140 } 141 142 143 144 /*************************************************************************** 145 * * 146 * Properties * 147 * * 148 **************************************************************************/ 149 150 // --- converter 151 private ObjectProperty<StringConverter<T>> converter = 152 new SimpleObjectProperty<StringConverter<T>>(this, "converter"); 153 154 /** 155 * The {@link StringConverter} property. 156 * @return the {@link StringConverter} property 157 */ 158 public final ObjectProperty<StringConverter<T>> converterProperty() { 159 return converter; 160 } 161 162 /** 163 * Sets the {@link StringConverter} to be used in this cell. 164 * @param value the {@link StringConverter} to be used in this cell 165 */ 166 public final void setConverter(StringConverter<T> value) { 167 converterProperty().set(value); 168 } 169 170 /** 171 * Returns the {@link StringConverter} used in this cell. 172 * @return 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() 189 || ! getTreeTableView().isEditable() 190 || ! getTableColumn().isEditable()) { 191 return; 192 } |