1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.List ; 26 import javax.swing.Action ; 27 import javax.swing.JSeparator ; 28 import org.apache.tools.ant.module.api.support.ActionUtils; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.modules.apisupport.project.NbModuleProject; 31 import org.netbeans.modules.apisupport.project.Util; 32 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 33 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteCustomizer; 34 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 35 import org.netbeans.spi.project.ActionProvider; 36 import org.netbeans.spi.project.SubprojectProvider; 37 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 38 import org.netbeans.spi.project.ui.support.CommonProjectActions; 39 import org.netbeans.spi.project.ui.support.DefaultProjectOperations; 40 import org.netbeans.spi.project.ui.support.ProjectSensitiveActions; 41 import org.openide.NotifyDescriptor; 42 import org.openide.actions.FindAction; 43 import org.openide.actions.ToolsAction; 44 import org.openide.execution.ExecutorTask; 45 import org.openide.filesystems.FileObject; 46 import org.openide.filesystems.Repository; 47 import org.openide.loaders.DataFolder; 48 import org.openide.loaders.FolderLookup; 49 import org.openide.util.Lookup; 50 import org.openide.util.NbBundle; 51 import org.openide.util.actions.SystemAction; 52 53 57 public final class SuiteActions implements ActionProvider { 58 59 static Action [] getProjectActions(SuiteProject project) { 60 List <Action > actions = new ArrayList <Action >(); 61 actions.add(CommonProjectActions.newFileAction()); 62 actions.add(null); 63 actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_BUILD, NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_build"), null)); 64 actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_REBUILD, NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_rebuild"), null)); 65 actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_CLEAN, NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_clean"), null)); 66 actions.add(null); 67 actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_RUN, NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_run"), null)); 68 actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_DEBUG, NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_debug"), null)); 69 actions.add(null); 70 actions.add(ProjectSensitiveActions.projectCommandAction("build-zip", NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_zip"), null)); 71 actions.add(null); 72 actions.add(ProjectSensitiveActions.projectCommandAction("build-jnlp", NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_build_jnlp"), null)); 73 actions.add(ProjectSensitiveActions.projectCommandAction("run-jnlp", NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_run_jnlp"), null)); 74 actions.add(ProjectSensitiveActions.projectCommandAction("debug-jnlp", NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_debug_jnlp"), null)); 75 actions.add(null); 76 NbPlatform platform = project.getPlatform(true); if (platform != null && platform.getHarnessVersion() >= NbPlatform.HARNESS_VERSION_55u1) { 78 actions.add(ProjectSensitiveActions.projectCommandAction("build-mac", NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_mac"), null)); 79 actions.add(null); 80 } 81 if (platform != null && platform.getHarnessVersion() >= NbPlatform.HARNESS_VERSION_50u1) { actions.add(ProjectSensitiveActions.projectCommandAction("nbms", NbBundle.getMessage(SuiteActions.class, "SUITE_ACTION_nbms"), null)); actions.add(null); 84 } 85 actions.add(CommonProjectActions.setAsMainProjectAction()); 86 actions.add(CommonProjectActions.openSubprojectsAction()); 87 actions.add(CommonProjectActions.closeProjectAction()); 88 actions.add(null); 89 actions.add(SystemAction.get(FindAction.class)); 90 actions.add(null); 91 actions.add(CommonProjectActions.renameProjectAction()); 92 actions.add(CommonProjectActions.moveProjectAction()); 93 actions.add(CommonProjectActions.deleteProjectAction()); 94 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("Projects/Actions"); if (fo != null && fo.isFolder()) { 96 actions.add(null); 97 for (Object next : new FolderLookup(DataFolder.findFolder(fo)).getLookup().lookupAll(Object .class)) { 98 if (next instanceof Action ) { 99 actions.add((Action ) next); 100 } else if (next instanceof JSeparator ) { 101 actions.add(null); 102 } 103 } 104 } 105 actions.add(null); 106 actions.add(SystemAction.get(ToolsAction.class)); 107 actions.add(null); 108 actions.add(CommonProjectActions.customizeProjectAction()); 109 return actions.toArray(new Action [actions.size()]); 110 } 111 112 private final SuiteProject project; 113 114 public SuiteActions(SuiteProject project) { 115 this.project = project; 116 } 117 118 public String [] getSupportedActions() { 119 return new String [] { 120 ActionProvider.COMMAND_BUILD, 121 ActionProvider.COMMAND_CLEAN, 122 ActionProvider.COMMAND_REBUILD, 123 ActionProvider.COMMAND_RUN, 124 ActionProvider.COMMAND_DEBUG, 125 "build-zip", "build-jnlp", "run-jnlp", "debug-jnlp", "build-mac", "nbms", "profile", ActionProvider.COMMAND_RENAME, 133 ActionProvider.COMMAND_MOVE, 134 ActionProvider.COMMAND_DELETE 135 }; 136 } 137 138 public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException { 139 if (ActionProvider.COMMAND_DELETE.equals(command) || 140 ActionProvider.COMMAND_RENAME.equals(command) || 141 ActionProvider.COMMAND_MOVE.equals(command)) { 142 return true; 143 } else if (Arrays.asList(getSupportedActions()).contains(command)) { 144 return findBuildXml(project) != null; 145 } else { 146 throw new IllegalArgumentException (command); 147 } 148 } 149 150 public void invokeAction(String command, Lookup context) throws IllegalArgumentException { 151 if (ActionProvider.COMMAND_DELETE.equals(command)) { 152 DefaultProjectOperations.performDefaultDeleteOperation(project); 153 } else if (ActionProvider.COMMAND_RENAME.equals(command)) { 154 DefaultProjectOperations.performDefaultRenameOperation(project, null); 155 } else if (ActionProvider.COMMAND_MOVE.equals(command)) { 156 DefaultProjectOperations.performDefaultMoveOperation(project); 157 } else { 158 NbPlatform plaf = project.getPlatform(false); 159 if (plaf != null) { 160 int v = plaf.getHarnessVersion(); 161 if (v != NbPlatform.HARNESS_VERSION_UNKNOWN) { 162 for (Project p : project.getLookup().lookup(SubprojectProvider.class).getSubprojects()) { 163 if (v < ((NbModuleProject) p).getMinimumHarnessVersion()) { 164 ModuleActions.promptForNewerHarness(); 165 return; 166 } 167 } 168 } 169 } 170 try { 171 invokeActionImpl(command, context); 172 } catch (IOException e) { 173 Util.err.notify(e); 174 } 175 } 176 } 177 178 181 public ExecutorTask invokeActionImpl(String command, Lookup context) throws IllegalArgumentException , IOException { 182 String [] targetNames; 183 if (command.equals(ActionProvider.COMMAND_BUILD)) { 184 targetNames = new String [] {"build"}; } else if (command.equals(ActionProvider.COMMAND_CLEAN)) { 186 targetNames = new String [] {"clean"}; } else if (command.equals(ActionProvider.COMMAND_REBUILD)) { 188 targetNames = new String [] {"clean", "build"}; } else if (command.equals(ActionProvider.COMMAND_RUN)) { 190 targetNames = new String [] {"run"}; } else if (command.equals(ActionProvider.COMMAND_DEBUG)) { 192 targetNames = new String [] {"debug"}; } else if (command.equals("build-zip")) { if (promptForAppName(PROMPT_FOR_APP_NAME_MODE_ZIP)) { return null; 196 } 197 targetNames = new String [] {"build-zip"}; } else if (command.equals("build-jnlp")) { if (promptForAppName(PROMPT_FOR_APP_NAME_MODE_JNLP)) { 200 return null; 201 } 202 targetNames = new String [] {"build-jnlp"}; } else if (command.equals("run-jnlp")) { if (promptForAppName(PROMPT_FOR_APP_NAME_MODE_JNLP)) { 205 return null; 206 } 207 targetNames = new String [] {"run-jnlp"}; } else if (command.equals("debug-jnlp")) { if (promptForAppName(PROMPT_FOR_APP_NAME_MODE_JNLP)) { 210 return null; 211 } 212 targetNames = new String [] {"debug-jnlp"}; } else if (command.equals("build-mac")) { targetNames = new String [] {"build-mac"}; } else if (command.equals("nbms")) { targetNames = new String [] {"nbms"}; } else if (command.equals("profile")) { targetNames = new String [] {"profile"}; } else { 220 throw new IllegalArgumentException (command); 221 } 222 223 return ActionUtils.runTarget(findBuildXml(project), targetNames, null); 224 } 225 226 private static FileObject findBuildXml(SuiteProject project) { 227 return project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); 228 } 229 230 private static final int PROMPT_FOR_APP_NAME_MODE_JNLP = 0; 231 private static final int PROMPT_FOR_APP_NAME_MODE_ZIP = 1; 232 233 private boolean promptForAppName(int mode) { 234 String name = project.getEvaluator().getProperty("app.name"); if (name != null) { 236 return false; 237 } 238 239 String msg; 241 switch (mode) { 242 case PROMPT_FOR_APP_NAME_MODE_JNLP: 243 msg = NbBundle.getMessage(ModuleActions.class, "ERR_app_name_jnlp"); 244 break; 245 case PROMPT_FOR_APP_NAME_MODE_ZIP: 246 msg = NbBundle.getMessage(ModuleActions.class, "ERR_app_name_zip"); 247 break; 248 default: 249 throw new AssertionError (mode); 250 } 251 if (UIUtil.showAcceptCancelDialog( 252 NbBundle.getMessage(ModuleActions.class, "TITLE_app_name"), 253 msg, 254 NbBundle.getMessage(ModuleActions.class, "LBL_configure_app_name"), 255 null, 256 NotifyDescriptor.WARNING_MESSAGE)) { 257 SuiteCustomizer cpi = project.getLookup().lookup(SuiteCustomizer.class); 258 cpi.showCustomizer(SuiteCustomizer.APPLICATION, SuiteCustomizer.APPLICATION_CREATE_STANDALONE_APPLICATION); 259 } 260 return true; 261 } 262 263 } 264 | Popular Tags |