1 11 package org.eclipse.debug.internal.ui.views.breakpoints; 12 13 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.model.IBreakpoint; 17 import org.eclipse.debug.core.model.ILineBreakpoint; 18 import org.eclipse.debug.internal.ui.DebugUIPlugin; 19 import org.eclipse.jface.viewers.IBasicPropertyConstants; 20 import org.eclipse.jface.viewers.ILabelProvider; 21 import org.eclipse.jface.viewers.StructuredViewer; 22 import org.eclipse.jface.viewers.Viewer; 23 import org.eclipse.jface.viewers.ViewerSorter; 24 25 public class BreakpointsSorter extends ViewerSorter { 26 29 public boolean isSorterProperty(Object element,String propertyId) { 30 return propertyId.equals(IBasicPropertyConstants.P_TEXT); 31 } 32 33 51 public int compare(Viewer viewer, Object e1, Object e2) { 52 if (!(e1 instanceof IBreakpoint)) { 53 return super.compare(viewer, e1, e2); 54 } 55 56 IBreakpoint b1= (IBreakpoint)e1; 57 IBreakpoint b2= (IBreakpoint)e2; 58 String modelId1= b1.getModelIdentifier(); 59 String modelId2= b2.getModelIdentifier(); 60 int result= modelId1.compareTo(modelId2); 61 if (result != 0) { 62 return result; 63 } 64 String type1= ""; String type2= ""; IMarker marker1= b1.getMarker(); 67 if (!marker1.exists()) { 68 return 0; 69 } 70 try { 71 type1= marker1.getType(); 72 } catch (CoreException ce) { 73 DebugUIPlugin.log(ce); 74 } 75 try { 76 IMarker marker2= b2.getMarker(); 77 if (!marker2.exists()) { 78 return 0; 79 } 80 type2= marker2.getType(); 81 } catch (CoreException e) { 82 DebugUIPlugin.log(e); 83 } 84 85 result= type1.compareTo(type2); 86 if (result != 0) { 87 return result; 88 } 89 91 ILabelProvider lprov = (ILabelProvider) ((StructuredViewer)viewer).getLabelProvider(); 92 String name1= lprov.getText(e1); 93 String name2= lprov.getText(e2); 94 95 boolean lineBreakpoint= false; 96 try { 97 lineBreakpoint= marker1.isSubtypeOf(IBreakpoint.LINE_BREAKPOINT_MARKER); 98 } catch (CoreException ce) { 99 } 100 if (lineBreakpoint) { 101 return compareLineBreakpoints(b1, b2, name1,name2); 102 } 103 104 return name1.compareTo(name2); 105 } 106 107 protected int compareLineBreakpoints(IBreakpoint b1, IBreakpoint b2, String name1, String name2) { 108 int colon1= name1.indexOf(':'); 109 if (colon1 != -1) { 110 int colon2= name2.indexOf(':'); 111 if (colon2 != -1) { 112 String upToColon1= name1.substring(0, colon1); 113 if (name2.startsWith(upToColon1)) { 114 int l1= 0; 115 int l2= 0; 116 try { 117 l1= ((ILineBreakpoint)b1).getLineNumber(); 118 } catch (CoreException e) { 119 DebugUIPlugin.log(e); 120 } 121 try { 122 l2= ((ILineBreakpoint)b2).getLineNumber(); 123 } catch (CoreException e) { 124 DebugUIPlugin.log(e); 125 } 126 return l1 - l2; 127 } 128 } 129 } 130 return name1.compareTo(name2); 131 } 132 } 133 | Popular Tags |