Open File from Balloon
I am creating a balloon at some point in my code & I want to put in a clickable link to a file. I currently have the file as a VirtualFile object:
VirtualFile file = _profilerManager.getCurentFile();
and I am creating & showing the balloon this way:
Balloon balloon = UiUtil.createWidthLimitedTextBalloonBuilder(ProfilerBundle.message("action.gw.profiler.AutoAnalysis.Complete", _file.getName()), MessageType.INFO, 600)
.setCloseButtonEnabled(true)
.setDisposable(_profilerManager.getProject())
.setHideOnAction(true)
.setHideOnClickOutside(true)
.setHideOnKeyOutside(true)
.createBalloon();
balloon.show(new RelativePoint(selectedCompoenent, new Point(50, selectedCompoenent.getY()
The current solution results in the file name being shown in the balloon, which is not bad, but it would be even nicer if it was clickable- and IJ navigated to that file. I am not too fussy about the balloon's appearance.
Please sign in to leave a comment.
Try using JBPopupFactory.createHTMLTextBaloonBuilder(..)
Thank you Kirill. Eventually I got back around to this. Here is the solution:
Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(ProfilerBundle.message("action.gw.profiler.AutoAnalysis.Complete", linkIfy(_file.getName())), Icons.AUTO_ANALYSIS, Color.CYAN, new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if(! (e.getEventType() == ACTIVATED)){return;}
FileEditorManager.getInstance(_profilerManager.getProject()).openFile(_file, true);
}
}).setCloseButtonEnabled(true)
.setDisposable(_profilerManager.getProject())
.setHideOnAction(true)
.setHideOnClickOutside(true)
.setHideOnLinkClick(true)
.setHideOnKeyOutside(true)
.createBalloon();
balloon.show(new RelativePoint(selectedCompoenent, new Point(50, selectedCompoenent.getY() * 3 / 2)), Balloon.Position.above);
I'm using these auxiliary functions to turn the string into a link:
References: