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.ViewerComparator; 24 27 public class BreakpointsComparator extends ViewerComparator { 28 31 public boolean isSorterProperty(Object element,String propertyId) { 32 return propertyId.equals(IBasicPropertyConstants.P_TEXT); 33 } 34 35 53 public int compare(Viewer viewer, Object e1, Object e2) { 54 if (!(e1 instanceof IBreakpoint)) { 55 return super.compare(viewer, e1, e2); 56 } 57 58 IBreakpoint b1= (IBreakpoint)e1; 59 IBreakpoint b2= (IBreakpoint)e2; 60 String modelId1= b1.getModelIdentifier(); 61 String modelId2= b2.getModelIdentifier(); 62 int result= modelId1.compareTo(modelId2); 63 if (result != 0) { 64 return result; 65 } 66 String type1= ""; String type2= ""; IMarker marker1= b1.getMarker(); 69 if (!marker1.exists()) { 70 return 0; 71 } 72 try { 73 type1= marker1.getType(); 74 } catch (CoreException ce) { 75 DebugUIPlugin.log(ce); 76 } 77 try { 78 IMarker marker2= b2.getMarker(); 79 if (!marker2.exists()) { 80 return 0; 81 } 82 type2= marker2.getType(); 83 } catch (CoreException e) { 84 DebugUIPlugin.log(e); 85 } 86 87 result= type1.compareTo(type2); 88 if (result != 0) { 89 return result; 90 } 91 93 ILabelProvider lprov = (ILabelProvider) ((StructuredViewer)viewer).getLabelProvider(); 94 String name1= lprov.getText(e1); 95 String name2= lprov.getText(e2); 96 97 boolean lineBreakpoint= false; 98 try { 99 lineBreakpoint= marker1.isSubtypeOf(IBreakpoint.LINE_BREAKPOINT_MARKER); 100 } catch (CoreException ce) { 101 } 102 if (lineBreakpoint) { 103 return compareLineBreakpoints(b1, b2, name1,name2); 104 } 105 106 return name1.compareTo(name2); 107 } 108 109 protected int compareLineBreakpoints(IBreakpoint b1, IBreakpoint b2, String name1, String name2) { 110 int colon1= name1.indexOf(':'); 111 if (colon1 != -1) { 112 int colon2= name2.indexOf(':'); 113 if (colon2 != -1) { 114 String upToColon1= name1.substring(0, colon1); 115 if (name2.startsWith(upToColon1)) { 116 int l1= 0; 117 int l2= 0; 118 try { 119 l1= ((ILineBreakpoint)b1).getLineNumber(); 120 } catch (CoreException e) { 121 DebugUIPlugin.log(e); 122 } 123 try { 124 l2= ((ILineBreakpoint)b2).getLineNumber(); 125 } catch (CoreException e) { 126 DebugUIPlugin.log(e); 127 } 128 return l1 - l2; 129 } 130 } 131 } 132 return name1.compareTo(name2); 133 } 134 } 135 | Popular Tags |