1 11 package org.eclipse.debug.internal.ui.sourcelookup; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.debug.core.IStatusHandler; 20 import org.eclipse.debug.internal.ui.DebugUIPlugin; 21 import org.eclipse.debug.ui.sourcelookup.CommonSourceNotFoundEditor; 22 import org.eclipse.jface.window.Window; 23 import org.eclipse.ui.dialogs.ElementListSelectionDialog; 24 25 30 public class ResolveDuplicatesHandler implements IStatusHandler { 31 34 public Object handleStatus(IStatus status, Object source) throws CoreException { 35 Object [] args = (Object [])source; 36 List sources = (List ) args[1]; 37 return resolveSourceElement(sources); 38 } 39 40 public Object resolveSourceElement(List sources) { 41 Object file = null; 42 sources = removeSourceNotFoundEditors(sources); 43 if(sources.size() == 1) { 44 return sources.get(0); 45 } else if(sources.size() == 0) { 46 return null; 47 } 48 ElementListSelectionDialog dialog = new ElementListSelectionDialog(DebugUIPlugin.getShell(), new SourceElementLabelProvider()); 49 dialog.setMultipleSelection(false); 50 dialog.setTitle(SourceLookupUIMessages.ResolveDuplicatesHandler_0); 51 dialog.setMessage(SourceLookupUIMessages.ResolveDuplicatesHandler_1); 52 dialog.setElements(sources.toArray()); 53 dialog.open(); 54 if(dialog.getReturnCode() == Window.OK) { 55 file = dialog.getFirstResult(); 56 } 57 return file; 58 } 59 60 67 private List removeSourceNotFoundEditors(List sources){ 68 Iterator iterator = sources.iterator(); 69 List filteredList = new ArrayList (); 70 Object next; 71 while(iterator.hasNext()) { 72 next = iterator.next(); 73 if (!(next instanceof CommonSourceNotFoundEditor)) { 74 filteredList.add(next); 75 } 76 } 77 if (filteredList.isEmpty() && sources.get(0) != null) { 78 filteredList.add(sources.get(0)); 79 } 80 return filteredList; 81 } 82 } 83 | Popular Tags |