Changeset 3468


Ignore:
Timestamp:
Mar 7, 2008, 4:00:00 PM (13 years ago)
Author:
yura
Message:
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  
    1212         point="org.eclipse.debug.core.launchConfigurationTypes">
    1313      <launchConfigurationType
    14             delegate="org.refal.plus.rfpdt.launch.RfpLaunchConfigurationDelegate"
     14            delegate="org.eclipse.jdt.launching.JavaLaunchDelegate"
    1515            id="org.refal.plus.rfpdt.launch.refal_plus"
    1616            modes="run, debug"
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpLaunchShortcut.java

    r3467 r3468  
    22
    33import java.util.ArrayList;
    4 import java.util.Collections;
    54import java.util.List;
    65
    76import org.eclipse.core.resources.IFile;
    8 import org.eclipse.core.resources.IProject;
    97import org.eclipse.core.runtime.CoreException;
    108import org.eclipse.debug.core.DebugPlugin;
     
    1715import org.eclipse.debug.ui.ILaunchShortcut;
    1816import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
    19 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
    2017import org.eclipse.jface.dialogs.ErrorDialog;
    2118import org.eclipse.jface.dialogs.MessageDialog;
     
    2522import org.eclipse.swt.widgets.Display;
    2623import org.eclipse.ui.IEditorPart;
     24import org.eclipse.ui.IWorkbenchPage;
    2725import org.eclipse.ui.dialogs.ElementListSelectionDialog;
    2826import org.refal.plus.rfpdt.editor.RfpEditor;
     
    3533public class RfpLaunchShortcut implements ILaunchShortcut {
    3634    public void launch (ISelection selection, String mode) {
    37         IFile module = this.getResourceFromSelection(selection);
     35        IFile module = getResourceFromSelection(selection);
    3836        launch: {
    3937            if (module == null)
     
    4240            if (!moduleName.endsWith(".rf") && !moduleName.endsWith(".rfi"))
    4341                break launch;
    44             this.launch(module, mode);
     42            launch(module, mode);
    4543            return;
    4644        }
     
    5048
    5149    public void launch (IEditorPart editor, String mode) {
    52         IFile module = this.getResourceFromEditor(editor);
     50        IFile module = getResourceFromEditor(editor);
    5351        if (module != null) {
    54             this.launch(module, mode);
     52            launch(module, mode);
    5553            return;
    5654        }
     
    5957    }
    6058
    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) {
    6264        if (selection.isEmpty())
    6365            return null;
     
    7072    }
    7173
    72     protected IFile getResourceFromEditor (IEditorPart part) {
     74    private static IFile getResourceFromEditor (IEditorPart part) {
    7375        if (part == null || !(part instanceof RfpEditor))
    7476            return null;
    7577        RfpEditor editor = (RfpEditor) part;
    7678        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('/', '.');
    7787    }
    7888
     
    8292     * @return a re-useable config or <code>null</code> if none
    8393     */
    84     protected ILaunchConfiguration 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>();
    8797        try {
    8898            ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(
    8999                    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)
    93101                if (config.getAttribute(IRfpLaunchConfigurationConstants.ATTR_MODULE_NAME, "").equals(
    94102                        getModuleName(module))
    95103                        && config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "").equals(
    96                                 getWorkingDirectory(module))) {
     104                                getWorkingDirectory(module)))
    97105                    candidateConfigs.add(config);
    98                 }
    99             }
    100106        } catch (CoreException e) {
    101107            System.err.println(e);
     
    109115        int candidateCount = candidateConfigs.size();
    110116        if (candidateCount < 1) {
    111             return this.createConfiguration(module);
     117            return createConfiguration(module);
    112118        } else if (candidateCount == 1) {
    113119            return (ILaunchConfiguration) candidateConfigs.get(0);
     
    117123             * method returns null, since cancelling the dialog should also cancel launching anything.
    118124             */
    119             ILaunchConfiguration config = this.chooseConfiguration(candidateConfigs, mode);
     125            ILaunchConfiguration config = chooseConfiguration(candidateConfigs, mode);
    120126            if (config != null) {
    121127                return config;
     
    129135     * chosen config, or <code>null</code> if the user cancelled the dialog.
    130136     */
    131     protected ILaunchConfiguration chooseConfiguration (List<ILaunchConfiguration> configList, String mode) {
     137    private static ILaunchConfiguration chooseConfiguration (List<ILaunchConfiguration> configList, String mode) {
    132138        IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
    133139        ElementListSelectionDialog dialog = new ElementListSelectionDialog(LaunchingPlugin.getShell(), labelProvider);
     
    151157     * Launches a configuration for the given module
    152158     */
    153     protected void launch (IFile module, String mode) {
     159    private static void launch (IFile module, String mode) {
    154160        ILaunchConfiguration config = findLaunchConfiguration(module, mode);
    155         if (config != null) {
     161        if (config != null)
    156162            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;
    166163    }
    167164
     
    169166     * Create & return a new configuration based on the specified <code>IFile</code>.
    170167     */
    171     protected ILaunchConfiguration createConfiguration (IFile module) {
     168    private static ILaunchConfiguration createConfiguration (IFile module) {
    172169        ILaunchConfiguration config = null;
    173170        ILaunchConfigurationWorkingCopy wc = null;
    174171        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(
    177174                    module.getName()));
    178175        } 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);
    189180        try {
    190181            config = wc.doSave();
    191182        } catch (CoreException exception) {
    192             this.reportCreatingConfiguration(exception);
     183            reportCreatingConfiguration(exception);
    193184        }
    194185        return config;
    195186    }
    196187
    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) {
    198211        Display.getDefault().asyncExec(new Runnable() {
    199212            public void run () {
     
    207220     * Returns the local java launch config type
    208221     */
    209     protected ILaunchConfigurationType getLaunchConfigType () {
    210         return this.getLaunchManager().getLaunchConfigurationType(
    211                 IRfpLaunchConfigurationConstants.LAUNCH_CONFIGURATION_TYPE);
    212     }
    213 
    214     protected ILaunchManager getLaunchManager () {
     222    private static ILaunchConfigurationType getLaunchConfigType () {
     223        return getLaunchManager()
     224                .getLaunchConfigurationType(IRfpLaunchConfigurationConstants.LAUNCH_CONFIGURATION_TYPE);
     225    }
     226
     227    private static ILaunchManager getLaunchManager () {
    215228        return DebugPlugin.getDefault().getLaunchManager();
    216229    }
    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     }
    225230}
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpRefalMainTab.java

    r3449 r3468  
    156156
    157157    public boolean isValid (ILaunchConfiguration config) {
    158 
    159158        setErrorMessage(null);
    160159        setMessage(null);
    161 
    162160        String name = fProjectText.getText().trim();
    163161        if (name.length() == 0) {
     
    170168            return false;
    171169        }
    172 
    173170        return true;
    174171    }
  • devel-tools/trunk/eclipse/org.refal.plus.rfpdt.launch/src/org/refal/plus/rfpdt/launch/ui/RfpTabGroup.java

    r3467 r3468  
    11package org.refal.plus.rfpdt.launch.ui;
    22
    3 import org.eclipse.core.resources.IFile;
    4 import org.eclipse.core.resources.IProject;
    53import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
    64import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
     
    1210import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab;
    1311import 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;
    2012
    2113public class RfpTabGroup extends AbstractLaunchConfigurationTabGroup {
     
    2921    public void setDefaults (ILaunchConfigurationWorkingCopy config) {
    3022        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);
    6024    }
    6125}
Note: See TracChangeset for help on using the changeset viewer.