Skip to content

Commit 270cc14

Browse files
committed
refactor: deprecate hascomponents api and provide alternatives
1 parent afb5bfb commit 270cc14

File tree

1 file changed

+98
-21
lines changed
  • vaadin-context-menu-flow-parent/vaadin-context-menu-flow/src/main/java/com/vaadin/flow/component/contextmenu

1 file changed

+98
-21
lines changed

vaadin-context-menu-flow-parent/vaadin-context-menu-flow/src/main/java/com/vaadin/flow/component/contextmenu/ContextMenuBase.java

+98-21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.vaadin.flow.component.contextmenu;
1717

18+
import java.util.Collection;
1819
import java.util.List;
1920
import java.util.stream.Stream;
2021

@@ -203,17 +204,10 @@ public void close() {
203204
/**
204205
* Adds a new item component with the given text content to the context menu
205206
* overlay.
206-
* <p>
207-
* This is a convenience method for the use case where you have a list of
208-
* highlightable {@link MenuItem}s inside the overlay. If you want to
209-
* configure the contents of the overlay without wrapping them inside
210-
* {@link MenuItem}s, or if you just want to add some non-highlightable
211-
* components between the items, use the {@link #add(Component...)} method.
212207
*
213208
* @param text
214209
* the text content for the created menu item
215210
* @return the created menu item
216-
* @see #add(Component...)
217211
*/
218212
public I addItem(String text) {
219213
return getMenuManager().addItem(text);
@@ -222,17 +216,10 @@ public I addItem(String text) {
222216
/**
223217
* Adds a new item component with the given component to the context menu
224218
* overlay.
225-
* <p>
226-
* This is a convenience method for the use case where you have a list of
227-
* highlightable {@link MenuItem}s inside the overlay. If you want to
228-
* configure the contents of the overlay without wrapping them inside
229-
* {@link MenuItem}s, or if you just want to add some non-highlightable
230-
* components between the items, use the {@link #add(Component...)} method.
231219
*
232220
* @param component
233221
* the component to add to the created menu item
234222
* @return the created menu item
235-
* @see #add(Component...)
236223
*/
237224
public I addItem(Component component) {
238225
return getMenuManager().addItem(component);
@@ -241,10 +228,6 @@ public I addItem(Component component) {
241228
/**
242229
* Adds the given components into the context menu overlay.
243230
* <p>
244-
* For the common use case of having a list of high-lightable items inside
245-
* the overlay, you can use the {@link #addItem(String)} convenience methods
246-
* instead.
247-
* <p>
248231
* The added elements in the DOM will not be children of the
249232
* {@code <vaadin-context-menu>} element, but will be inserted into an
250233
* overlay that is attached into the {@code <body>}.
@@ -253,23 +236,98 @@ public I addItem(Component component) {
253236
* the components to add
254237
* @see HasMenuItems#addItem(String, ComponentEventListener)
255238
* @see HasMenuItems#addItem(Component, ComponentEventListener)
239+
*
240+
* @deprecated Since 24.8, use {@link #addItem(Component)} instead
256241
*/
242+
@Deprecated(since = "24.8")
257243
@Override
258244
public void add(Component... components) {
259245
getMenuManager().add(components);
260246
}
261247

248+
/**
249+
* @inheritDoc
250+
*
251+
* @deprecated Since 24.8, use {@link #addItem(Component)} instead
252+
*/
253+
@Deprecated(since = "24.8")
254+
@Override
255+
public void add(Collection<Component> components) {
256+
HasComponents.super.add(components);
257+
}
258+
259+
/**
260+
* @inheritDoc
261+
*
262+
* @deprecated Since 24.8, use {@link #addItem(String)} instead
263+
*/
264+
@Deprecated(since = "24.8")
265+
@Override
266+
public void add(String text) {
267+
HasComponents.super.add(text);
268+
}
269+
270+
/**
271+
* @inheritDoc
272+
*
273+
* @deprecated Since 24.8, use {@link #addItem(Component)} instead
274+
*/
275+
@Deprecated(since = "24.8")
276+
@Override
277+
public void addComponentAsFirst(Component component) {
278+
HasComponents.super.addComponentAsFirst(component);
279+
}
280+
281+
/**
282+
* @inheritDoc
283+
*
284+
* @deprecated Since 24.8, use {@link #removeItem(Component...)} instead
285+
*/
286+
@Deprecated(since = "24.8")
262287
@Override
263288
public void remove(Component... components) {
289+
removeItem(components);
290+
}
291+
292+
/**
293+
* Removes the provided components from the context menu overlay.
294+
*
295+
* @param components
296+
* the components to remove
297+
*/
298+
public void removeItem(Component... components) {
264299
getMenuManager().remove(components);
265300
}
266301

267302
/**
268-
* Removes all of the child components. This also removes all the items
269-
* added with {@link #addItem(String)} and its overload methods.
303+
* @inheritDoc
304+
*
305+
* @deprecated Since 24.8, use {@link #removeItem(Component...)} instead
306+
*/
307+
@Deprecated(since = "24.8")
308+
@Override
309+
public void remove(Collection<Component> components) {
310+
removeItem(components == null ? null
311+
: components.toArray(new Component[0]));
312+
}
313+
314+
/**
315+
* Removes all the child components. This also removes all the items added
316+
* with {@link #addItem(String)} and its overload methods.
317+
*
318+
* @deprecated Since 24.8, use {@link #removeAllItems()} instead
270319
*/
320+
@Deprecated(since = "24.8")
271321
@Override
272322
public void removeAll() {
323+
removeAllItems();
324+
}
325+
326+
/**
327+
* Removes all the child components. This also removes all the items added
328+
* with {@link #addItem(String)} and its overload methods.
329+
*/
330+
public void removeAllItems() {
273331
getMenuManager().removeAll();
274332
}
275333

@@ -284,10 +342,29 @@ public void removeAll() {
284342
* the index, where the component will be added
285343
* @param component
286344
* the component to add
287-
* @see #add(Component...)
345+
*
346+
* @deprecated Since 24.8, use {@link #addItemAtIndex(int, Component)}
347+
* instead
288348
*/
349+
@Deprecated(since = "24.8")
289350
@Override
290351
public void addComponentAtIndex(int index, Component component) {
352+
addItemAtIndex(index, component);
353+
}
354+
355+
/**
356+
* Adds the given component into this context menu at the given index.
357+
* <p>
358+
* The added elements in the DOM will not be children of the
359+
* {@code <vaadin-context-menu>} element, but will be inserted into an
360+
* overlay that is attached into the {@code <body>}.
361+
*
362+
* @param index
363+
* the index, where the component will be added
364+
* @param component
365+
* the component to add
366+
*/
367+
public void addItemAtIndex(int index, Component component) {
291368
getMenuManager().addComponentAtIndex(index, component);
292369
}
293370

0 commit comments

Comments
 (0)