|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.crashanalyser.model; |
|
19 |
|
20 import org.eclipse.jface.viewers.ViewerSorter; |
|
21 import org.eclipse.jface.viewers.Viewer; |
|
22 |
|
23 import com.nokia.s60tools.crashanalyser.containers.ErrorLibraryError; |
|
24 |
|
25 /** |
|
26 * Sorts errors correctly in ErrorDialog's panics list. |
|
27 * |
|
28 * E.g. |
|
29 * |
|
30 * USER 1 |
|
31 * USER 2 |
|
32 * USER 34 |
|
33 * W32 1 |
|
34 * W32 2 |
|
35 * |
|
36 */ |
|
37 public class PanicsViewerSorter extends ViewerSorter { |
|
38 |
|
39 @Override |
|
40 public int compare(Viewer viewer, Object e1, Object e2) { |
|
41 String panicName1 = ((ErrorLibraryError)e1).toString().trim(); |
|
42 String panicName2 = ((ErrorLibraryError)e2).toString().trim(); |
|
43 |
|
44 // separate panic id from panic name |
|
45 // panic name is category + panic id e.g. "W32 4" |
|
46 int index1 = panicName1.lastIndexOf(' '); |
|
47 int index2 = panicName2.lastIndexOf(' '); |
|
48 if (index1 > -1 && index2 > -1) { |
|
49 String category1 = panicName1.substring(0, index1).trim(); |
|
50 String category2 = panicName2.substring(0, index2).trim(); |
|
51 String panicId1 = panicName1.substring(index1).trim(); |
|
52 String panicId2 = panicName2.substring(index2).trim(); |
|
53 int res = category1.compareTo(category2); |
|
54 if (res == 0) { |
|
55 try { |
|
56 int panic1 = Integer.valueOf( panicId1 ).intValue(); |
|
57 int panic2 = Integer.valueOf( panicId2 ).intValue(); |
|
58 if (panic1 < panic2) |
|
59 return -1; |
|
60 else if (panic1 > panic2) |
|
61 return 1; |
|
62 else |
|
63 return 0; |
|
64 } catch (Exception e) { |
|
65 return panicName1.compareTo(panicName2); |
|
66 } |
|
67 } else { |
|
68 return panicName1.compareTo(panicName2); |
|
69 } |
|
70 |
|
71 } else { |
|
72 return panicName1.compareTo(panicName2); |
|
73 } |
|
74 } |
|
75 } |