public static MouseListener installFollowingSelectionTreePopup(final JTree tree, final ActionGroup group, final String place, final ActionManager actionManager){
if (ApplicationManager.getApplication() == null) return new MouseAdapter(){};
PopupHandler handler = new PopupHandler() {
public void invokePopup(Component comp, int x, int y) {
if (tree.getPathForLocation(x, y) != null && Arrays.binarySearch(tree.getSelectionRows(), tree.getRowForLocation(x, y)) > -1) { //do not show popup menu on rows other than selection
final ActionPopupMenu popupMenu = actionManager.createActionPopupMenu(place, group);
popupMenu.getComponent().show(comp, x, y);
}
}
};
tree.addMouseListener(handler);
return handler;