1 19 20 28 29 package org.netbeans.modules.xml.refactoring.actions; 30 31 import javax.swing.*; 32 33 import org.openide.util.*; 34 import org.openide.util.actions.NodeAction; 35 import org.openide.util.actions.Presenter; 36 import org.openide.util.actions.SystemAction; 37 38 43 public class RefactorAction extends NodeAction implements Presenter.Popup{ 44 private static final long serialVersionUID = 1L; 45 46 55 public String getName() { 56 return NbBundle.getMessage(RefactorAction.class, 57 "LBL_Refactor"); 58 } 59 60 61 private static final SystemAction[] grouped() { 62 return new SystemAction[] { 63 SystemAction.get(SafelyRenameAction.class), 64 null, 65 SystemAction.get(SafelyDeleteAction.class), 66 null, 67 SystemAction.get(RefactoringUndoAction.class), 68 SystemAction.get(RefactoringRedoAction.class) 69 }; 70 } 71 72 protected SystemAction[] getGroupedActions() { 73 return grouped(); 74 } 75 76 public JMenuItem getPopupPresenter() { 77 return new LazyMenu(getName()); 78 } 79 80 public HelpCtx getHelpCtx() { 81 return HelpCtx.DEFAULT_HELP; 82 } 85 86 protected boolean enable(org.openide.nodes.Node[] activatedNodes) { 87 return true; 88 } 89 90 protected void performAction(org.openide.nodes.Node[] activatedNodes) { 91 assert false : "Should never be called: "; 92 } 93 94 95 98 protected class LazyMenu extends JMenu { 99 private final static long serialVersionUID = 1L; 100 101 public LazyMenu(String name) { 102 super(name); 103 } 104 105 public JPopupMenu getPopupMenu() { 106 if (getItemCount() == 0) { 107 SystemAction[] grouped = getGroupedActions(); 108 for (int i = 0; i < grouped.length; i++) { 109 SystemAction action = grouped[i]; 110 if (action == null) { 111 addSeparator(); 112 } else if (action instanceof Presenter.Popup) { 113 add(((Presenter.Popup)action).getPopupPresenter()); 114 } else { 115 assert false : "Action had no popup presenter: " + action; 116 } 117 } 118 } 119 return super.getPopupMenu(); 120 } 121 122 } 123 124 125 } 126 | Popular Tags |