private static void addListeners(final WorkspacePopupMenu popupMenu, final AFreeplaneAction action) {
if (action instanceof PopupMenuListener) {
popupMenu.addPopupMenuListener(new DelegatingPopupMenuListener((PopupMenuListener) action, popupMenu));
}
if (AFreeplaneAction.checkSelectionOnPopup(action)) {
popupMenu.addPopupMenuListener(new PopupMenuListener() {
public void popupMenuCanceled(final PopupMenuEvent e) {
}
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
}
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
if(action instanceof AWorkspaceAction && e.getSource() instanceof WorkspacePopupMenu) {
WorkspacePopupMenu menu = ((WorkspacePopupMenu)e.getSource());
TreePath[] selectedNodes = ((JTree)menu.getInvoker()).getSelectionPaths();
AWorkspaceTreeNode node = (AWorkspaceTreeNode) ((JTree)menu.getInvoker()).getClosestPathForLocation(menu.getInvokerLocation().x, menu.getInvokerLocation().y).getLastPathComponent();
((AWorkspaceAction) action).setSelectedFor(node, selectedNodes);
}
else {
action.setSelected();
}
}
});
}
if (AWorkspaceAction.checkEnabledOnPopup(action)) {
popupMenu.addPopupMenuListener(new PopupMenuListener() {
public void popupMenuCanceled(final PopupMenuEvent e) {
}
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
}