@@ -71,6 +71,48 @@ public class ChipField<T> extends AbstractField<ChipField<T>, List<T>>
7171 private ItemLabelGenerator <T > itemLabelGenerator ;
7272 private SerializableFunction <String , T > newItemHandler ;
7373
74+ public abstract static class ChipEvent <T > extends ComponentEvent <ChipField <T >> {
75+
76+ private final String chipLabel ;
77+ private final T item ;
78+
79+ public ChipEvent (ChipField <T > source , boolean fromClient , String chipLabel ) {
80+ super (source , fromClient );
81+ this .chipLabel = chipLabel ;
82+ this .item = source .findItemByLabel (chipLabel ).orElse (null );
83+ }
84+
85+ public String getChipLabel () {
86+ return chipLabel ;
87+ }
88+
89+ public T getItem () {
90+ return item ;
91+ }
92+
93+ }
94+
95+ @ DomEvent ("chip-removed" )
96+ public static class ChipRemovedEvent <T > extends ChipEvent <T > {
97+ public ChipRemovedEvent (ChipField <T > source , boolean fromClient , @ EventData (CHIP_LABEL ) String chipLabel ) {
98+ super (source , fromClient , chipLabel );
99+ }
100+ }
101+
102+ @ DomEvent ("chip-created" )
103+ public static class ChipCreatedEvent <T > extends ChipEvent <T > {
104+ public ChipCreatedEvent (ChipField <T > source , boolean fromClient , @ EventData (CHIP_LABEL ) String chipLabel ) {
105+ super (source , fromClient , chipLabel );
106+ }
107+ }
108+
109+ @ DomEvent ("chip-clicked" )
110+ public static class ChipClickedEvent <T > extends ChipEvent <T > {
111+ public ChipClickedEvent (ChipField <T > source , boolean fromClient , @ EventData (CHIP_LABEL ) String chipLabel ) {
112+ super (source , fromClient , chipLabel );
113+ }
114+ }
115+
74116 @ SafeVarargs
75117 public ChipField (String label , ItemLabelGenerator <T > itemLabelGenerator , T ... availableItems ) {
76118 super (new ArrayList <>());
@@ -231,37 +273,6 @@ public void validate() {
231273 getElement ().callJsFunction ("validate" );
232274 }
233275
234- // EVENTS
235- @ DomEvent ("chip-removed" )
236- public static class ChipRemovedEvent <T > extends ComponentEvent <ChipField <T >> {
237-
238- private final String chipLabel ;
239-
240- public ChipRemovedEvent (ChipField <T > source , boolean fromClient , @ EventData (CHIP_LABEL ) String chipLabel ) {
241- super (source , fromClient );
242- this .chipLabel = chipLabel ;
243- }
244-
245- public String getChipLabel () {
246- return chipLabel ;
247- }
248- }
249-
250- @ DomEvent ("chip-created" )
251- public static class ChipCreatedEvent <T > extends ComponentEvent <ChipField <T >> {
252-
253- private final String chipLabel ;
254-
255- public ChipCreatedEvent (ChipField <T > source , boolean fromClient , @ EventData (CHIP_LABEL ) String chipLabel ) {
256- super (source , fromClient );
257- this .chipLabel = chipLabel ;
258- }
259-
260- public String getChipLabel () {
261- return chipLabel ;
262- }
263- }
264-
265276 @ SuppressWarnings ({ "unchecked" , "rawtypes" })
266277 public Registration addChipRemovedListener (ComponentEventListener <ChipRemovedEvent <T >> listener ) {
267278 return addListener (ChipRemovedEvent .class , (ComponentEventListener ) listener );
@@ -324,21 +335,6 @@ private void removeSelectedItem(T itemToRemove, boolean fromClient) {
324335 }
325336 }
326337
327- @ DomEvent ("chip-clicked" )
328- public static class ChipClickedEvent <T > extends ComponentEvent <ChipField <T >> {
329-
330- private final String chipLabel ;
331-
332- public ChipClickedEvent (ChipField <T > source , boolean fromClient , @ EventData (CHIP_LABEL ) String chipLabel ) {
333- super (source , fromClient );
334- this .chipLabel = chipLabel ;
335- }
336-
337- public String getChipLabel () {
338- return chipLabel ;
339- }
340- }
341-
342338 @ SuppressWarnings ({ "unchecked" , "rawtypes" })
343339 public Registration addChipClickedListener (ComponentEventListener <ChipClickedEvent <T >> listener ) {
344340 return addListener (ChipClickedEvent .class , (ComponentEventListener ) listener );
0 commit comments