Changeset 3468 for devel-tools/trunk
- Timestamp:
- Mar 7, 2008, 4:00:00 PM (13 years ago)
- Location:
- devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/plugin.xml
r3463 r3468 12 12 point="org.eclipse.debug.core.launchConfigurationTypes"> 13 13 <launchConfigurationType 14 delegate="org. refal.plus.rfpdt.launch.RfpLaunchConfigurationDelegate"14 delegate="org.eclipse.jdt.launching.JavaLaunchDelegate" 15 15 id="org.refal.plus.rfpdt.launch.refal_plus" 16 16 modes="run, debug" -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpLaunchShortcut.java
r3467 r3468 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collections;5 4 import java.util.List; 6 5 7 6 import org.eclipse.core.resources.IFile; 8 import org.eclipse.core.resources.IProject;9 7 import org.eclipse.core.runtime.CoreException; 10 8 import org.eclipse.debug.core.DebugPlugin; … … 17 15 import org.eclipse.debug.ui.ILaunchShortcut; 18 16 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 19 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;20 17 import org.eclipse.jface.dialogs.ErrorDialog; 21 18 import org.eclipse.jface.dialogs.MessageDialog; … … 25 22 import org.eclipse.swt.widgets.Display; 26 23 import org.eclipse.ui.IEditorPart; 24 import org.eclipse.ui.IWorkbenchPage; 27 25 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 28 26 import org.refal.plus.rfpdt.editor.RfpEditor; … … 35 33 public class RfpLaunchShortcut implements ILaunchShortcut { 36 34 public void launch (ISelection selection, String mode) { 37 IFile module = this.getResourceFromSelection(selection);35 IFile module = getResourceFromSelection(selection); 38 36 launch: { 39 37 if (module == null) … … 42 40 if (!moduleName.endsWith(".rf") && !moduleName.endsWith(".rfi")) 43 41 break launch; 44 this.launch(module, mode);42 launch(module, mode); 45 43 return; 46 44 } … … 50 48 51 49 public void launch (IEditorPart editor, String mode) { 52 IFile module = this.getResourceFromEditor(editor);50 IFile module = getResourceFromEditor(editor); 53 51 if (module != null) { 54 this.launch(module, mode);52 launch(module, mode); 55 53 return; 56 54 } … … 59 57 } 60 58 61 protected IFile getResourceFromSelection (ISelection selection) { 59 static void createConfiguration (ILaunchConfigurationWorkingCopy config) { 60 createConfiguration(config, getResource()); 61 } 62 63 private static IFile getResourceFromSelection (ISelection selection) { 62 64 if (selection.isEmpty()) 63 65 return null; … … 70 72 } 71 73 72 pr otectedIFile getResourceFromEditor (IEditorPart part) {74 private static IFile getResourceFromEditor (IEditorPart part) { 73 75 if (part == null || !(part instanceof RfpEditor)) 74 76 return null; 75 77 RfpEditor editor = (RfpEditor) part; 76 78 return (IFile) editor.getEditorInput().getAdapter(IFile.class); 79 } 80 81 private static String getWorkingDirectory (IFile module) { 82 return module.getParent().getFullPath().makeRelative().toString(); 83 } 84 85 private static String getModuleName (IFile module) { 86 return module.getProjectRelativePath().removeFileExtension().toString().replace('/', '.'); 77 87 } 78 88 … … 82 92 * @return a re-useable config or <code>null</code> if none 83 93 */ 84 pr otectedILaunchConfiguration findLaunchConfiguration (IFile module, String mode) {85 ILaunchConfigurationType configType = this.getLaunchConfigType();86 List<ILaunchConfiguration> candidateConfigs = Collections.emptyList();94 private static ILaunchConfiguration findLaunchConfiguration (IFile module, String mode) { 95 ILaunchConfigurationType configType = getLaunchConfigType(); 96 ArrayList<ILaunchConfiguration> candidateConfigs = new ArrayList<ILaunchConfiguration>(); 87 97 try { 88 98 ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations( 89 99 configType); 90 candidateConfigs = new ArrayList<ILaunchConfiguration>(configs.length); 91 for (int i = 0; i < configs.length; i++) { 92 ILaunchConfiguration config = configs[i]; 100 for (ILaunchConfiguration config : configs) 93 101 if (config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, "").equals( 94 102 getModuleName(module)) 95 103 && config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "").equals( 96 getWorkingDirectory(module))) {104 getWorkingDirectory(module))) 97 105 candidateConfigs.add(config); 98 }99 }100 106 } catch (CoreException e) { 101 107 System.err.println(e); … … 109 115 int candidateCount = candidateConfigs.size(); 110 116 if (candidateCount < 1) { 111 return this.createConfiguration(module);117 return createConfiguration(module); 112 118 } else if (candidateCount == 1) { 113 119 return (ILaunchConfiguration) candidateConfigs.get(0); … … 117 123 * method returns null, since cancelling the dialog should also cancel launching anything. 118 124 */ 119 ILaunchConfiguration config = this.chooseConfiguration(candidateConfigs, mode);125 ILaunchConfiguration config = chooseConfiguration(candidateConfigs, mode); 120 126 if (config != null) { 121 127 return config; … … 129 135 * chosen config, or <code>null</code> if the user cancelled the dialog. 130 136 */ 131 pr otectedILaunchConfiguration chooseConfiguration (List<ILaunchConfiguration> configList, String mode) {137 private static ILaunchConfiguration chooseConfiguration (List<ILaunchConfiguration> configList, String mode) { 132 138 IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation(); 133 139 ElementListSelectionDialog dialog = new ElementListSelectionDialog(LaunchingPlugin.getShell(), labelProvider); … … 151 157 * Launches a configuration for the given module 152 158 */ 153 pr otectedvoid launch (IFile module, String mode) {159 private static void launch (IFile module, String mode) { 154 160 ILaunchConfiguration config = findLaunchConfiguration(module, mode); 155 if (config != null) {161 if (config != null) 156 162 DebugUITools.launch(config, mode); 157 }158 }159 160 protected List<String> asMementos (IRuntimeClasspathEntry[] entries) throws CoreException {161 List<String> mementos = new ArrayList<String>(entries.length);162 for (IRuntimeClasspathEntry entry : entries) {163 mementos.add(entry.getMemento());164 }165 return mementos;166 163 } 167 164 … … 169 166 * Create & return a new configuration based on the specified <code>IFile</code>. 170 167 */ 171 pr otectedILaunchConfiguration createConfiguration (IFile module) {168 private static ILaunchConfiguration createConfiguration (IFile module) { 172 169 ILaunchConfiguration config = null; 173 170 ILaunchConfigurationWorkingCopy wc = null; 174 171 try { 175 ILaunchConfigurationType configType = this.getLaunchConfigType();176 wc = configType.newInstance(null, this.getLaunchManager().generateUniqueLaunchConfigurationNameFrom(172 ILaunchConfigurationType configType = getLaunchConfigType(); 173 wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom( 177 174 module.getName())); 178 175 } catch (CoreException exception) { 179 this.reportCreatingConfiguration(exception); 180 return null; 181 } 182 IProject project = module.getProject(); 183 // TODO do not hardcode the attributes in 2 places (see RfpTabGroup) 184 wc.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName()); 185 wc.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, getModuleName(module)); 186 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, 187 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 188 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, getWorkingDirectory(module)); 176 reportCreatingConfiguration(exception); 177 return null; 178 } 179 createConfiguration(wc, module); 189 180 try { 190 181 config = wc.doSave(); 191 182 } catch (CoreException exception) { 192 this.reportCreatingConfiguration(exception);183 reportCreatingConfiguration(exception); 193 184 } 194 185 return config; 195 186 } 196 187 197 protected void reportCreatingConfiguration (final CoreException exception) { 188 private static void createConfiguration (ILaunchConfigurationWorkingCopy config, IFile module) { 189 if (module != null) { 190 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, module.getProject().getName()); 191 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, getModuleName(module)); 192 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, getWorkingDirectory(module)); 193 } 194 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, 195 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 196 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, 197 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 198 } 199 200 private static IFile getResource () { 201 IWorkbenchPage page = LaunchingPlugin.getActivePage(); 202 if (page == null) 203 return null; 204 ISelection selection = page.getSelection(); 205 if (selection instanceof IStructuredSelection) 206 return getResourceFromSelection((IStructuredSelection) selection); 207 return getResourceFromEditor(page.getActiveEditor()); 208 } 209 210 private static void reportCreatingConfiguration (final CoreException exception) { 198 211 Display.getDefault().asyncExec(new Runnable() { 199 212 public void run () { … … 207 220 * Returns the local java launch config type 208 221 */ 209 pr otectedILaunchConfigurationType getLaunchConfigType () {210 return this.getLaunchManager().getLaunchConfigurationType(211 IRfpLaunchConfigurationConstants.LAUNCH_CONFIGURATION_TYPE);212 } 213 214 pr otectedILaunchManager getLaunchManager () {222 private static ILaunchConfigurationType getLaunchConfigType () { 223 return getLaunchManager() 224 .getLaunchConfigurationType(IRfpLaunchConfigurationConstants.LAUNCH_CONFIGURATION_TYPE); 225 } 226 227 private static ILaunchManager getLaunchManager () { 215 228 return DebugPlugin.getDefault().getLaunchManager(); 216 229 } 217 218 static String getWorkingDirectory (IFile module) {219 return module.getParent().getFullPath().makeRelative().toString();220 }221 222 static String getModuleName (IFile module) {223 return module.getProjectRelativePath().removeFileExtension().toString().replace('/', '.');224 }225 230 } -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpRefalMainTab.java
r3449 r3468 156 156 157 157 public boolean isValid (ILaunchConfiguration config) { 158 159 158 setErrorMessage(null); 160 159 setMessage(null); 161 162 160 String name = fProjectText.getText().trim(); 163 161 if (name.length() == 0) { … … 170 168 return false; 171 169 } 172 173 170 return true; 174 171 } -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpTabGroup.java
r3467 r3468 1 1 package org.refal.plus.rfpdt.launch.ui; 2 2 3 import org.eclipse.core.resources.IFile;4 import org.eclipse.core.resources.IProject;5 3 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 6 4 import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; … … 12 10 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab; 13 11 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab; 14 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;15 import org.eclipse.jface.viewers.ISelection;16 import org.eclipse.jface.viewers.IStructuredSelection;17 import org.eclipse.ui.IWorkbenchPage;18 import org.refal.plus.rfpdt.launch.IRfpLaunchConfigurationConstants;19 import org.refal.plus.rfpdt.launch.LaunchingPlugin;20 12 21 13 public class RfpTabGroup extends AbstractLaunchConfigurationTabGroup { … … 29 21 public void setDefaults (ILaunchConfigurationWorkingCopy config) { 30 22 super.setDefaults(config); 31 IProject project = null; 32 IFile resource = this.getResource(); 33 if (resource != null) { 34 project = resource.getProject(); 35 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName()); 36 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, RfpLaunchShortcut 37 .getModuleName(resource)); 38 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, RfpLaunchShortcut 39 .getWorkingDirectory(resource)); 40 } 41 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, 42 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 43 // helper.setClasspathDefaults(config); 44 // This is tricky: without setting ATTR_PROJECT_NAME to the empty 45 // string, the project is expected to be a Java project, which in our 46 // case is not necessarily so, and some methods validate on the 47 // existance of a Java project with that name. 48 //config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); 49 } 50 51 private IFile getResource () { 52 IWorkbenchPage page = LaunchingPlugin.getActivePage(); 53 if (page == null) 54 return null; 55 ISelection selection = page.getSelection(); 56 RfpLaunchShortcut helper = new RfpLaunchShortcut(); 57 if (selection instanceof IStructuredSelection) 58 return helper.getResourceFromSelection((IStructuredSelection) selection); 59 return helper.getResourceFromEditor(page.getActiveEditor()); 23 RfpLaunchShortcut.createConfiguration(config); 60 24 } 61 25 }
Note: See TracChangeset
for help on using the changeset viewer.