@Nullable public static IViewPart findView(IWorkbenchWindow workbenchWindow, String viewId) { IViewReference[] references = workbenchWindow.getActivePage().getViewReferences(); for (IViewReference ref : references) { if (ref.getId().equals(viewId)) { return ref.getView(false); } } return null; }
@Nullable public static <T> T findView(IWorkbenchWindow workbenchWindow, Class<T> viewClass) { IViewReference[] references = workbenchWindow.getActivePage().getViewReferences(); for (IViewReference ref : references) { IViewPart view = ref.getView(false); if (view != null && viewClass.isAssignableFrom(view.getClass())) { return viewClass.cast(view); } } return null; }