void (@NotNull AnActionEvent e) { final Editor editor = e.getData(CommonDataKeys.EDITOR); if (editor == null) { return; } final Project project = editor.getProject(); if (project == null) { return; } final PsiDocumentManager docmgr = PsiDocumentManager.getInstance(project); final Document document = editor.getDocument(); docmgr.commitDocument(document); final PsiFile psiFile = docmgr.getPsiFile(document); if (!(psiFile instanceof XmlFile)) { return; } final PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset()); if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) { XPathAppComponent.showEditorHint(XPathBundle.message("hint.text.no.suitable.context.for.xpath.expression.selected"), editor); return; } final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element); if (node == null) { XPathAppComponent.showEditorHint(XPathBundle.message("hint.text.no.suitable.context.for.xpath.expression.selected"), editor); return; } final Config cfg = XPathAppComponent.getInstance().getConfig(); final RangeHighlighter h = HighlighterUtil.highlightNode(editor, node, cfg.getContextAttributes(), cfg); final String path = XPathSupport.getInstance().getUniquePath((XmlElement)node, null); //NON-NLS final JTextField label = new JTextField(path); //noinspection HardCodedStringLiteral label.setPreferredSize(new Dimension(label.getPreferredSize().width + new JLabel("M").getPreferredSize().width, label.getPreferredSize().height)); label.setOpaque(false); label.setEditable(false); label.setBorder(null); label.setHorizontalAlignment(SwingConstants.CENTER); label.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); final JPanel p = new NonOpaquePanel(new BorderLayout()); final JLabel l = new JLabel(XPathBundle.message("label.xpath")); p.add(l, BorderLayout.WEST); p.add(label, BorderLayout.CENTER); InplaceButton copy = new InplaceButton(ActionsBundle.message("action.EditorCopy.text"), PlatformIcons.COPY_ICON, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CopyPasteManager.getInstance().setContents(new StringSelection(path)); Balloon balloon = JBPopupFactory.getInstance().getParentBalloonFor(p); if (balloon != null) { balloon.hide(true); } } }); p.add(copy, BorderLayout.EAST); final LightweightHint hint = new LightweightHint(p) { @Override public void hide() { super.hide(); HighlighterUtil.removeHighlighter(editor, h); } @Override protected boolean canAutoHideOn(TooltipEvent event) { InputEvent inputEvent = event.getInputEvent(); return ((inputEvent instanceof MouseEvent)) && ((MouseEvent)inputEvent).getButton() != 0; } }; final Point point = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition()); point.y += editor.getLineHeight() / 2; HintHint hintHint = new HintHint(editor, point).setAwtTooltip(true).setContentActive(true).setExplicitClose(true).setShowImmediately(true); HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManager.HIDE_BY_ANY_KEY, 0, false, hintHint); }