1 19 20 21 package org.netbeans.modules.i18n; 22 23 import org.openide.cookies.EditorCookie; 24 import org.openide.loaders.DataObject; 25 import org.openide.nodes.Node; 26 import org.openide.util.HelpCtx; 27 import org.openide.util.actions.NodeAction; 28 import org.netbeans.api.project.FileOwnerQuery; 29 30 31 39 public class I18nAction extends NodeAction { 40 41 42 static final long serialVersionUID =3322896507302889271L; 43 44 public I18nAction() { 45 putValue("noIconInMenu", Boolean.TRUE); 46 } 47 48 52 protected void performAction(final Node[] activatedNodes) { 53 if (activatedNodes.length != 1) 54 return; 55 56 final Node node = activatedNodes[0]; 57 DataObject dataObject = (DataObject) node.getCookie(DataObject.class); 58 if (dataObject == null) 59 return; 60 61 EditorCookie editorCookie = (EditorCookie) node.getCookie(EditorCookie.class); 62 if (editorCookie == null) { 63 editorCookie = (EditorCookie) dataObject.getCookie(EditorCookie.class); 64 if (editorCookie == null) 65 return; 66 } 67 68 editorCookie.open(); 69 I18nManager.getDefault().internationalize(dataObject); 70 } 71 72 protected boolean asynchronous() { 73 return false; 74 } 75 76 78 protected boolean enable(Node[] activatedNodes) { 79 if (activatedNodes.length != 1) 80 return false; 81 82 final Node node = activatedNodes[0]; 83 DataObject dataObject = (DataObject) node.getCookie(DataObject.class); 84 if (dataObject == null || dataObject.getPrimaryFile() == null) 85 return false; 86 87 EditorCookie editorCookie = (EditorCookie) node.getCookie(EditorCookie.class); 88 if (editorCookie == null) { 89 editorCookie = (EditorCookie) dataObject.getCookie(EditorCookie.class); 90 if (editorCookie == null) 91 return false; 92 } 93 94 if (!FactoryRegistry.hasFactory(dataObject.getClass())) 95 return false; 96 97 if (FileOwnerQuery.getOwner(dataObject.getPrimaryFile()) == null) 99 return false; 100 101 return true; 102 } 103 104 105 public String getName() { 106 return I18nUtil.getBundle().getString("CTL_I18nAction"); 107 } 108 109 110 public HelpCtx getHelpCtx() { 111 return new HelpCtx(I18nUtil.HELP_ID_AUTOINSERT); 112 } 113 } 114 | Popular Tags |