1 19 package org.openide.actions; 20 21 import org.openide.DialogDisplayer; 22 import org.openide.NotifyDescriptor; 23 import org.openide.nodes.Node; 24 import org.openide.util.Exceptions; 25 import org.openide.util.HelpCtx; 26 import org.openide.util.NbBundle; 27 import org.openide.util.actions.*; 28 29 30 35 public class RenameAction extends NodeAction { 36 protected boolean surviveFocusChange() { 37 return false; 38 } 39 40 public String getName() { 41 return NbBundle.getMessage(RenameAction.class, "Rename"); 42 } 43 44 public HelpCtx getHelpCtx() { 45 return new HelpCtx(RenameAction.class); 46 } 47 48 protected boolean enable(Node[] activatedNodes) { 49 if ((activatedNodes == null) || (activatedNodes.length != 1)) { 51 return false; 52 } 53 54 return activatedNodes[0].canRename(); 56 } 57 58 protected void performAction(Node[] activatedNodes) { 59 Node n = activatedNodes[0]; 61 NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine( 62 NbBundle.getMessage(RenameAction.class, "CTL_RenameLabel"), 63 NbBundle.getMessage(RenameAction.class, "CTL_RenameTitle") 64 ); 65 dlg.setInputText(n.getName()); 66 67 if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) { 68 String newname = null; 69 70 try { 71 newname = dlg.getInputText(); 72 73 if (!newname.equals("")) { 74 n.setName(dlg.getInputText()); } 76 } catch (IllegalArgumentException e) { 77 boolean needToAnnotate = Exceptions.findLocalizedMessage(e) == null; 79 80 if (needToAnnotate) { 82 Exceptions.attachLocalizedMessage(e, 83 NbBundle.getMessage(RenameAction.class, 84 "MSG_BadFormat", 85 n.getName(), 86 newname)); 87 } 88 89 Exceptions.printStackTrace(e); 90 } 91 } 92 } 93 94 protected boolean asynchronous() { 95 return false; 96 } 97 } 98 | Popular Tags |