Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8ae15ceddc559879e0ef1d50964310b79804202a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*******************************************************************************
 * Copyright (c) 2000, 2006 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.views.breakpoints;


import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.ILineBreakpoint;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.viewers.IBasicPropertyConstants;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
/**
 * @since 3.3
 */
public class BreakpointsComparator extends ViewerComparator {
		/**
		 * @see ViewerSorter#isSorterProperty(Object, String)
		 */
		public boolean isSorterProperty(Object element,String propertyId) {
			return propertyId.equals(IBasicPropertyConstants.P_TEXT);
		}
		
		/**
		 * Returns a negative, zero, or positive number depending on whether
		 * the first element is less than, equal to, or greater than
		 * the second element.
		 * <p>
		 * Group breakpoints by debug model
		 * 	within debug model, group breakpoints by type 
		 * 		within type groups, sort by line number (if applicable) and then
		 * 		alphabetically by label
		 * 
		 * @param viewer the viewer
		 * @param e1 the first element
		 * @param e2 the second element
		 * @return a negative number if the first element is less than the 
		 *  second element; the value <code>0</code> if the first element is
		 *  equal to the second element; and a positive number if the first
		 *  element is greater than the second element
		 */
		public int compare(Viewer viewer, Object e1, Object e2) {
            if (!(e1 instanceof IBreakpoint)) {
                return super.compare(viewer, e1, e2);
            }
	
			IBreakpoint b1= (IBreakpoint)e1;
			IBreakpoint b2= (IBreakpoint)e2;
			String modelId1= b1.getModelIdentifier();
			String modelId2= b2.getModelIdentifier();
			int result= modelId1.compareTo(modelId2);
			if (result != 0) {
				return result;
			}
			String type1= ""; //$NON-NLS-1$
			String type2= ""; //$NON-NLS-1$
			IMarker marker1= b1.getMarker();
			if (!marker1.exists()) {
				return 0;
			}
			try {
				type1= marker1.getType();
			} catch (CoreException ce) {
				DebugUIPlugin.log(ce);
			}
			try {
				IMarker marker2= b2.getMarker();
				if (!marker2.exists()) {
					return 0;
				}
				type2= marker2.getType();	
			} catch (CoreException e) {
				DebugUIPlugin.log(e);
			}
		
			result= type1.compareTo(type2);
			if (result != 0) {
				return result;
			}
			// model and type are the same
		
			ILabelProvider lprov = (ILabelProvider) ((StructuredViewer)viewer).getLabelProvider();
			String name1= lprov.getText(e1);
			String name2= lprov.getText(e2);
	
			boolean lineBreakpoint= false;
			try {
				lineBreakpoint= marker1.isSubtypeOf(IBreakpoint.LINE_BREAKPOINT_MARKER);
			} catch (CoreException ce) {
			}
			if (lineBreakpoint) {
				return compareLineBreakpoints(b1, b2, name1,name2);
			} 
			
			return name1.compareTo(name2);		
		}
		
		protected int compareLineBreakpoints(IBreakpoint b1, IBreakpoint b2, String name1, String name2) {
			int colon1= name1.indexOf(':');
			if (colon1 != -1) {
				int colon2= name2.indexOf(':');
				if (colon2 != -1) {
					String upToColon1= name1.substring(0, colon1);
					if (name2.startsWith(upToColon1)) {
						int l1= 0;
						int l2= 0;
						try {
							l1= ((ILineBreakpoint)b1).getLineNumber();	
						} catch (CoreException e) {
							DebugUIPlugin.log(e);
						}
						try {
							l2= ((ILineBreakpoint)b2).getLineNumber();	
						} catch (CoreException e) {
							DebugUIPlugin.log(e);
						}
						return l1 - l2;
					}
				}
			}
			return name1.compareTo(name2);
		}
	}

Back to the top