void (@NotNull AnActionEvent e) { VirtualFile file = getFileFromSelection(); if (file != null) { final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); if (psiFile != null) { final ImplementationViewComponent viewComponent = new ImplementationViewComponent(Collections.singletonList(new PsiImplementationViewElement(psiFile)), 0); final TreeSelectionListener listener = e1 -> { final VirtualFile selection = getFileFromSelection(); if (selection != null) { final PsiFile newElement = PsiManager.getInstance(myProject).findFile(selection); if (newElement != null) { viewComponent.update(Collections.singletonList(new PsiImplementationViewElement(newElement)), 0); } } }; myTree.addTreeSelectionListener(listener); final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(viewComponent, viewComponent.getPreferredFocusableComponent()) .setProject(myProject) .setDimensionServiceKey(myProject, ImageDuplicateResultsDialog.class.getName(), false) .setResizable(true) .setMovable(true) .setRequestFocus(false) .addListener(new JBPopupListener() { @Override public void onClosed(@NotNull LightweightWindowEvent event) { viewComponent.cleanup(); } }) .setCancelCallback(() -> { myTree.removeTreeSelectionListener(listener); return true; }) .setTitle("Image Preview") .createPopup(); final Window window = ImageDuplicateResultsDialog.this.getWindow(); popup.show(new RelativePoint(window, new Point(window.getWidth(), 0))); viewComponent.setHint(popup, "Image Preview"); } } }