// 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