+ /**
+ * Checks whether the given mouse event is a popup trigger and occured over
+ * a file. If so, the context menu is shown.
+ *
+ * @param mouseEvent
+ * The mouse event to check
+ */
+ private void maybeShowContextMenu(MouseEvent mouseEvent) {
+ if (!mouseEvent.isPopupTrigger()) {
+ return;
+ }
+ Point eventLocation = mouseEvent.getPoint();
+ TreePath clickedPath = fileTree.getPathForLocation(eventLocation.x, eventLocation.y);
+ if (clickedPath == null) {
+ return;
+ }
+ fileTree.setSelectionPath(clickedPath);
+ treeContextMenu.show(fileTree, eventLocation.x, eventLocation.y);
+ }
+