VaadinUtils { @SuppressWarnings("unchecked") public static <T> T getParentOfClass(Component component, Class<T> clazz) { while (component.getParent().isPresent()) { component = component.getParent().orElse(null); if (component != null && clazz.isAssignableFrom(component.getClass())) { return (T) component; } } return null; } private  VaadinUtils(); static String bigDecimalToString(boolean percentage, boolean useGrouping, BigDecimal value); static String bigDecimalToString(boolean currency, boolean percentage, boolean useGrouping,
			BigDecimal value); static String bigDecimalToString(boolean currency, boolean percentage, boolean useGrouping, int precision,
			BigDecimal value, Locale locale); static String bigDecimalToString(boolean currency, boolean percentage, boolean useGrouping, int precision,
			BigDecimal value, Locale locale, String currencySymbol); static Image createImage(String imageName); static String doubleToString(boolean currency, boolean percentage, boolean useGrouping, int precision,
			Double value, Locale locale); static String doubleToString(boolean currency, boolean percentage, boolean useGrouping, int precision,
			Double value, Locale locale, String currencySymbol); static String getCurrencySymbol(); static Locale getDateLocale(); @SuppressWarnings("unchecked") static T getFirstChildOfClass(Component component, Class<T> clazz); static String getFirstValueFromCollection(Map<String, Object> map, String key); static Object getFromSession(String name); static Locale getLocale(); @SuppressWarnings("unchecked") static T getParentOfClass(Component component, Class<T> clazz); @SuppressWarnings("unchecked") static String getSessionAttributeValueFromMap(String attributeName, String key); static String integerToString(boolean grouping, boolean percentage, Integer value); static String integerToString(boolean grouping, boolean percentage, Integer value, Locale locale); static String longToString(boolean grouping, boolean percentage, Long value); static String longToString(boolean grouping, boolean percentage, Long value, Locale locale); static String numberToString(AttributeModel am, T value, boolean grouping, Locale locale,
			String currencySymbol); static void removeFromSession(String name); static void setLabel(Component component, String label); static void setPlaceHolder(Component component, String placeHolder); static void setTooltip(Component component, String tooltip); static void showConfirmDialog(String question, Runnable whenConfirmed); static void showConfirmDialog(String question, Runnable whenConfirmed, Runnable whenCanceled); static void showErrorNotification(String message); static void showNotification(String message, Position position, NotificationVariant variant); static void showTrayNotification(String message); static void storeDateLocale(Locale locale); static void storeInSession(String name, Object value); static void storeLocale(Locale locale); static BigDecimal stringToBigDecimal(boolean percentage, boolean useGrouping, boolean currency,
			int precision, String value, Locale locale); static BigDecimal stringToBigDecimal(boolean percentage, boolean useGrouping, boolean currency,
			String value); static Double stringToDouble(boolean percentage, boolean useGrouping, boolean currency, int precision,
			String value, Locale locale); static Integer stringToInteger(boolean grouping, String value); static Integer stringToInteger(boolean grouping, String value, Locale locale); static Long stringToLong(boolean grouping, String value); static Long stringToLong(boolean grouping, String value, Locale locale); static VerticalLayout createOverflowLayout(String height);  }
@Test public void testGetParentOfClass() { VerticalLayout vert = new VerticalLayout(); HorizontalLayout hor = new HorizontalLayout(); Button button = new Button(); vert.add(hor); hor.add(button); assertEquals(hor, VaadinUtils.getParentOfClass(button, HorizontalLayout.class)); assertEquals(vert, VaadinUtils.getParentOfClass(button, VerticalLayout.class)); }