diff options
10 files changed, 188 insertions, 0 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java index 819994aa9..b02740406 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java @@ -83,6 +83,7 @@ import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.core.ILaunchesListener; import org.eclipse.debug.core.ILaunchesListener2; +import org.eclipse.debug.core.IStatusHandler; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IDisconnect; import org.eclipse.debug.core.model.IPersistableSourceLocator; @@ -112,6 +113,44 @@ import org.xml.sax.helpers.DefaultHandler; public class LaunchManager extends PlatformObject implements ILaunchManager, IResourceChangeListener { /** + * Constant to define debug.core for the status codes + * + * @since 3.2 + */ + private static final String DEBUG_CORE = "org.eclipse.debug.core"; //$NON-NLS-1$ + + /** + * Constant to define debug.ui for the status codes + * + * @since 3.2 + */ + private static final String DEBUG_UI = "org.eclipse.debug.ui"; //$NON-NLS-1$ + + /** + * Constant to represent the empty string + * + * @since 3.2 + */ + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + + /** + * Status code for which a UI prompter is registered. + * + * @since 3.2 + */ + protected static final IStatus promptStatus = new Status(IStatus.INFO, DEBUG_UI, 200, EMPTY_STRING, null); + + /** + * Status code for which a prompter will ask the user to delete any/all of the launch configurations + * that are associated with this project being deleted + * + * @since 3.2 + */ + protected static final IStatus deleteAssociatedLaunchConfigs = new Status(IStatus.INFO, DEBUG_CORE, 225, EMPTY_STRING, null); + + + + /** * Notifies a launch config listener in a safe runnable to handle * exceptions. */ @@ -265,6 +304,7 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe */ private Map fFileToConfig = new HashMap(); + /** * Builds a cache of configs that will be deleted in the given project */ @@ -278,6 +318,12 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe fFileToConfig.put(file, configuration); } } + //bug 113772 + try { + IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(promptStatus); + handler.handleStatus(deleteAssociatedLaunchConfigs, project); + } + catch (CoreException e){e.printStackTrace();} } /** diff --git a/org.eclipse.debug.ui/plugin.xml b/org.eclipse.debug.ui/plugin.xml index 92c20adef..e59024148 100644 --- a/org.eclipse.debug.ui/plugin.xml +++ b/org.eclipse.debug.ui/plugin.xml @@ -1528,6 +1528,11 @@ class="org.eclipse.debug.internal.ui.launchConfigurations.SaveScopeResourcesHandler" code="222" id="org.eclipse.debug.ui.statusHandler.saveScopedResources" + plugin="org.eclipse.debug.core"/> + <statusHandler + class="org.eclipse.debug.internal.ui.launchConfigurations.DeleteLaunchConfigurations" + code="225" + id="org.eclipse.debug.ui.deleteAssociatedLaunchConfigs" plugin="org.eclipse.debug.core"/> </extension> <extension diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java index a3d990682..fe246331e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java @@ -118,5 +118,6 @@ public class DebugUIPreferenceInitializer extends AbstractPreferenceInitializer prefs.setDefault(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED, true); prefs.setDefault(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED, true); prefs.setDefault(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES, false); + prefs.setDefault(IInternalDebugUIConstants.PREF_DELETE_CONFIGS_ON_PROJECT_DELETE, MessageDialogWithToggle.PROMPT); } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java index fbf6ea295..d14e66cec 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java @@ -129,6 +129,13 @@ public interface IInternalDebugUIConstants { public static final String PREF_FILTER_LAUNCH_DELETED = IDebugUIConstants.PLUGIN_ID + ".PREF_FILTER_LAUNCH_DELETED"; //$NON-NLS-1$ /** + * Preference for prompting if launch configurations should be deleted when a project they are linked to is deleted + * @see LaunchManager#preDelete(IProject) + * @since 3.2 + */ + public static final String PREF_DELETE_CONFIGS_ON_PROJECT_DELETE =IDebugUIConstants.PLUGIN_ID +".PREF_DELETE_CONFIGS_ON_PROJECT_DELETE"; //$NON-NLS-1$ + + /** * Preference for enabling/disabling filtering based on selected items from the launch configuration type table * @since 3.2 */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/DeleteLaunchConfigurations.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/DeleteLaunchConfigurations.java new file mode 100644 index 000000000..60b8c711d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/DeleteLaunchConfigurations.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2004, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.launchConfigurations; + +import java.util.ArrayList; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.IStatusHandler; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.ui.dialogs.ListSelectionDialog; +import org.eclipse.ui.model.AdaptableList; +import org.eclipse.ui.model.WorkbenchContentProvider; + +/** + * Provides a status handler to prompt the user to delete any launch configurations + * for the associated project that is about to be deleted, for more information + * see <code>LaunchManager#preDelete(IProject)</code>. + * + * @since 3.2 + * + */ +public class DeleteLaunchConfigurations implements IStatusHandler { + + /* (non-Javadoc) + * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object) + */ + public Object handleStatus(IStatus status, Object source) throws CoreException { + String pref = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_DELETE_CONFIGS_ON_PROJECT_DELETE); + if(source instanceof IProject) { + IProject project = (IProject)source; + ILaunchConfiguration[] configs = collectAssociatedLaunches(project); + if(configs.length > 0) { + if(pref.equals(MessageDialogWithToggle.PROMPT)) { + ListSelectionDialog lsd = new ListSelectionDialog(DebugUIPlugin.getShell(), + new AdaptableList(configs), + new WorkbenchContentProvider(), + DebugUITools.newDebugModelPresentation(), + LaunchConfigurationsMessages.DeleteLaunchConfigurations_0); + lsd.setInitialSelections(configs); + lsd.setTitle(LaunchConfigurationsMessages.DeleteLaunchConfigurations_1); + if(lsd.open() == IDialogConstants.OK_ID) { + doDelete(lsd.getResult()); + } + } + else if(pref.equals(MessageDialogWithToggle.ALWAYS)){ + doDelete(collectAssociatedLaunches(project)); + } + } + } + return null; + } + + /** + * Gets to launch configuration associated with the specified project. + * This method relies on the resource mapping existing, if no such mapping + * exists the launch configuration is ignored. + * + * @param project the project to collect launch configurations for + * @return the list of associated launch configurations + */ + private ILaunchConfiguration[] collectAssociatedLaunches(IProject project) { + ArrayList list = new ArrayList(); + try { + ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(); + IResource[] resources = null; + for(int i = 0; i < configs.length; i++) { + resources = configs[i].getMappedResources(); + if(resources != null) { + for(int j = 0; j < resources.length; j++){ + if(resources[j].equals(project)) { + list.add(configs[i]); + } + } + } + } + } + catch (CoreException e) {e.printStackTrace();} + return (ILaunchConfiguration[])list.toArray(new ILaunchConfiguration[list.size()]); + } + + /** + * Actually performs the deletion of the launch configurations. + * @param launch the launch configurations to delete + */ + private void doDelete(Object[] launches) { + try { + for(int i = 0; i < launches.length; i++) { + ((ILaunchConfiguration)launches[i]).delete(); + } + } + catch (CoreException e) {e.printStackTrace();} + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java index ab9b8b623..9c0ab55b8 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java @@ -175,4 +175,8 @@ public class LaunchConfigurationsMessages extends NLS { public static String LaunchConfigurationsDialog_6; + public static String DeleteLaunchConfigurations_0; + + public static String DeleteLaunchConfigurations_1; + }
\ No newline at end of file diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties index ed2604d11..88baecf3b 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties @@ -112,6 +112,8 @@ LaunchConfigurationTabGroupViewer_No_tabs_defined_for_launch_configuration_type_ DuplicateLaunchConfigurationAction__Duplicate_1=&Duplicate DeleteLaunchConfigurationAction_Dele_te_1=Dele&te +DeleteLaunchConfigurations_0=Select associated launch configurations to delete. +DeleteLaunchConfigurations_1=Delete Launch Configurations CreateLaunchConfigurationAction_Ne_w_1=Ne&w CreateLaunchConfigurationAction_New_configuration_2=New_configuration diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java index d2959d6bc..b712f27b2 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java @@ -126,6 +126,8 @@ public class DebugPreferencesMessages extends NLS { public static String PerspectivePreferencePage_7; public static String PerspectivePreferencePage_8; + + public static String LaunchConfigurationsPreferencePage_2; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties index ee86563d2..0a7086377 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties @@ -112,3 +112,4 @@ PerspectivePreferencePage_7=&Debug PerspectivePreferencePage_8=De&bug LaunchConfigurationsPreferencePage_0=Filter checked launch configuration type&s. LaunchConfigurationsPreferencePage_1=Launch Configurations +LaunchConfigurationsPreferencePage_2=Delete confi&gurations when associated project is deleted diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/LaunchConfigurationsPreferencePage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/LaunchConfigurationsPreferencePage.java index 598c28893..a9df27706 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/LaunchConfigurationsPreferencePage.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/LaunchConfigurationsPreferencePage.java @@ -26,9 +26,11 @@ import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupFilter; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.preference.RadioGroupFieldEditor; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; @@ -146,6 +148,13 @@ public class LaunchConfigurationsPreferencePage extends PreferencePage implement fFieldEditors.add(edit); edit = new BooleanFieldEditor(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED, DebugPreferencesMessages.LaunchingPreferencePage_34, SWT.NONE, spacer); fFieldEditors.add(edit); + edit = new RadioGroupFieldEditor(IInternalDebugUIConstants.PREF_DELETE_CONFIGS_ON_PROJECT_DELETE, DebugPreferencesMessages.LaunchConfigurationsPreferencePage_2, 3, + new String[][] {{DebugPreferencesMessages.LaunchingPreferencePage_3, MessageDialogWithToggle.ALWAYS}, + {DebugPreferencesMessages.LaunchingPreferencePage_4, MessageDialogWithToggle.NEVER}, + {DebugPreferencesMessages.LaunchingPreferencePage_5, MessageDialogWithToggle.PROMPT}}, + comp, + true); + fFieldEditors.add(edit); //add table options createTypeFiltering(group); |