1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.debug.core.DebugPlugin; 21 import org.eclipse.debug.core.ILaunchConfiguration; 22 import org.eclipse.debug.core.IStatusHandler; 23 import org.eclipse.debug.internal.ui.DebugUIPlugin; 24 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 25 import org.eclipse.jface.dialogs.IDialogConstants; 26 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 27 import org.eclipse.ui.model.AdaptableList; 28 29 37 public class DeleteLaunchConfigurationStatusHandler implements IStatusHandler { 38 39 42 public Object handleStatus(IStatus status, Object source) throws CoreException { 43 String pref = DebugUIPlugin.getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_DELETE_CONFIGS_ON_PROJECT_DELETE); 44 if(source instanceof IProject[]) { 45 IProject[] projects = (IProject[])source; 46 ArrayList configs = new ArrayList (); 47 ArrayList elements = null; 48 HashMap map = new HashMap (); 49 for (int i = 0; i < projects.length; i++) { 50 elements = collectAssociatedLaunches(projects[i]); 51 if(!elements.isEmpty()) { 52 map.put(projects[i], elements); 53 configs.addAll(elements); 54 } 55 } 56 if(configs.size() > 0) { 57 if(pref.equals(MessageDialogWithToggle.PROMPT)) { 58 DeleteAssociatedLaunchConfigurationsDialog lsd = new DeleteAssociatedLaunchConfigurationsDialog(DebugUIPlugin.getShell(), 59 new AdaptableList(configs), 60 LaunchConfigurationsMessages.DeleteLaunchConfigurations_0, 61 map); 62 lsd.setInitialSelections(configs.toArray()); 63 lsd.setTitle(LaunchConfigurationsMessages.DeleteLaunchConfigurations_1); 64 if(lsd.open() == IDialogConstants.OK_ID) { 65 doDelete(lsd.getResult()); 66 } 67 } 68 else if(pref.equals(MessageDialogWithToggle.ALWAYS)){ 69 doDelete(configs.toArray()); 70 } 71 } 72 } 73 return null; 74 } 75 76 84 private ArrayList collectAssociatedLaunches(IProject project) { 85 ArrayList list = new ArrayList (); 86 try { 87 ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(); 88 IResource[] resources = null; 89 for(int i = 0; i < configs.length; i++) { 90 if(configs[i].isLocal()) { 91 resources = configs[i].getMappedResources(); 92 if(resources != null) { 93 for(int j = 0; j < resources.length; j++){ 94 if(resources[j].equals(project)) { 95 list.add(configs[i]); 96 } 97 } 98 } 99 } 100 } 101 } 102 catch (CoreException e) { 103 DebugUIPlugin.log(e); 104 } 105 return list; 106 } 107 108 112 private void doDelete(Object [] launches) { 113 try { 114 for(int i = 0; i < launches.length; i++) { 115 ((ILaunchConfiguration)launches[i]).delete(); 116 } 117 } 118 catch (CoreException e) { 119 DebugUIPlugin.log(e); 120 } 121 } 122 123 } 124 | Popular Tags |