60 * This method will only work on {@link ListView} instances which are of
61 * type String.
62 *
63 * @return A {@link Callback} that can be inserted into the
64 * {@link ListView#cellFactoryProperty() cell factory property} of a
65 * ListView, that enables textual editing of the content.
66 */
67 public static Callback<ListView<String>, ListCell<String>> forListView() {
68 return forListView(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 {@link ListView#edit(int)} is called.
74 * This method will work on any ListView instance, regardless of its generic
75 * type. However, to enable this, a {@link StringConverter} must be provided
76 * that will convert the given String (from what the user typed in) into an
77 * instance of type T. This item will then be passed along to the
78 * {@link ListView#onEditCommitProperty()} callback.
79 *
80 * @param converter A {@link StringConverter} that can convert the given String
81 * (from what the user typed in) into an instance of type T.
82 * @return A {@link Callback} that can be inserted into the
83 * {@link ListView#cellFactoryProperty() cell factory property} of a
84 * ListView, that enables textual editing of the content.
85 */
86 public static <T> Callback<ListView<T>, ListCell<T>> forListView(final StringConverter<T> converter) {
87 return list -> new TextFieldListCell<T>(converter);
88 }
89
90
91
92 /***************************************************************************
93 * *
94 * Fields *
95 * *
96 **************************************************************************/
97 private TextField textField;
98
99
130 */
131 public TextFieldListCell(StringConverter<T> converter) {
132 this.getStyleClass().add("text-field-list-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 * Public API *
173 * *
174 **************************************************************************/
175
176 /** {@inheritDoc} */
177 @Override public void startEdit() {
178 if (! isEditable() || ! getListView().isEditable()) {
179 return;
180 }
181 super.startEdit();
182
183 if (isEditing()) {
|
60 * This method will only work on {@link ListView} instances which are of
61 * type String.
62 *
63 * @return A {@link Callback} that can be inserted into the
64 * {@link ListView#cellFactoryProperty() cell factory property} of a
65 * ListView, that enables textual editing of the content.
66 */
67 public static Callback<ListView<String>, ListCell<String>> forListView() {
68 return forListView(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 {@link ListView#edit(int)} is called.
74 * This method will work on any ListView instance, regardless of its generic
75 * type. However, to enable this, a {@link StringConverter} must be provided
76 * that will convert the given String (from what the user typed in) into an
77 * instance of type T. This item will then be passed along to the
78 * {@link ListView#onEditCommitProperty()} callback.
79 *
80 * @param <T> The type of the item contained within the Cell
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 ListView#cellFactoryProperty() cell factory property} of a
85 * ListView, that enables textual editing of the content.
86 */
87 public static <T> Callback<ListView<T>, ListCell<T>> forListView(final StringConverter<T> converter) {
88 return list -> new TextFieldListCell<T>(converter);
89 }
90
91
92
93 /***************************************************************************
94 * *
95 * Fields *
96 * *
97 **************************************************************************/
98 private TextField textField;
99
100
131 */
132 public TextFieldListCell(StringConverter<T> converter) {
133 this.getStyleClass().add("text-field-list-cell");
134 setConverter(converter);
135 }
136
137
138
139 /***************************************************************************
140 * *
141 * Properties *
142 * *
143 **************************************************************************/
144
145 // --- converter
146 private ObjectProperty<StringConverter<T>> converter =
147 new SimpleObjectProperty<StringConverter<T>>(this, "converter");
148
149 /**
150 * The {@link StringConverter} property.
151 * @return 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 * @param value the {@link StringConverter} to be used in this cell
160 */
161 public final void setConverter(StringConverter<T> value) {
162 converterProperty().set(value);
163 }
164
165 /**
166 * Returns the {@link StringConverter} used in this cell.
167 * @return the {@link StringConverter} used in this cell
168 */
169 public final StringConverter<T> getConverter() {
170 return converterProperty().get();
171 }
172
173
174 /***************************************************************************
175 * *
176 * Public API *
177 * *
178 **************************************************************************/
179
180 /** {@inheritDoc} */
181 @Override public void startEdit() {
182 if (! isEditable() || ! getListView().isEditable()) {
183 return;
184 }
185 super.startEdit();
186
187 if (isEditing()) {
|