1 19 20 package org.netbeans.modules.scripting.php.webproject; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Properties ; 27 import org.apache.tools.ant.module.api.support.ActionUtils; 28 import org.netbeans.modules.scripting.php.dbginterface.api.DbgDebugger; 29 import org.netbeans.modules.scripting.php.dbginterface.api.DbgSourceMap; 30 import org.netbeans.modules.scripting.php.dbginterface.api.DebuggerStartException; 31 import org.netbeans.spi.project.ActionProvider; 32 import org.netbeans.spi.project.ui.support.DefaultProjectOperations; 33 import org.openide.ErrorManager; 34 import org.openide.awt.HtmlBrowser; 35 import org.openide.execution.ExecutorTask; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.loaders.DataFolder; 39 import org.openide.loaders.DataObject; 40 import org.openide.loaders.DataObjectNotFoundException; 41 import org.openide.util.Lookup; 42 43 47 public class PhpProjectActionProvider implements ActionProvider { 48 private final PhpProject project; 49 50 private static final String [] supportedActions = { 51 COMMAND_RUN, 52 COMMAND_DEBUG, 53 COMMAND_DELETE, 54 COMMAND_COPY, 55 COMMAND_MOVE, 56 COMMAND_RENAME 57 }; 58 59 static int debugSessionNo = 1; 60 61 62 public PhpProjectActionProvider(PhpProject project) { 63 this.project = project; 64 } 65 66 public String [] getSupportedActions() { 67 return supportedActions; 68 } 69 70 public void invokeAction(String command, Lookup context) throws IllegalArgumentException { 71 String urlSuffix = ""; 72 String useSourceDir = project.getProperty(PhpProjectProperties.USE_SOURCE_DIR); 73 boolean openBrowser = true; 74 75 System.err.println("mw PhpProjectActionProvider useSourceDir= " + useSourceDir); 76 77 78 if (COMMAND_DELETE.equals(command)) { 79 DefaultProjectOperations.performDefaultDeleteOperation(project); 80 return; 81 } 82 83 if (COMMAND_COPY.equals(command)) { 84 DefaultProjectOperations.performDefaultCopyOperation(project); 85 return; 86 } 87 88 if (COMMAND_MOVE.equals(command)) { 89 DefaultProjectOperations.performDefaultMoveOperation(project); 90 return; 91 } 92 93 if (COMMAND_RENAME.equals(command)) { 94 DefaultProjectOperations.performDefaultRenameOperation(project, null 95 ); 96 return; 97 } 98 99 if ((COMMAND_DEBUG.equals(command))) { 100 URL serverBaseUrl = null; 101 String serverTargetDir = project.getProperty(PhpProjectProperties.TARGET_DIR); 102 FileObject baseDirFO = project.getProjectDirectory(); 103 104 try { 105 serverBaseUrl = new URL (project.getProperty(PhpProjectProperties.URL)); 106 } 107 catch (MalformedURLException mue) { 108 ErrorManager.getDefault().notify(ErrorManager.WARNING, mue); 109 } 110 111 DbgSourceMap sourceMap = new DbgSourceMap(serverBaseUrl, serverTargetDir, 112 baseDirFO); 113 114 try { 115 urlSuffix = "?DBGSESSID=" + debugSessionNo++ + "@" + 116 DbgDebugger.startListening(sourceMap); 117 118 System.err.println("mw Debug urlSuffix= " + urlSuffix); 119 } 120 catch (DebuggerStartException ex) { 121 ErrorManager.getDefault().notify(ErrorManager.WARNING, ex); 122 } 123 124 } 125 126 if (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command)) { 127 if (!Boolean.parseBoolean(useSourceDir)) { 128 openBrowser = false; 129 130 try { 131 Properties p = new Properties (); 132 String [] targetNames = new String [] { "copy-hack" }; 133 FileObject buildFo = project.getProjectDirectory().getFileObject("nbproject/copyHack.xml"); 134 135 p.put("srcDir", FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath()); 136 p.put("targetDir", project.getProperty(PhpProjectProperties.TARGET_DIR)); 137 138 p.list(System.err); 139 140 if (buildFo != null) { 141 ExecutorTask task = ActionUtils.runTarget(buildFo, targetNames, p); 142 143 if (task.result() == 0) { 144 openBrowser = true; 145 } 146 } 147 } catch (DataObjectNotFoundException ex) { 148 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 149 } catch (IOException ioe) { 150 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 151 } 152 } 153 154 if (openBrowser) { 155 try { 156 String url = project.getProperty(PhpProjectProperties.URL); 157 158 HtmlBrowser.URLDisplayer.getDefault().showURL(new URL (url + urlSuffix)); 159 } catch (MalformedURLException ex) { 160 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 161 } 162 } 163 164 return; 165 } 166 167 throw new UnsupportedOperationException ("Not supported yet."); 168 } 169 170 public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException { 171 if (COMMAND_DEBUG.equals(command)) { 172 return true; 173 } 174 else if (COMMAND_RUN.equals(command)) { 175 return true; 176 } 177 else { 178 return true; 180 } 181 } 182 } 183 | Popular Tags |