Changeset 3449
- Timestamp:
- Feb 28, 2008, 1:25:34 PM (13 years ago)
- Location:
- devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/IRfpLaunchConfigurationConstants.java
r3444 r3449 5 5 /** 6 6 * Constant definitions for Refal Plus launch configurations. 7 *8 7 * Constant definitions only; not to be implemented. 9 8 */ 10 public interface IRfpLaunchConfigurationConstants /*extends IJavaLaunchConfigurationConstants*/ { 11 12 public static final String ATTR_PROJECT_NAME = "org.refal.plus.rfpdt.launch.project_name"; 13 14 public static final String ATTR_MODULE_NAME = IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; 15 16 public static final String PLUGIN_ID = "org.refal.plus.rfpdt.launch"; 17 18 public static final String LAUNCH_CONFIGURATION_TYPE = "org.refal.plus.rfpdt.launch.refal_plus"; 19 20 public static final String CLASSPATH_PROVIDER = "org.refal.plus.rfpdt.launch.rfp_classpath"; 21 9 public interface IRfpLaunchConfigurationConstants /* extends IJavaLaunchConfigurationConstants */{ 10 public static final String ATTR_PROJECT_NAME = "org.refal.plus.rfpdt.launch.project_name"; 11 public static final String ATTR_MODULE_NAME = IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME; 12 public static final String PLUGIN_ID = "org.refal.plus.rfpdt.launch"; 13 public static final String LAUNCH_CONFIGURATION_TYPE = "org.refal.plus.rfpdt.launch.refal_plus"; 14 public static final String CLASSPATH_PROVIDER = "org.refal.plus.rfpdt.launch.rfp_classpath"; 22 15 } -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/LaunchingPlugin.java
r3444 r3449 11 11 12 12 public class LaunchingPlugin extends AbstractUIPlugin { 13 // The shared instance. 14 private static LaunchingPlugin plugin; 13 15 14 // The shared instance. 15 private static LaunchingPlugin plugin; 16 private ResourceBundle resourceBundle; 16 17 17 private ResourceBundle resourceBundle; 18 public LaunchingPlugin () { 19 super(); 20 plugin = this; 21 try { 22 resourceBundle = ResourceBundle.getBundle("org.refal.plus.rfpdt.launch.LaunchingPluginResources"); 23 } catch (MissingResourceException x) { 24 resourceBundle = null; 25 } 26 } 18 27 19 public LaunchingPlugin() { 20 super(); 21 plugin = this; 22 try { 23 resourceBundle = ResourceBundle 24 .getBundle("org.refal.plus.rfpdt.launch.LaunchingPluginResources"); 25 } catch (MissingResourceException x) { 26 resourceBundle = null; 27 } 28 } 28 /** 29 * This method is called upon plug-in activation 30 */ 31 public void start (BundleContext context) throws Exception { 32 super.start(context); 33 } 29 34 30 31 * This method is called upon plug-in activation 32 33 public void start(BundleContext context) throws Exception {34 super.start(context);35 35 /** 36 * This method is called when the plug-in is stopped 37 */ 38 public void stop (BundleContext context) throws Exception { 39 super.stop(context); 40 } 36 41 37 38 * This method is called when the plug-in is stopped 39 40 public void stop(BundleContext context) throws Exception{41 super.stop(context);42 42 /** 43 * Returns the shared instance. 44 */ 45 public static LaunchingPlugin getDefault () { 46 return plugin; 47 } 43 48 44 /** 45 * Returns the shared instance. 46 */ 47 public static LaunchingPlugin getDefault() { 48 return plugin; 49 } 49 /** 50 * Returns the string from the plugin's resource bundle, or 'key' if not found. 51 */ 52 public static String getResourceString (String key) { 53 ResourceBundle bundle = LaunchingPlugin.getDefault().getResourceBundle(); 54 try { 55 return (bundle != null) ? bundle.getString(key) : key; 56 } catch (MissingResourceException e) { 57 return key; 58 } 59 } 50 60 51 /** 52 * Returns the string from the plugin's resource bundle, or 'key' if not 53 * found. 54 */ 55 public static String getResourceString(String key) { 56 ResourceBundle bundle = LaunchingPlugin.getDefault() 57 .getResourceBundle(); 58 try { 59 return (bundle != null) ? bundle.getString(key) : key; 60 } catch (MissingResourceException e) { 61 return key; 62 } 63 } 61 /** 62 * Returns the plugin's resource bundle, 63 */ 64 public ResourceBundle getResourceBundle () { 65 return resourceBundle; 66 } 64 67 65 /** 66 * Returns the plugin's resource bundle, 67 */ 68 public ResourceBundle getResourceBundle() { 69 return resourceBundle; 70 } 68 /** 69 * Convenience method to get the window that owns this action's Shell. 70 */ 71 public static Shell getShell () { 72 IWorkbenchWindow window = getActiveWorkbenchWindow(); 73 if (window != null) { 74 return window.getShell(); 75 } 76 return null; 77 } 71 78 72 /** 73 * Convenience method to get the window that owns this action's Shell. 74 */ 75 public static Shell getShell() { 76 IWorkbenchWindow window = getActiveWorkbenchWindow(); 77 if (window != null) { 78 return window.getShell(); 79 } 80 return null; 81 } 79 public static IWorkbenchWindow getActiveWorkbenchWindow () { 80 return getDefault().getWorkbench().getActiveWorkbenchWindow(); 81 } 82 82 83 public static IWorkbenchWindow getActiveWorkbenchWindow() { 84 return getDefault().getWorkbench().getActiveWorkbenchWindow(); 85 } 86 87 public static IWorkbenchPage getActivePage() { 88 IWorkbenchWindow w = getActiveWorkbenchWindow(); 89 if (w != null) { 90 return w.getActivePage(); 91 } 92 return null; 93 } 83 public static IWorkbenchPage getActivePage () { 84 IWorkbenchWindow w = getActiveWorkbenchWindow(); 85 if (w != null) { 86 return w.getActivePage(); 87 } 88 return null; 89 } 94 90 } -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/RfpClasspathProvider.java
r3444 r3449 6 6 import java.util.Arrays; 7 7 import java.util.List; 8 8 9 import org.eclipse.core.resources.ResourcesPlugin; 9 10 import org.eclipse.core.runtime.CoreException; … … 20 21 import org.eclipse.jdt.launching.JavaRuntime; 21 22 import org.eclipse.jdt.launching.StandardClasspathProvider; 22 //import org.eclipse.osgi.baseadaptor.BaseData;23 //import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;24 //import org.eclipse.osgi.framework.internal.core.BundleHost;25 23 import org.osgi.framework.Bundle; 26 24 import org.refal.plus.rfpdt.core.RfpCorePlugin; 27 25 28 26 public class RfpClasspathProvider extends StandardClasspathProvider { 29 27 private List<IRuntimeClasspathEntry> defaultUserClassPath (ILaunchConfiguration configuration) throws CoreException { 30 28 List<IPath> paths = new ArrayList<IPath>(); 31 29 String projectName = configuration.getAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); … … 35 33 Bundle b = Platform.getBundle("org.refal.plus"); 36 34 // TODO: 37 // if (b instanceof BundleHost) {38 // 39 // 40 // 41 // }35 // if (b instanceof BundleHost) { 36 // BundleFile file = ((BaseData) ((BundleHost) b).getBundleData()).getBundleFile(); 37 // String x = file.getBaseFile().getAbsolutePath(); 38 // x.charAt(0); 39 // } 42 40 try { 43 41 URL url = b.getEntry("/bin"); … … 96 94 } 97 95 98 public IRuntimeClasspathEntry[] computeUnresolvedClasspath (ILaunchConfiguration configuration) throws CoreException { 96 public IRuntimeClasspathEntry[] computeUnresolvedClasspath (ILaunchConfiguration configuration) 97 throws CoreException { 99 98 IRuntimeClasspathEntry[] entries = super.computeUnresolvedClasspath(configuration); 100 99 boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/RfpLaunchConfigurationDelegate.java
r3444 r3449 11 11 12 12 public class RfpLaunchConfigurationDelegate extends JavaLaunchDelegate { 13 @Override14 public boolean isStopInMain (ILaunchConfiguration configuration) throws CoreException {15 return false; // TODO: add checkbox to run/debug configuration dialog.16 }17 18 13 /** 19 14 * Implementation from LaunchConfigurationDelegate (avoiding java-specific checks from JavaLaunchDelegate). -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpLaunchShortcut.java
r3444 r3449 35 35 */ 36 36 public class RfpLaunchShortcut implements ILaunchShortcut { 37 38 public void launch(ISelection selection, String mode) { 39 IFile module = this.getResourceFromSelection(selection); 40 launch: { 41 if (module == null) 42 break launch; 43 String moduleName = module.getName(); 44 if (!moduleName.endsWith(".rf") && !moduleName.endsWith(".rfi")) 45 break launch; 46 this.launch(module, mode); 47 return; 48 } 49 MessageDialog.openError(LaunchingPlugin.getShell(), 50 "Cannot Launch Refal Plus application", 51 "The selection is not a Refal Plus file. Please select one .rf file to launch."); 52 } 53 54 public void launch(IEditorPart editor, String mode) { 55 IFile module = this.getResourceFromEditor(editor); 56 if (module != null) { 57 this.launch(module, mode); 58 return; 59 } 60 MessageDialog.openError(LaunchingPlugin.getShell(), 61 "Cannot Launch Refal Plus application", 62 "The selection is not a Refal Plus file. Please select one .rf file to launch."); 63 } 64 65 protected IFile getResourceFromSelection(ISelection selection) { 66 if (selection.isEmpty()) 67 return null; 68 if(!(selection instanceof IStructuredSelection)) 69 return null; 70 Object selectedObject = ((IStructuredSelection)selection).getFirstElement(); 71 if (selectedObject instanceof IFile) 72 return (IFile) selectedObject; 73 return null; 74 } 75 76 protected IFile getResourceFromEditor(IEditorPart part) { 77 if (part == null || !(part instanceof RfpEditor)) 78 return null; 79 RfpEditor editor = (RfpEditor) part; 80 return (IFile) editor.getEditorInput().getAdapter(IFile.class); 81 } 82 83 /** 84 * Locate a configuration to relaunch for the given type. If one cannot be 85 * found, create one. 86 * 87 * @return a re-useable config or <code>null</code> if none 88 */ 89 protected ILaunchConfiguration findLaunchConfiguration(IFile module, String mode) { 90 ILaunchConfigurationType configType = this.getLaunchConfigType(); 91 List<ILaunchConfiguration> candidateConfigs = Collections.emptyList(); 92 try { 93 ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType); 94 candidateConfigs = new ArrayList<ILaunchConfiguration>(configs.length); 95 for (int i = 0; i < configs.length; i++) { 96 ILaunchConfiguration config = configs[i]; 97 if (config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, "").equals(getModuleName(module)) 98 && config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "").equals( 99 this.getWorkingDirectory(module))) 100 { 101 candidateConfigs.add(config); 102 } 103 } 104 } catch (CoreException e) { 105 System.err.println(e); 106 //CorePlugin.log(e); 107 } 108 /* 109 * If there are no existing configs associated with the IFile, create 110 * one. If there is exactly one config associated with the IFile, return 111 * it. Otherwise, if there is more than one config associated with the 112 * IFile, prompt the user to choose one. 113 */ 114 int candidateCount = candidateConfigs.size(); 115 if (candidateCount < 1) { 116 return this.createConfiguration(module); 117 } else if (candidateCount == 1) { 118 return (ILaunchConfiguration) candidateConfigs.get(0); 119 } else { 120 /* 121 * Prompt the user to choose a config. A null result means the user 122 * cancelled the dialog, in which case this method returns null, 123 * since cancelling the dialog should also cancel launching 124 * anything. 125 */ 126 ILaunchConfiguration config = this.chooseConfiguration(candidateConfigs, mode); 127 if (config != null) { 128 return config; 129 } 130 } 131 return null; 132 } 133 134 /** 135 * Show a selection dialog that allows the user to choose one of the 136 * specified launch configurations. Return the chosen config, or 137 * <code>null</code> if the user cancelled the dialog. 138 */ 139 protected ILaunchConfiguration chooseConfiguration(List<ILaunchConfiguration> configList, String mode) { 140 IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation(); 141 ElementListSelectionDialog dialog = new ElementListSelectionDialog(LaunchingPlugin.getShell(), labelProvider); 142 dialog.setElements(configList.toArray()); 143 dialog.setTitle("Launch Configuration Selection"); 144 if (mode.equals(ILaunchManager.DEBUG_MODE)) { 145 dialog.setMessage("Choose a launch configuration to deb&ug"); 146 } else { 147 dialog.setMessage("Choose a launch configuration to r&un:"); 148 } 149 dialog.setMultipleSelection(false); 150 int result = dialog.open(); 151 labelProvider.dispose(); 152 if (result == Window.OK) { 153 return (ILaunchConfiguration) dialog.getFirstResult(); 154 } 155 return null; 156 } 157 158 /** 159 * Launches a configuration for the given module 160 */ 161 protected void launch(IFile module, String mode) { 162 ILaunchConfiguration config = findLaunchConfiguration(module, mode); 163 if (config != null) { 164 DebugUITools.launch(config, mode); 165 } 166 } 167 168 public void setClasspathDefaults(ILaunchConfigurationWorkingCopy configuration) { 169 try { 170 IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); 171 // Set ATTR_DEFAULT_CLASSPATH to false here, because we want to use 172 // a custom class path. 173 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); 174 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, this.asMementos(entries)); 175 } catch (CoreException e) { 176 //CorePlugin.log(e); // TODO can we do better? Like: 177 // JDIDebugUIPlugin.errorDialog(LauncherMessages.getString("JavaClasspathTab.Unable_to_save_classpath_1"), 178 // e); //$NON-NLS-1$ 179 return; 180 } 181 } 182 183 protected List<String> asMementos(IRuntimeClasspathEntry[] entries) throws CoreException { 184 List<String> mementos = new ArrayList<String>(entries.length); 185 for (IRuntimeClasspathEntry entry : entries) { 186 mementos.add(entry.getMemento()); 187 } 188 return mementos; 189 } 190 191 /** 192 * Create & return a new configuration based on the specified 193 * <code>IFile</code>. 194 */ 195 protected ILaunchConfiguration createConfiguration(IFile module) { 196 ILaunchConfiguration config = null; 197 ILaunchConfigurationWorkingCopy wc = null; 198 try { 199 ILaunchConfigurationType configType = this.getLaunchConfigType(); 200 wc = configType.newInstance(null, this.getLaunchManager().generateUniqueLaunchConfigurationNameFrom(module.getName())); 201 } catch (CoreException exception) { 202 this.reportCreatingConfiguration(exception); 203 return null; 204 } 205 IProject project = module.getProject(); 206 // TODO do not hardcode the attributes in 2 places (see RfpTabGroup) 207 wc.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName()); 208 wc.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, getModuleName(module)); 209 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, 210 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 211 setClasspathDefaults(wc); 212 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, this.getWorkingDirectory(module)); 213 try { 214 config = wc.doSave(); 215 } catch (CoreException exception) { 216 this.reportCreatingConfiguration(exception); 217 } 218 return config; 219 } 220 221 protected String getWorkingDirectory(IFile rfFile) { 222 return rfFile.getParent().getFullPath().makeRelative().toString(); 223 } 224 225 protected void reportCreatingConfiguration(final CoreException exception) { 226 Display.getDefault().asyncExec(new Runnable() { 227 public void run() { 228 ErrorDialog.openError(LaunchingPlugin.getShell(), "Cannot Create Configuration", 229 "An exception occurred attempting to create launch configuration", exception.getStatus()); 230 } 231 }); 232 } 233 234 /** 235 * Returns the local java launch config type 236 */ 237 protected ILaunchConfigurationType getLaunchConfigType() { 238 return this.getLaunchManager().getLaunchConfigurationType(IRfpLaunchConfigurationConstants.LAUNCH_CONFIGURATION_TYPE); 239 } 240 241 protected ILaunchManager getLaunchManager() { 242 return DebugPlugin.getDefault().getLaunchManager(); 243 } 244 245 static String getModuleName(IFile module) { 37 public void launch (ISelection selection, String mode) { 38 IFile module = this.getResourceFromSelection(selection); 39 launch: { 40 if (module == null) 41 break launch; 42 String moduleName = module.getName(); 43 if (!moduleName.endsWith(".rf") && !moduleName.endsWith(".rfi")) 44 break launch; 45 this.launch(module, mode); 46 return; 47 } 48 MessageDialog.openError(LaunchingPlugin.getShell(), "Cannot Launch Refal Plus application", 49 "The selection is not a Refal Plus file. Please select one .rf file to launch."); 50 } 51 52 public void launch (IEditorPart editor, String mode) { 53 IFile module = this.getResourceFromEditor(editor); 54 if (module != null) { 55 this.launch(module, mode); 56 return; 57 } 58 MessageDialog.openError(LaunchingPlugin.getShell(), "Cannot Launch Refal Plus application", 59 "The selection is not a Refal Plus file. Please select one .rf file to launch."); 60 } 61 62 protected IFile getResourceFromSelection (ISelection selection) { 63 if (selection.isEmpty()) 64 return null; 65 if (!(selection instanceof IStructuredSelection)) 66 return null; 67 Object selectedObject = ((IStructuredSelection) selection).getFirstElement(); 68 if (selectedObject instanceof IFile) 69 return (IFile) selectedObject; 70 return null; 71 } 72 73 protected IFile getResourceFromEditor (IEditorPart part) { 74 if (part == null || !(part instanceof RfpEditor)) 75 return null; 76 RfpEditor editor = (RfpEditor) part; 77 return (IFile) editor.getEditorInput().getAdapter(IFile.class); 78 } 79 80 /** 81 * Locate a configuration to relaunch for the given type. If one cannot be found, create one. 82 * 83 * @return a re-useable config or <code>null</code> if none 84 */ 85 protected ILaunchConfiguration findLaunchConfiguration (IFile module, String mode) { 86 ILaunchConfigurationType configType = this.getLaunchConfigType(); 87 List<ILaunchConfiguration> candidateConfigs = Collections.emptyList(); 88 try { 89 ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations( 90 configType); 91 candidateConfigs = new ArrayList<ILaunchConfiguration>(configs.length); 92 for (int i = 0; i < configs.length; i++) { 93 ILaunchConfiguration config = configs[i]; 94 if (config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, "").equals( 95 getModuleName(module)) 96 && config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "").equals( 97 this.getWorkingDirectory(module))) { 98 candidateConfigs.add(config); 99 } 100 } 101 } catch (CoreException e) { 102 System.err.println(e); 103 // CorePlugin.log(e); 104 } 105 /* 106 * If there are no existing configs associated with the IFile, create one. If there is exactly one config 107 * associated with the IFile, return it. Otherwise, if there is more than one config associated with the IFile, 108 * prompt the user to choose one. 109 */ 110 int candidateCount = candidateConfigs.size(); 111 if (candidateCount < 1) { 112 return this.createConfiguration(module); 113 } else if (candidateCount == 1) { 114 return (ILaunchConfiguration) candidateConfigs.get(0); 115 } else { 116 /* 117 * Prompt the user to choose a config. A null result means the user cancelled the dialog, in which case this 118 * method returns null, since cancelling the dialog should also cancel launching anything. 119 */ 120 ILaunchConfiguration config = this.chooseConfiguration(candidateConfigs, mode); 121 if (config != null) { 122 return config; 123 } 124 } 125 return null; 126 } 127 128 /** 129 * Show a selection dialog that allows the user to choose one of the specified launch configurations. Return the 130 * chosen config, or <code>null</code> if the user cancelled the dialog. 131 */ 132 protected ILaunchConfiguration chooseConfiguration (List<ILaunchConfiguration> configList, String mode) { 133 IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation(); 134 ElementListSelectionDialog dialog = new ElementListSelectionDialog(LaunchingPlugin.getShell(), labelProvider); 135 dialog.setElements(configList.toArray()); 136 dialog.setTitle("Launch Configuration Selection"); 137 if (mode.equals(ILaunchManager.DEBUG_MODE)) { 138 dialog.setMessage("Choose a launch configuration to deb&ug"); 139 } else { 140 dialog.setMessage("Choose a launch configuration to r&un:"); 141 } 142 dialog.setMultipleSelection(false); 143 int result = dialog.open(); 144 labelProvider.dispose(); 145 if (result == Window.OK) { 146 return (ILaunchConfiguration) dialog.getFirstResult(); 147 } 148 return null; 149 } 150 151 /** 152 * Launches a configuration for the given module 153 */ 154 protected void launch (IFile module, String mode) { 155 ILaunchConfiguration config = findLaunchConfiguration(module, mode); 156 if (config != null) { 157 DebugUITools.launch(config, mode); 158 } 159 } 160 161 public void setClasspathDefaults (ILaunchConfigurationWorkingCopy configuration) { 162 try { 163 IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration); 164 // Set ATTR_DEFAULT_CLASSPATH to false here, because we want to use 165 // a custom class path. 166 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); 167 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, this.asMementos(entries)); 168 } catch (CoreException e) { 169 // CorePlugin.log(e); // TODO can we do better? Like: 170 // JDIDebugUIPlugin.errorDialog(LauncherMessages.getString("JavaClasspathTab.Unable_to_save_classpath_1"), 171 // e); //$NON-NLS-1$ 172 return; 173 } 174 } 175 176 protected List<String> asMementos (IRuntimeClasspathEntry[] entries) throws CoreException { 177 List<String> mementos = new ArrayList<String>(entries.length); 178 for (IRuntimeClasspathEntry entry : entries) { 179 mementos.add(entry.getMemento()); 180 } 181 return mementos; 182 } 183 184 /** 185 * Create & return a new configuration based on the specified <code>IFile</code>. 186 */ 187 protected ILaunchConfiguration createConfiguration (IFile module) { 188 ILaunchConfiguration config = null; 189 ILaunchConfigurationWorkingCopy wc = null; 190 try { 191 ILaunchConfigurationType configType = this.getLaunchConfigType(); 192 wc = configType.newInstance(null, this.getLaunchManager().generateUniqueLaunchConfigurationNameFrom( 193 module.getName())); 194 } catch (CoreException exception) { 195 this.reportCreatingConfiguration(exception); 196 return null; 197 } 198 IProject project = module.getProject(); 199 // TODO do not hardcode the attributes in 2 places (see RfpTabGroup) 200 wc.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName()); 201 wc.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, getModuleName(module)); 202 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, 203 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 204 setClasspathDefaults(wc); 205 wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, this.getWorkingDirectory(module)); 206 try { 207 config = wc.doSave(); 208 } catch (CoreException exception) { 209 this.reportCreatingConfiguration(exception); 210 } 211 return config; 212 } 213 214 protected String getWorkingDirectory (IFile rfFile) { 215 return rfFile.getParent().getFullPath().makeRelative().toString(); 216 } 217 218 protected void reportCreatingConfiguration (final CoreException exception) { 219 Display.getDefault().asyncExec(new Runnable() { 220 public void run () { 221 ErrorDialog.openError(LaunchingPlugin.getShell(), "Cannot Create Configuration", 222 "An exception occurred attempting to create launch configuration", exception.getStatus()); 223 } 224 }); 225 } 226 227 /** 228 * Returns the local java launch config type 229 */ 230 protected ILaunchConfigurationType getLaunchConfigType () { 231 return this.getLaunchManager().getLaunchConfigurationType( 232 IRfpLaunchConfigurationConstants.LAUNCH_CONFIGURATION_TYPE); 233 } 234 235 protected ILaunchManager getLaunchManager () { 236 return DebugPlugin.getDefault().getLaunchManager(); 237 } 238 239 static String getModuleName (IFile module) { 246 240 return module.getProjectRelativePath().removeFileExtension().toString().replace('/', '.'); 247 241 } 248 249 242 } -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpRefalMainTab.java
r3444 r3449 5 5 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 6 6 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 7 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 7 8 import org.eclipse.jdt.ui.ISharedImages; 8 9 import org.eclipse.jdt.ui.JavaUI; … … 10 11 import org.eclipse.swt.events.ModifyEvent; 11 12 import org.eclipse.swt.events.ModifyListener; 13 import org.eclipse.swt.events.SelectionEvent; 14 import org.eclipse.swt.events.SelectionListener; 12 15 import org.eclipse.swt.graphics.Font; 13 16 import org.eclipse.swt.graphics.Image; 14 17 import org.eclipse.swt.layout.GridData; 15 18 import org.eclipse.swt.layout.GridLayout; 19 import org.eclipse.swt.widgets.Button; 16 20 import org.eclipse.swt.widgets.Composite; 17 21 import org.eclipse.swt.widgets.Group; … … 19 23 import org.refal.plus.rfpdt.launch.IRfpLaunchConfigurationConstants; 20 24 25 public class RfpRefalMainTab extends AbstractLaunchConfigurationTab { 26 private Text fProjectText; 27 private Text fModuleText; 28 private Button fStopInMainCheckButton; 21 29 22 public class RfpRefalMainTab extends AbstractLaunchConfigurationTab { 30 public void createControl (Composite parent) { 31 Composite comp = new Composite(parent, SWT.NONE); 32 setControl(comp); 33 GridLayout topLayout = new GridLayout(); 34 comp.setLayout(topLayout); 35 createProjectEditor(comp); 36 createModuleEditor(comp); 37 // GridData gd; 38 // 39 // createVerticalSpacer(comp, 1); 40 // 41 // Composite mainComp = new Composite(comp, SWT.NONE); 42 // GridLayout mainLayout = new GridLayout(); 43 // mainLayout.numColumns = 2; 44 // mainLayout.marginHeight = 0; 45 // mainLayout.marginWidth = 0; 46 // mainComp.setLayout(mainLayout); 47 // gd = new GridData(GridData.FILL_HORIZONTAL); 48 // mainComp.setLayoutData(gd); 49 // mainComp.setFont(font); 50 // 51 // fMainLabel = new Label(mainComp, SWT.NONE); 52 // fMainLabel.setText("Refal module (qualified name):"); 53 // gd = new GridData(); 54 // gd.horizontalSpan = 2; 55 // fMainLabel.setLayoutData(gd); 56 // fMainLabel.setFont(font); 57 // 58 // fMainText = new Text(mainComp, SWT.SINGLE | SWT.BORDER); 59 // gd = new GridData(GridData.FILL_HORIZONTAL); 60 // fMainText.setLayoutData(gd); 61 // fMainText.setFont(font); 62 // fMainText.addModifyListener(new ModifyListener() { 63 // public void modifyText(ModifyEvent evt) { 64 // updateLaunchConfigurationDialog(); 65 // } 66 // }); 67 // 68 } 23 69 24 protected Text fProjectText; 25 protected Text fModuleText; 26 27 public void createControl(Composite parent) { 28 Composite comp = new Composite(parent, SWT.NONE); 29 setControl(comp); 30 GridLayout topLayout = new GridLayout(); 31 comp.setLayout(topLayout); 32 createProjectEditor(comp); 33 createModuleEditor(comp); 34 // GridData gd; 35 // 36 // createVerticalSpacer(comp, 1); 37 // 38 // Composite mainComp = new Composite(comp, SWT.NONE); 39 // GridLayout mainLayout = new GridLayout(); 40 // mainLayout.numColumns = 2; 41 // mainLayout.marginHeight = 0; 42 // mainLayout.marginWidth = 0; 43 // mainComp.setLayout(mainLayout); 44 // gd = new GridData(GridData.FILL_HORIZONTAL); 45 // mainComp.setLayoutData(gd); 46 // mainComp.setFont(font); 47 // 48 // fMainLabel = new Label(mainComp, SWT.NONE); 49 // fMainLabel.setText("Refal module (qualified name):"); 50 // gd = new GridData(); 51 // gd.horizontalSpan = 2; 52 // fMainLabel.setLayoutData(gd); 53 // fMainLabel.setFont(font); 54 // 55 // fMainText = new Text(mainComp, SWT.SINGLE | SWT.BORDER); 56 // gd = new GridData(GridData.FILL_HORIZONTAL); 57 // fMainText.setLayoutData(gd); 58 // fMainText.setFont(font); 59 // fMainText.addModifyListener(new ModifyListener() { 60 // public void modifyText(ModifyEvent evt) { 61 // updateLaunchConfigurationDialog(); 62 // } 63 // }); 64 // 65 } 70 private void createProjectEditor (Composite parent) { 71 Font font = parent.getFont(); 72 Group group = new Group(parent, SWT.NONE); 73 group.setText("Refal project"); 74 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 75 group.setLayoutData(gd); 76 GridLayout layout = new GridLayout(); 77 layout.numColumns = 1; 78 group.setLayout(layout); 79 group.setFont(font); 80 fProjectText = new Text(group, SWT.SINGLE | SWT.BORDER); 81 gd = new GridData(GridData.FILL_HORIZONTAL); 82 fProjectText.setLayoutData(gd); 83 fProjectText.setFont(font); 84 fProjectText.addModifyListener(new ModifyListener() { 85 public void modifyText (ModifyEvent evt) { 86 updateLaunchConfigurationDialog(); 87 } 88 }); 89 // fProjButton = createPushButton(group, LauncherMessages.AbstractJavaMainTab_1, null); 90 // fProjButton.addSelectionListener(fListener); 91 } 66 92 67 private void createProjectEditor(Composite parent) { 68 Font font= parent.getFont(); 69 Group group= new Group(parent, SWT.NONE); 70 group.setText("Refal project"); 71 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 72 group.setLayoutData(gd); 73 GridLayout layout = new GridLayout(); 74 layout.numColumns = 2; 75 group.setLayout(layout); 76 group.setFont(font); 77 fProjectText = new Text(group, SWT.SINGLE | SWT.BORDER); 78 gd = new GridData(GridData.FILL_HORIZONTAL); 79 fProjectText.setLayoutData(gd); 80 fProjectText.setFont(font); 81 fProjectText.addModifyListener(new ModifyListener() { 82 public void modifyText(ModifyEvent evt) { 83 updateLaunchConfigurationDialog(); 84 } 85 }); 86 //fProjButton = createPushButton(group, LauncherMessages.AbstractJavaMainTab_1, null); 87 //fProjButton.addSelectionListener(fListener); 88 } 89 private void createModuleEditor(Composite parent) { 90 Font font= parent.getFont(); 91 Group group= new Group(parent, SWT.NONE); 92 group.setText("Refal main module (qualified name)"); 93 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 94 group.setLayoutData(gd); 95 GridLayout layout = new GridLayout(); 96 layout.numColumns = 2; 97 group.setLayout(layout); 98 group.setFont(font); 99 fModuleText = new Text(group, SWT.SINGLE | SWT.BORDER); 100 gd = new GridData(GridData.FILL_HORIZONTAL); 101 fModuleText.setLayoutData(gd); 102 fModuleText.setFont(font); 103 fModuleText.addModifyListener(new ModifyListener() { 104 public void modifyText(ModifyEvent evt) { 105 updateLaunchConfigurationDialog(); 106 } 107 }); 108 //fProjButton = createPushButton(group, LauncherMessages.AbstractJavaMainTab_1, null); 109 //fProjButton.addSelectionListener(fListener); 110 } 111 112 public void initializeFrom(ILaunchConfiguration config) { 113 String projectName = ""; 114 String moduleName = ""; 115 try { 116 projectName = config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); 117 moduleName = config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, ""); 118 } catch (CoreException ce) { 119 //CorePlugin.log(ce); 120 } 121 fProjectText.setText(projectName); 122 fModuleText.setText(moduleName); 123 } 93 private void createModuleEditor (Composite parent) { 94 Font font = parent.getFont(); 95 Group group = new Group(parent, SWT.NONE); 96 group.setText("Refal main module (qualified name)"); 97 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 98 group.setLayoutData(gd); 99 GridLayout layout = new GridLayout(); 100 layout.numColumns = 1; 101 group.setLayout(layout); 102 group.setFont(font); 103 fModuleText = new Text(group, SWT.SINGLE | SWT.BORDER); 104 gd = new GridData(GridData.FILL_HORIZONTAL); 105 fModuleText.setLayoutData(gd); 106 fModuleText.setFont(font); 107 fModuleText.addModifyListener(new ModifyListener() { 108 public void modifyText (ModifyEvent evt) { 109 updateLaunchConfigurationDialog(); 110 } 111 }); 112 fStopInMainCheckButton = new Button(group, SWT.CHECK); 113 fStopInMainCheckButton.setText("Stop in main"); 114 gd = new GridData(GridData.FILL_HORIZONTAL); 115 fStopInMainCheckButton.setLayoutData(gd); 116 fStopInMainCheckButton.setFont(font); 117 fStopInMainCheckButton.addSelectionListener(new SelectionListener() { 118 public void widgetDefaultSelected (SelectionEvent e) { 119 updateLaunchConfigurationDialog(); 120 } 124 121 125 public void performApply(ILaunchConfigurationWorkingCopy config) { 126 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjectText.getText().trim()); 127 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, fModuleText.getText().trim()); 128 } 122 public void widgetSelected (SelectionEvent e) { 123 updateLaunchConfigurationDialog(); 124 } 125 }); 126 // fProjButton = createPushButton(group, LauncherMessages.AbstractJavaMainTab_1, null); 127 // fProjButton.addSelectionListener(fListener); 128 } 129 129 130 public void dispose() { 131 } 130 public void initializeFrom (ILaunchConfiguration config) { 131 String projectName = ""; 132 String moduleName = ""; 133 boolean stopInMain = false; 134 try { 135 projectName = config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); 136 moduleName = config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, ""); 137 stopInMain = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_STOP_IN_MAIN, false); 138 } catch (CoreException ce) { 139 // CorePlugin.log(ce); 140 } 141 fProjectText.setText(projectName); 142 fModuleText.setText(moduleName); 143 fStopInMainCheckButton.setSelection(stopInMain); 144 } 132 145 133 public boolean isValid(ILaunchConfiguration config) { 134 135 setErrorMessage(null); 136 setMessage(null); 137 138 String name = fProjectText.getText().trim(); 139 if (name.length() == 0) { 140 setErrorMessage("Project name not specified"); 141 return false; 142 } 143 name = fModuleText.getText().trim(); 144 if (name.length() == 0) { 145 setErrorMessage("Main module name not specified"); 146 return false; 147 } 148 149 return true; 150 } 146 public void performApply (ILaunchConfigurationWorkingCopy config) { 147 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjectText.getText().trim()); 148 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, fModuleText.getText().trim()); 149 if (fStopInMainCheckButton.getSelection()) 150 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_STOP_IN_MAIN, true); 151 else 152 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_STOP_IN_MAIN, (String) null); 153 } 151 154 152 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 153 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); 154 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, ""); 155 } 155 public void dispose () {} 156 156 157 public String getName() { 158 return "Refal Main"; 159 } 157 public boolean isValid (ILaunchConfiguration config) { 160 158 161 public Image getImage() { 162 return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS); 163 } 159 setErrorMessage(null); 160 setMessage(null); 164 161 162 String name = fProjectText.getText().trim(); 163 if (name.length() == 0) { 164 setErrorMessage("Project name not specified"); 165 return false; 166 } 167 name = fModuleText.getText().trim(); 168 if (name.length() == 0) { 169 setErrorMessage("Main module name not specified"); 170 return false; 171 } 172 173 return true; 174 } 175 176 public void setDefaults (ILaunchConfigurationWorkingCopy config) { 177 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); 178 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, ""); 179 } 180 181 public String getName () { 182 return "Refal Main"; 183 } 184 185 public Image getImage () { 186 return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS); 187 } 165 188 } -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpTabGroup.java
r3444 r3449 1 1 package org.refal.plus.rfpdt.launch.ui; 2 3 2 4 3 import org.eclipse.core.resources.IFile; … … 21 20 22 21 public class RfpTabGroup extends AbstractLaunchConfigurationTabGroup { 22 public void createTabs (ILaunchConfigurationDialog dialog, String mode) { 23 ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new RfpRefalMainTab(), new JavaArgumentsTab(), 24 new JavaJRETab(), new JavaClasspathTab(), /* new SourceLookupTab(), */ 25 new EnvironmentTab(), new CommonTab() }; 26 this.setTabs(tabs); 27 } 23 28 24 public void createTabs(ILaunchConfigurationDialog dialog, String mode) { 25 ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { 26 new RfpRefalMainTab(), 27 new JavaArgumentsTab(), new JavaJRETab(), 28 new JavaClasspathTab(), /*new SourceLookupTab(),*/ 29 new EnvironmentTab(), new CommonTab() }; 30 this.setTabs(tabs); 31 } 29 public void setDefaults (ILaunchConfigurationWorkingCopy config) { 30 super.setDefaults(config); 31 RfpLaunchShortcut helper = new RfpLaunchShortcut(); 32 IProject project = null; 33 IFile resource = this.getResource(); 34 if (resource != null) { 35 project = resource.getProject(); 36 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName()); 37 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, RfpLaunchShortcut 38 .getModuleName(resource)); 39 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, helper 40 .getWorkingDirectory(resource)); 41 } 42 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, 43 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 44 helper.setClasspathDefaults(config); 45 // This is tricky: without setting ATTR_PROJECT_NAME to the empty 46 // string, the project is expected to be a Java project, which in our 47 // case is not necessarily so, and some methods validate on the 48 // existance of a Java project with that name. 49 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); 50 } 32 51 33 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 34 super.setDefaults(config); 35 RfpLaunchShortcut helper = new RfpLaunchShortcut(); 36 IProject project = null; 37 IFile resource = this.getResource(); 38 if (resource != null) { 39 project = resource.getProject(); 40 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_PROJECT_NAME, 41 project.getName()); 42 config.setAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, 43 RfpLaunchShortcut.getModuleName(resource)); 44 config.setAttribute( 45 IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, 46 helper.getWorkingDirectory(resource)); 47 } 48 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, 49 IRfpLaunchConfigurationConstants.CLASSPATH_PROVIDER); 50 helper.setClasspathDefaults(config); 51 // This is tricky: without setting ATTR_PROJECT_NAME to the empty 52 // string, the project is expected to be a Java project, which in our 53 // case is not necessarily so, and some methods validate on the 54 // existance of a Java project with that name. 55 config.setAttribute( 56 IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); 57 } 58 59 private IFile getResource() { 60 IWorkbenchPage page = LaunchingPlugin.getActivePage(); 61 if (page == null) 62 return null; 63 ISelection selection = page.getSelection(); 64 RfpLaunchShortcut helper = new RfpLaunchShortcut(); 65 if (selection instanceof IStructuredSelection) 66 return helper 67 .getResourceFromSelection((IStructuredSelection) selection); 68 return helper.getResourceFromEditor(page.getActiveEditor()); 69 } 70 52 private IFile getResource () { 53 IWorkbenchPage page = LaunchingPlugin.getActivePage(); 54 if (page == null) 55 return null; 56 ISelection selection = page.getSelection(); 57 RfpLaunchShortcut helper = new RfpLaunchShortcut(); 58 if (selection instanceof IStructuredSelection) 59 return helper.getResourceFromSelection((IStructuredSelection) selection); 60 return helper.getResourceFromEditor(page.getActiveEditor()); 61 } 71 62 }
Note: See TracChangeset
for help on using the changeset viewer.