/** * Gets a stream of components of type {@code T} which may be implemented by opened {@link TopComponent}s. * The stream also includes components that are part of opened {@link WorkspaceTopComponent}s. * * @param type The interface implemented by or the class extended by an opened {@link TopComponent} * @param <T> The type's type. * @return A stream of components of type {@code T}. */ public static <T> Stream<T> getOpened(final Class<T> type) { return tcProvider.getOpened().stream() .flatMap(topComponent -> { if (topComponent instanceof WindowContainer) { return Stream.concat(Stream.of(topComponent), ((WindowContainer) topComponent).getOpenedWindows().stream()); } return Stream.of(topComponent); }) .filter(topComponent -> type.isAssignableFrom(topComponent.getClass())) .map(topComponent -> (T) topComponent); }