1 19 20 21 package org.netbeans.modules.j2ee.archive.project; 22 23 import java.io.IOException ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.spi.project.ActionProvider; 28 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 29 import org.openide.DialogDisplayer; 30 import org.openide.ErrorManager; 31 import org.openide.NotifyDescriptor; 32 import org.openide.filesystems.FileObject; 33 import org.openide.util.Lookup; 34 import org.netbeans.spi.project.ui.support.DefaultProjectOperations; 35 import org.openide.util.NbBundle; 36 import org.apache.tools.ant.module.api.support.ActionUtils; 37 38 public class ProvidesAction implements ActionProvider { 39 private static final String COMMAND_VERIFY = "verify"; 41 private Project project; 42 static Map commands; 43 static { 44 commands = new HashMap (); 45 commands.put(COMMAND_BUILD, new String [] {"dist"}); commands.put(COMMAND_RUN, new String [] {"run-deploy"}); commands.put(COMMAND_VERIFY, new String [] {"verify"}); } 49 50 ProvidesAction(Project project) { 51 this.project=project; 52 } 53 54 public String [] getSupportedActions() { 55 return new String [] {ActionProvider.COMMAND_BUILD, 57 ActionProvider.COMMAND_RUN, COMMAND_VERIFY, 58 ActionProvider.COMMAND_DELETE, 59 ActionProvider.COMMAND_COPY, 60 ActionProvider.COMMAND_MOVE, 61 ActionProvider.COMMAND_RENAME, 62 }; 63 } 64 65 public void invokeAction(final String command, final Lookup context) { 66 if (COMMAND_DELETE.equals(command)) { 67 DefaultProjectOperations.performDefaultDeleteOperation(project); 68 return ; 69 } 70 71 if (COMMAND_COPY.equals(command)) { 72 DefaultProjectOperations.performDefaultCopyOperation(project); 73 return ; 74 } 75 76 if (COMMAND_MOVE.equals(command)) { 77 DefaultProjectOperations.performDefaultMoveOperation(project); 78 return ; 79 } 80 81 if (COMMAND_RENAME.equals(command)) { 82 DefaultProjectOperations.performDefaultRenameOperation(project, null); 83 return ; 84 } 85 86 87 Runnable action = new Runnable () { 89 public void run () { 90 String [] targetNames; 91 92 targetNames = getTargetNames(command, context); 93 if (targetNames == null) { 94 return; 95 } 96 if (targetNames.length == 0) { 97 targetNames = null; 98 } 99 try { 100 FileObject buildFo = findBuildXml(); 101 if (buildFo == null || !buildFo.isValid()) { 102 NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(ProvidesAction.class, 104 java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/archive/project/Bundle").getString("LBL_No_Build_XML_Found")), NotifyDescriptor.WARNING_MESSAGE); 105 DialogDisplayer.getDefault().notify(nd); 106 } 107 else { 108 ActionUtils.runTarget(buildFo, targetNames, null); } 110 } 111 catch (IOException e) { 112 ErrorManager.getDefault().notify(e); 113 } 114 } 115 }; 116 117 action.run(); 118 } 119 120 public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException { 121 return ! (findBuildXml() == null); 123 } 124 125 128 String [] getTargetNames(String command, Lookup context) throws IllegalArgumentException { 129 String [] targetNames = (String [])commands.get(command); 130 return targetNames; 131 } 132 133 private FileObject findBuildXml() { 134 return project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); 135 } 136 } 137 | Popular Tags |