// Using div because shadow root causes otherwise styling issues
61 | implements
62 | HasStyle,
63 | HasSize
64 | {
65 | /*
66 | * UI-Components
67 | */
68 | protected final Button btnEdit = new Button(VaadinIcon.PENCIL.create());
69 | protected final Button btnSave = new Button(VaadinIcon.CHECK.create());
70 | protected final Button btnClose = new Button(VaadinIcon.CLOSE.create());
71 | protected final Span label = new Span();
72 |
73 | protected final C editor;
74 |
75 | /*
76 | * Suppliers / Configuration
77 | */
78 | protected ItemLabelGenerator
nativeLabelGenerator;
79 | protected String emptyLabelValue = "";
80 |
81 | protected AbstractEditableLabel(final C editor, final Consumer additionalInitActions)
82 | {
83 | super(editor.getEmptyValue());
84 |
85 | this.editor = editor;
86 |
87 | this.initUI();
88 | this.registerListeners();
89 |
90 | if(additionalInitActions != null)
91 | {
92 | additionalInitActions.accept(this.self());
93 | }
94 |
95 | // initial UI state
96 | this.disableEditMode();
97 | this.withLabelGenerator(Object::toString);
98 | }
99 |
100 | protected void initUI()
101 | {
102 | this.addClassName(EditableLabelStyles.CONTAINER);
103 |
104 | this.label.addClassName(EditableLabelStyles.LABEL);
105 |
106 | this.btnEdit.addClassName(EditableLabelStyles.EDIT_BUTTON);
107 |
108 | this.btnSave.addClickShortcut(Key.ENTER);
109 |
110 | this.btnClose.addClickShortcut(Key.ESCAPE);
111 |
112 | Stream.of(this.btnEdit, this.btnSave, this.btnClose)
113 | .forEach(btn -> {
114 | btn.addClassName(EditableLabelStyles.BUTTON);
115 | btn.addThemeVariants(ButtonVariant.LUMO_SMALL, ButtonVariant.LUMO_TERTIARY);
116 | });
117 |
118 | this.getEditor().addClassName(EditableLabelStyles.EDITOR);
119 | this.getEditor().setWidthFull();
120 |
121 | this.getContent().add(this.label, this.editor, this.btnEdit, this.btnSave, this.btnClose);
122 | }
123 |
124 | // region Listeners
125 |
126 | protected void registerListeners()
127 | {
128 | this.btnEdit.addClickListener(this::onEdit);
129 | this.btnSave.addClickListener(this::onSave);
130 | this.btnClose.addClickListener(this::onClose);
131 | }
132 |
133 | protected void onEdit(final ClickEvent ev)
134 | {
135 | this.getEditor().setValue(this.getValue());
136 |
137 | this.enableEditMode(ev.isFromClient());
138 | }
139 |
140 | protected void onSave(final ClickEvent ev)
141 | {
142 | this.updateValue(this.getEditor().getValue(), ev.isFromClient());
143 |
144 | this.disableEditMode(ev.isFromClient());
145 | }
146 |
147 | protected void onClose(final ClickEvent ev)
148 | {
149 | this.disableEditMode(ev.isFromClient());
150 | }
151 |
152 |
153 | // endregion
154 |
155 | // region Value Management
156 |
157 | /**
158 | * @see #setValue(Object)
159 | */
160 | public S withValue(final V value)
161 | {
162 | this.setValue(value);
163 | return this.self();
164 | }
165 |
166 | /**
167 | * Updates the underlying values (if the newValues doesn't equals the oldValue)
168 | *
169 | * @implNote
170 | * This is a "workaround" for
171 | * vaadin/flow#11392
172 | * The following behaviors may be unexpected:
173 | *
174 | * The {@link ValueChangeEvent} is fired before the UI is updated
175 | * No internal data management like in {@link AbstractFieldSupport}
176 | *
177 | */
178 | protected void updateValue(final V newValue, final boolean isFromClient)
179 | {
180 | final V oldValue = this.getValue();
181 | this.setModelValue(newValue, isFromClient);
182 |
183 | if(!this.valueEquals(oldValue, newValue))
184 | {
185 | this.setPresentationValue(newValue);
186 | }
187 | }
188 |
189 | @Override
190 | protected void setPresentationValue(final V newPresentationValue)
191 | {
192 | this.updateLabelText(newPresentationValue);
193 | }
194 |
195 | /**
196 | * Updates the label text based on the value to display.
197 | *
198 | * This value is rendered using the {@link #nativeLabelGenerator}.
199 | *
200 | * If the value is null or blank/empty the {@link #btnEdit} will always be shown
201 | * and not just when hovering the label.
202 | *
203 | * @param value The value to display
204 | */
205 | protected void updateLabelText(final V value)
206 | {
207 | final String labelText = this.nativeLabelGenerator.apply(value);
208 |
209 | // The edit button would not be displayed if nothing is visible
210 | this.btnEdit.setClassName(
211 | EditableLabelStyles.EDIT_BUTTON_ALWAYS_VISIBLE,
212 | labelText == null || labelText.isBlank());
213 |
214 | this.label.setText(labelText);
215 | }
216 |
217 | // endregion
218 |
219 | // region EditMode
220 | /**
221 | * @see #setEditMode(boolean)
222 | */
223 | public void enableEditMode()
224 | {
225 | this.enableEditMode(false);
226 | }
227 |
228 | protected void enableEditMode(final boolean isFromClient)
229 | {
230 | this.setEditMode(true, isFromClient);
231 | }
232 |
233 | /**
234 | * @see #setEditMode(boolean)
235 | */
236 | public void disableEditMode()
237 | {
238 | this.disableEditMode(false);
239 | }
240 |
241 | protected void disableEditMode(final boolean isFromClient)
242 | {
243 | this.setEditMode(false, isFromClient);
244 | }
245 |
246 | /**
247 | * Sets the editMode:
248 | *
249 | * true - Enables edit mode - displays the editor
250 | * false - Disables edit mode - displays the label
251 | *
252 | * @param enabled true
when in editMode otherwise false
253 | */
254 | public void setEditMode(final boolean enabled)
255 | {
256 | this.setEditMode(enabled, false);
257 | }
258 |
259 | protected void setEditMode(final boolean enabled, final boolean isFromClient)
260 | {
261 | if(this.isEditMode() == enabled || this.isReadOnly() && enabled)
262 | {
263 | return;
264 | }
265 |
266 | this.getEditor().setVisible(enabled);
267 | this.label.setVisible(!enabled);
268 | this.btnEdit.setVisible(!enabled);
269 | this.btnSave.setVisible(enabled);
270 | this.btnClose.setVisible(enabled);
271 |
272 | if(enabled && this.getEditor() instanceof Focusable>)
273 | {
274 | ((Focusable>)this.getEditor()).focus();
275 | }
276 |
277 | this.fireEvent(new EditModeChangedEvent<>(enabled, this.self(), isFromClient));
278 | }
279 |
280 | public boolean isEditMode()
281 | {
282 | return this.getEditor().isVisible();
283 | }
284 |
285 | @SuppressWarnings("unchecked")
286 | public Registration addEditModeChangedListener(final ComponentEventListener> listener)
287 | {
288 | return this.addListener(EditModeChangedEvent.class, (ComponentEventListener)listener);
289 | }
290 |
291 | // endregion
292 |
293 | // region withIcons
294 |
295 | /**
296 | * Changes the icon of the edit button. Default is {@link VaadinIcon#PENCIL}
297 | *
298 | * @param editIcon to show on the edit button
299 | * @return self
300 | */
301 | public S withEditIcon(final Component editIcon)
302 | {
303 | this.btnEdit.setIcon(editIcon);
304 | return this.self();
305 | }
306 |
307 | /**
308 | * Changes the icon of the save button. Default is {@link VaadinIcon#CHECK}
309 | *
310 | * @param saveIcon to show on the save button
311 | * @return self
312 | */
313 | public S withSaveIcon(final Component saveIcon)
314 | {
315 | this.btnSave.setIcon(saveIcon);
316 | return this.self();
317 | }
318 |
319 | /**
320 | * Changes the icon of the close button. Default is {@link VaadinIcon#CLOSE}
321 | *
322 | * @param closeIcon to show on the close button
323 | * @return self
324 | */
325 | public S withCloseIcon(final Component closeIcon)
326 | {
327 | this.btnClose.setIcon(closeIcon);
328 | return this.self();
329 | }
330 |
331 | // endregion
332 |
333 | // region LabelGenerator
334 |
335 | /**
336 | * Sets the label generator used for displaying the label.
337 | *
338 | * It's recommended to use {@link #withLabelGenerator(ItemLabelGenerator, Supplier)} or its variants
339 | * because they included null/empty-value checks.
340 | */
341 | public S withNativeLabelGenerator(final ItemLabelGenerator labelGenerator)
342 | {
343 | this.nativeLabelGenerator = Objects.requireNonNull(labelGenerator);
344 | this.updateLabelText(this.getValue());
345 | return this.self();
346 | }
347 |
348 | /**
349 | * Sets the label generator used for displaying the label.
350 | *
351 | * If the value is null or empty {@code emptyValue} is used.
352 | * @see #withNativeLabelGenerator(ItemLabelGenerator)
353 | */
354 | public S withLabelGenerator(final ItemLabelGenerator notEmptyLabelGenerator, final Supplier emptyValue)
355 | {
356 | return this.withNativeLabelGenerator(
357 | v -> v == null || this.valueEquals(v, this.getEmptyValue())
358 | ? emptyValue.get()
359 | : notEmptyLabelGenerator.apply(v));
360 | }
361 |
362 | /**
363 | * @see #withLabelGenerator(ItemLabelGenerator, Supplier)
364 | */
365 | public S withLabelGenerator(final ItemLabelGenerator notEmptyLabelGenerator, final String emptyValue)
366 | {
367 | Objects.requireNonNull(emptyValue);
368 | return this.withLabelGenerator(notEmptyLabelGenerator, () -> emptyValue);
369 | }
370 |
371 | /**
372 | * @see #withLabelGenerator(ItemLabelGenerator, Supplier)
373 | */
374 | public S withLabelGenerator(final ItemLabelGenerator notEmptyLabelGenerator)
375 | {
376 | return this.withLabelGenerator(notEmptyLabelGenerator, this.getEmptyLabelValue());
377 | }
378 |
379 | public String getEmptyLabelValue()
380 | {
381 | return this.emptyLabelValue;
382 | }
383 |
384 | /**
385 | * Set's the default value when the value to display is null or empty.
386 | * @see #withLabelGenerator(ItemLabelGenerator, Supplier)
387 | */
388 | public S withEmptyLabelValue(final String emptyLabelValue)
389 | {
390 | this.emptyLabelValue = Objects.requireNonNull(emptyLabelValue);
391 | return this.self();
392 | }
393 |
394 | //endregion
395 |
396 | /**
397 | * @return the component used to edit the value
398 | */
399 | public C getEditor()
400 | {
401 | return this.editor;
402 | }
403 |
404 | @Override
405 | public void setReadOnly(final boolean readOnly)
406 | {
407 | super.setReadOnly(readOnly);
408 |
409 | this.btnEdit.setEnabled(!readOnly);
410 | if(readOnly && this.isEditMode())
411 | {
412 | this.disableEditMode();
413 | }
414 | }
415 |
416 | @Override
417 | public void setRequiredIndicatorVisible(final boolean requiredIndicatorVisible)
418 | {
419 | super.setRequiredIndicatorVisible(requiredIndicatorVisible);
420 | this.getEditor().setRequiredIndicatorVisible(requiredIndicatorVisible);
421 | }
422 |
423 | @SuppressWarnings("unchecked")
424 | protected S self()
425 | {
426 | return (S)this;
427 | }
428 |
429 | protected static class EditModeChangedEvent
430 | , C extends Component & HasSize & HasStyle & HasValue, V>, V>
431 | extends ComponentEvent
432 | {
433 | protected final boolean editModeEnabled;
434 |
435 | public EditModeChangedEvent(final boolean editModeEnabled, final S source, final boolean fromClient)
436 | {
437 | super(source, fromClient);
438 | this.editModeEnabled = editModeEnabled;
439 | }
440 |
441 | public boolean isEditModeEnabled()
442 | {
443 | return this.editModeEnabled;
444 | }
445 | }
446 | }
447 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/EditableLabel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label;
17 |
18 | import java.util.function.Consumer;
19 |
20 | import com.vaadin.flow.component.Component;
21 | import com.vaadin.flow.component.HasSize;
22 | import com.vaadin.flow.component.HasStyle;
23 | import com.vaadin.flow.component.HasValue;
24 |
25 |
26 | /**
27 | * The default simple implementation of {@link AbstractEditableLabel}.
28 | *
29 | * @param value type which is handled through this component
30 | * @param Vaadin-{@link Component} to edit the value
31 | *
32 | * @author AB
33 | * @author JR
34 | */
35 | public class EditableLabel, V>
36 | extends AbstractEditableLabel, C, V>
37 | {
38 | public EditableLabel(final C editor)
39 | {
40 | this(editor, null);
41 | }
42 |
43 | public EditableLabel(final C editor, final Consumer> additionalInitActions)
44 | {
45 | super(editor, additionalInitActions);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/EditableLabelStyles.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label;
17 |
18 | /**
19 | * Styles for the {@link AbstractEditableLabel}
20 | */
21 | public final class EditableLabelStyles
22 | {
23 | private EditableLabelStyles()
24 | {
25 | }
26 |
27 | public static final String LOCATION = "./styles/editableLabel.css";
28 |
29 | public static final String CONTAINER = "editable-label-container";
30 | public static final String BUTTON = "editable-label-button";
31 | public static final String EDIT_BUTTON = "editable-label-edit-button";
32 | public static final String EDIT_BUTTON_ALWAYS_VISIBLE = "editable-label-edit-button-always-visible";
33 | public static final String LABEL = "editable-label-label";
34 | public static final String EDITOR = "editable-label-editor";
35 | }
36 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/predefined/EditableLabelBigDecimalField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label.predefined;
17 |
18 | import java.math.BigDecimal;
19 | import java.text.NumberFormat;
20 | import java.util.function.Consumer;
21 |
22 | import com.vaadin.flow.component.textfield.BigDecimalField;
23 |
24 | import software.xdev.vaadin.editable_label.AbstractEditableLabel;
25 |
26 |
27 | /**
28 | * Offers a simple label which can be edited as a {@link BigDecimalField}.
29 | *
30 | * @author JR
31 | * @author AB
32 | */
33 | public class EditableLabelBigDecimalField
34 | extends AbstractEditableLabel
35 | {
36 | public EditableLabelBigDecimalField()
37 | {
38 | this(new BigDecimalField());
39 | }
40 |
41 | public EditableLabelBigDecimalField(final BigDecimalField editor)
42 | {
43 | this(editor, null);
44 | }
45 |
46 | public EditableLabelBigDecimalField(final Consumer additionalInitActions)
47 | {
48 | this(new BigDecimalField(), additionalInitActions);
49 | }
50 |
51 | public EditableLabelBigDecimalField(
52 | final BigDecimalField editor,
53 | final Consumer additionalInitActions)
54 | {
55 | super(editor, additionalInitActions);
56 | }
57 |
58 | @Override
59 | protected void initUI()
60 | {
61 | super.initUI();
62 | this.getEditor().setAutoselect(true);
63 | }
64 |
65 | public EditableLabelBigDecimalField withNumberFormat(final NumberFormat format)
66 | {
67 | return this.withLabelGenerator(format::format);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/predefined/EditableLabelComboBox.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label.predefined;
17 |
18 | import java.util.Collection;
19 | import java.util.function.Consumer;
20 |
21 | import com.vaadin.flow.component.ItemLabelGenerator;
22 | import com.vaadin.flow.component.combobox.ComboBox;
23 | import com.vaadin.flow.component.combobox.dataview.ComboBoxDataView;
24 | import com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView;
25 | import com.vaadin.flow.component.combobox.dataview.ComboBoxListDataView;
26 | import com.vaadin.flow.data.provider.BackEndDataProvider;
27 | import com.vaadin.flow.data.provider.DataProvider;
28 | import com.vaadin.flow.data.provider.HasDataView;
29 | import com.vaadin.flow.data.provider.HasLazyDataView;
30 | import com.vaadin.flow.data.provider.HasListDataView;
31 | import com.vaadin.flow.data.provider.InMemoryDataProvider;
32 | import com.vaadin.flow.data.provider.ListDataProvider;
33 | import com.vaadin.flow.function.SerializableFunction;
34 |
35 | import software.xdev.vaadin.editable_label.AbstractEditableLabel;
36 |
37 |
38 | /**
39 | * Offers a simple label which can be edited as a {@link ComboBox}.
40 | *
41 | * @author AB
42 | * @author JR
43 | */
44 | public class EditableLabelComboBox
45 | extends AbstractEditableLabel, ComboBox, T>
46 | implements
47 | HasDataView>,
48 | HasListDataView>,
49 | HasLazyDataView>
50 | {
51 | public EditableLabelComboBox()
52 | {
53 | this(new ComboBox<>());
54 | }
55 |
56 | public EditableLabelComboBox(final ComboBox editor)
57 | {
58 | this(editor, null);
59 | }
60 |
61 | public EditableLabelComboBox(final Consumer> additionalInitActions)
62 | {
63 | this(new ComboBox<>(), additionalInitActions);
64 | }
65 |
66 | public EditableLabelComboBox(
67 | final ComboBox editor,
68 | final Consumer> additionalInitActions)
69 | {
70 | super(editor, additionalInitActions);
71 | }
72 |
73 | @Override
74 | protected void initUI()
75 | {
76 | super.initUI();
77 | // Open ComboBox when in edit mode
78 | this.addEditModeChangedListener(ev -> this.getEditor().setOpened(ev.isEditModeEnabled()));
79 | }
80 |
81 | @Override
82 | public EditableLabelComboBox withNativeLabelGenerator(final ItemLabelGenerator labelGenerator)
83 | {
84 | super.withNativeLabelGenerator(labelGenerator);
85 | this.getEditor().setItemLabelGenerator(labelGenerator);
86 | return this.self();
87 | }
88 |
89 | public EditableLabelComboBox withItems(final T... items)
90 | {
91 | return this.withItems(DataProvider.ofItems(items));
92 | }
93 |
94 | public EditableLabelComboBox withItems(final Collection items)
95 | {
96 | return this.withItems(DataProvider.ofCollection(items));
97 | }
98 |
99 | public EditableLabelComboBox withItems(final ListDataProvider items)
100 | {
101 | this.setItems(items);
102 | return this.self();
103 | }
104 |
105 | @Override
106 | public ComboBoxListDataView setItems(final ListDataProvider dataProvider)
107 | {
108 | return this.getEditor().setItems(dataProvider);
109 | }
110 |
111 | @Override
112 | public ComboBoxListDataView getListDataView()
113 | {
114 | return this.getEditor().getListDataView();
115 | }
116 |
117 | @Override
118 | public ComboBoxDataView setItems(final DataProvider dataProvider)
119 | {
120 | return this.getEditor().setItems(dataProvider);
121 | }
122 |
123 | /**
124 | * @see ComboBox#setItems(InMemoryDataProvider, SerializableFunction)
125 | * @deprecated See upstream
126 | */
127 | @Deprecated(forRemoval = true)
128 | @Override
129 | public ComboBoxDataView setItems(final InMemoryDataProvider dataProvider)
130 | {
131 | return this.getEditor().setItems(dataProvider);
132 | }
133 |
134 | @Override
135 | public ComboBoxDataView getGenericDataView()
136 | {
137 | return this.getEditor().getGenericDataView();
138 | }
139 |
140 | @Override
141 | public ComboBoxLazyDataView setItems(final BackEndDataProvider dataProvider)
142 | {
143 | return this.getEditor().setItems(dataProvider);
144 | }
145 |
146 | @Override
147 | public ComboBoxLazyDataView getLazyDataView()
148 | {
149 | return this.getEditor().getLazyDataView();
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/predefined/EditableLabelDatePicker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label.predefined;
17 |
18 | import java.time.LocalDate;
19 | import java.time.format.DateTimeFormatter;
20 | import java.util.function.Consumer;
21 |
22 | import com.vaadin.flow.component.datepicker.DatePicker;
23 |
24 | import software.xdev.vaadin.editable_label.AbstractEditableLabel;
25 |
26 |
27 | /**
28 | * Offers a simple label which can be edited as a {@link DatePicker}.
29 | *
30 | * @author JR
31 | * @author AB
32 | */
33 | public class EditableLabelDatePicker
34 | extends AbstractEditableLabel
35 | {
36 | public EditableLabelDatePicker()
37 | {
38 | this(new DatePicker());
39 | }
40 |
41 | public EditableLabelDatePicker(final DatePicker editor)
42 | {
43 | this(editor, null);
44 | }
45 |
46 | public EditableLabelDatePicker(final Consumer additionalInitActions)
47 | {
48 | this(new DatePicker(), additionalInitActions);
49 | }
50 |
51 | public EditableLabelDatePicker(
52 | final DatePicker editor,
53 | final Consumer additionalInitActions)
54 | {
55 | super(editor, additionalInitActions);
56 | }
57 |
58 | public EditableLabelDatePicker withTryUseI18NFormat()
59 | {
60 | final DatePicker.DatePickerI18n i18n = this.editor.getI18n();
61 | if(i18n != null && !i18n.getDateFormats().isEmpty())
62 | {
63 | this.withLabelGenerator(DateTimeFormatter.ofPattern(i18n.getDateFormats().get(0))::format);
64 | }
65 | return this.self();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/predefined/EditableLabelNumberField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label.predefined;
17 |
18 | import java.util.function.Consumer;
19 |
20 | import com.vaadin.flow.component.textfield.NumberField;
21 | import com.vaadin.flow.component.textfield.TextFieldVariant;
22 |
23 | import software.xdev.vaadin.editable_label.AbstractEditableLabel;
24 |
25 |
26 | /**
27 | * Offers a simple label which can be edited as a {@link NumberField}.
28 | *
29 | * @author JR
30 | * @author AB
31 | */
32 | public class EditableLabelNumberField
33 | extends AbstractEditableLabel
34 | {
35 | public EditableLabelNumberField()
36 | {
37 | this(new NumberField());
38 | }
39 |
40 | public EditableLabelNumberField(final NumberField editor)
41 | {
42 | this(editor, null);
43 | }
44 |
45 | public EditableLabelNumberField(final Consumer additionalInitActions)
46 | {
47 | this(new NumberField(), additionalInitActions);
48 | }
49 |
50 | public EditableLabelNumberField(
51 | final NumberField editor,
52 | final Consumer additionalInitActions)
53 | {
54 | super(editor, additionalInitActions);
55 | }
56 |
57 | @Override
58 | protected void initUI()
59 | {
60 | super.initUI();
61 | this.getEditor().setAutoselect(true);
62 | this.getEditor().addThemeVariants(TextFieldVariant.LUMO_SMALL);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/predefined/EditableLabelTextArea.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label.predefined;
17 |
18 | import java.util.function.Consumer;
19 |
20 | import com.vaadin.flow.component.textfield.TextArea;
21 | import com.vaadin.flow.component.textfield.TextAreaVariant;
22 |
23 | import software.xdev.vaadin.editable_label.AbstractEditableLabel;
24 |
25 |
26 | /**
27 | * Offers a simple label which can be edited as a {@link TextArea}.
28 | *
29 | * @author JR
30 | * @author AB
31 | */
32 | public class EditableLabelTextArea
33 | extends AbstractEditableLabel
34 | {
35 | public EditableLabelTextArea()
36 | {
37 | this(new TextArea());
38 | }
39 |
40 | public EditableLabelTextArea(final TextArea editor)
41 | {
42 | this(editor, null);
43 | }
44 |
45 | public EditableLabelTextArea(final Consumer additionalInitActions)
46 | {
47 | this(new TextArea(), additionalInitActions);
48 | }
49 |
50 | public EditableLabelTextArea(
51 | final TextArea editor,
52 | final Consumer additionalInitActions)
53 | {
54 | super(editor, additionalInitActions);
55 | }
56 |
57 | @Override
58 | protected void initUI()
59 | {
60 | super.initUI();
61 | this.getEditor().setAutoselect(true);
62 | this.getEditor().addThemeVariants(TextAreaVariant.LUMO_SMALL);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/java/software/xdev/vaadin/editable_label/predefined/EditableLabelTextField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2023 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.editable_label.predefined;
17 |
18 | import java.util.function.Consumer;
19 |
20 | import com.vaadin.flow.component.textfield.TextField;
21 | import com.vaadin.flow.component.textfield.TextFieldVariant;
22 |
23 | import software.xdev.vaadin.editable_label.AbstractEditableLabel;
24 |
25 |
26 | /**
27 | * Offers a simple label which can be edited as a {@link TextField}.
28 | *
29 | * @author JR
30 | * @author AB
31 | */
32 | public class EditableLabelTextField
33 | extends AbstractEditableLabel
34 | {
35 | public EditableLabelTextField()
36 | {
37 | this(new TextField());
38 | }
39 |
40 | public EditableLabelTextField(final TextField editor)
41 | {
42 | this(editor, null);
43 | }
44 |
45 | public EditableLabelTextField(final Consumer additionalInitActions)
46 | {
47 | this(new TextField(), additionalInitActions);
48 | }
49 |
50 | public EditableLabelTextField(
51 | final TextField editor,
52 | final Consumer additionalInitActions)
53 | {
54 | super(editor, additionalInitActions);
55 | }
56 |
57 | @Override
58 | protected void initUI()
59 | {
60 | super.initUI();
61 | this.getEditor().setAutoselect(true);
62 | this.getEditor().addThemeVariants(TextFieldVariant.LUMO_SMALL);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/vaadin-editable-label/src/main/resources/META-INF/resources/frontend/styles/editableLabel.css:
--------------------------------------------------------------------------------
1 | .editable-label-container {
2 | display: flex;
3 | align-items: center;
4 | }
5 |
6 | .editable-label-button {
7 | margin: 0;
8 | padding: 0;
9 | cursor: pointer;
10 | }
11 |
12 | .editable-label-edit-button {
13 | display: none;
14 | height: var(--lumo-size-xs);
15 | width: var(--lumo-size-xs);
16 | }
17 |
18 | .editable-label-container:hover>.editable-label-edit-button, .editable-label-edit-button-always-visible {
19 | display: block;
20 | }
21 |
--------------------------------------------------------------------------------