1 19 20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres; 21 import javax.swing.*; 22 import org.openide.loaders.DataObject; 23 import org.openide.nodes.Node; 24 25 import org.openide.util.*; 26 import org.netbeans.api.project.FileOwnerQuery; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer; 29 import org.openide.util.actions.Presenter; 30 import org.openide.util.actions.NodeAction; 31 import org.openide.util.actions.SystemAction; 32 33 37 public class EnterpriseRefActionGroup extends NodeAction implements Presenter.Popup { 38 39 public String getName() { 40 return NbBundle.getMessage(EnterpriseRefActionGroup.class, "LBL_EnterpriseActionGroup"); 41 } 42 43 44 private static final SystemAction[] grouped() { 45 return new SystemAction[] { 46 SystemAction.get(CallEjbAction.class), 47 SystemAction.get(UseDatabaseAction.class), 48 SystemAction.get(SendJMSMessageAction.class), 49 SystemAction.get(SendEmailAction.class) 50 }; 51 } 52 53 public JMenuItem getPopupPresenter() { 54 boolean oneNodeSelected = getActivatedNodes().length == 1; 55 if (oneNodeSelected && hasEnterpriseRefStrategy()) { 56 return new LazyMenu(); 57 } 58 JMenuItem jMenuItem = super.getPopupPresenter(); 59 jMenuItem.setVisible(false); 60 return jMenuItem; 61 } 62 63 public HelpCtx getHelpCtx() { 64 return HelpCtx.DEFAULT_HELP; 65 } 68 69 protected boolean enable(org.openide.nodes.Node[] activatedNodes) { 70 return true; 71 } 72 73 protected void performAction(org.openide.nodes.Node[] activatedNodes) { 74 assert false : "Should never be called: "; 75 } 76 77 private Project getSelectedProject() { 78 Node[] activatedNodes = getActivatedNodes(); 79 DataObject dobj = (DataObject) 80 activatedNodes[0].getLookup().lookup(DataObject.class); 81 82 return dobj == null ? null:FileOwnerQuery.getOwner(dobj.getPrimaryFile()); 83 } 84 85 private boolean hasEnterpriseRefStrategy() { 86 Project project = getSelectedProject(); 87 return project != null && 88 project.getLookup().lookup(EnterpriseReferenceContainer.class) != null; 89 } 90 91 94 private final class LazyMenu extends JMenu { 95 96 public LazyMenu() { 97 super(EnterpriseRefActionGroup.this.getName()); 98 } 99 100 public JPopupMenu getPopupMenu() { 101 if (getItemCount() == 0) { 102 Action[] grouped = grouped(); 103 for (int i = 0; i < grouped.length; i++) { 104 Action action = grouped[i]; 105 if (action == null && getItemCount() != 0) { 106 addSeparator(); 107 } else { 108 if (action instanceof ContextAwareAction) { 109 action = ((ContextAwareAction)action).createContextAwareInstance(Utilities.actionsGlobalContext()); 110 } 111 if (action instanceof Presenter.Popup) { 112 add(((Presenter.Popup)action).getPopupPresenter()); 113 } 114 } 115 } 116 } 117 return super.getPopupMenu(); 118 } 119 } 120 121 } 122 | Popular Tags |