1 19 20 package org.netbeans.modules.web.core.jsploader; 21 22 import org.openide.DialogDisplayer; 23 import org.openide.NotifyDescriptor; 24 import org.openide.cookies.EditorCookie; 25 import org.openide.filesystems.FileObject; 26 import org.openide.nodes.Node; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.NbBundle; 29 import org.openide.util.actions.CookieAction; 30 31 37 public class EditServletAction extends CookieAction { 38 39 40 private static final long serialVersionUID = 183706095337315796L; 41 42 43 private static final String [] UNSUPPORTED_EXTENSIONS = new String []{"jspf", "tagf"}; 44 45 50 protected boolean surviveFocusChange () { 51 return false; 52 } 53 54 58 public String getName () { 59 return NbBundle.getBundle(EditServletAction.class).getString("EditServlet"); 60 } 61 62 65 public HelpCtx getHelpCtx () { 66 return new HelpCtx (EditServletAction.class); 67 } 68 69 73 protected boolean enable(Node[] activatedNodes) { 74 for (int i = 0; i < activatedNodes.length; i++) { 75 JspDataObject jspdo = (JspDataObject)activatedNodes[i].getCookie(JspDataObject.class); 76 if(jspdo != null) { 77 FileObject jspfo = jspdo.getPrimaryFile(); 78 if(jspfo != null) { 79 String fileExt = jspfo.getExt(); 80 if(fileExt != null && isUnsupportedExtension(fileExt)) { 81 return false; 82 } 83 } 84 } 85 } 86 return true; 87 } 88 89 private boolean isUnsupportedExtension(String ext) { 90 for(String uext : UNSUPPORTED_EXTENSIONS) { 91 if(uext.equals(ext)) return true; 92 } 93 return false; 94 } 95 96 97 protected int mode() { 98 return MODE_ANY; 99 } 100 101 106 protected Class [] cookieClasses () { 107 return new Class [] { JspDataObject.class }; 108 } 109 110 114 protected void performAction (final Node[] activatedNodes) { 115 for (int i = 0; i < activatedNodes.length; i++) { 116 JspDataObject jspdo = (JspDataObject)activatedNodes[i].getCookie(JspDataObject.class); 117 if (jspdo != null) { 118 jspdo.refreshPlugin(true); 119 EditorCookie cook = jspdo.getServletEditor(); 120 if (cook != null) 121 cook.open (); 122 else { 123 String msg = NbBundle.getMessage(EditServletAction.class, "ERR_CantEditServlet"); 125 String title = NbBundle.getMessage(EditServletAction.class, "EditServlet"); 126 NotifyDescriptor descriptor = new NotifyDescriptor(msg, title, 127 NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE, 128 new Object []{NotifyDescriptor.OK_OPTION}, null); 129 DialogDisplayer.getDefault().notify(descriptor); 130 } 131 } 132 } 133 } 134 135 protected boolean asynchronous() { 136 return false; 137 } 138 139 } 140 | Popular Tags |