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) {
}
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();
TreePath path = ((JTree)menu.getInvoker()).getClosestPathForLocation( menu.getInvokerLocation().x , menu.getInvokerLocation().y);
if(path != null) {
AWorkspaceTreeNode node = (AWorkspaceTreeNode) path.getLastPathComponent();
((AWorkspaceAction) action).setEnabledFor(node, selectedNodes);
}
else {
((AWorkspaceAction) action).setEnabledFor((AWorkspaceTreeNode) WorkspaceController.getCurrentModel().getRoot(), selectedNodes);
}