|
1 /* |
|
2 * Copyright (c) 2009 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 |
|
19 package com.nokia.s60tools.memspy.ui.views; |
|
20 |
|
21 import org.eclipse.jface.viewers.Viewer; |
|
22 |
|
23 import com.nokia.s60tools.memspy.model.MemSpyFileBundle; |
|
24 import com.nokia.s60tools.ui.S60ToolsViewerSorter; |
|
25 |
|
26 /** |
|
27 * class MemSpyDataSorter |
|
28 * Data sorter for MemSpy's main view. |
|
29 */ |
|
30 |
|
31 public class MemSpyDataSorter extends S60ToolsViewerSorter { |
|
32 |
|
33 /** |
|
34 * Import function data is sorted by file type |
|
35 */ |
|
36 public static final int FILE_TYPE = 1; |
|
37 /** |
|
38 * Import function data is sorted by file name |
|
39 */ |
|
40 public static final int FILENAME = 2; |
|
41 |
|
42 /** |
|
43 * Import function data is sorted by time |
|
44 */ |
|
45 public static final int TIME = 3; |
|
46 |
|
47 /** |
|
48 * Constructor |
|
49 */ |
|
50 public MemSpyDataSorter() { |
|
51 super(); |
|
52 // By default set sorting to time |
|
53 setSortCriteria(TIME); |
|
54 } |
|
55 |
|
56 /* (non-Javadoc) |
|
57 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
|
58 */ |
|
59 public int compare(Viewer viewer, Object e1, Object e2) { |
|
60 |
|
61 |
|
62 // By default comparison does not do any ordering |
|
63 int comparisonResult = 0; |
|
64 |
|
65 MemSpyFileBundle f1 = (MemSpyFileBundle) e1; |
|
66 MemSpyFileBundle f2 = (MemSpyFileBundle) e2; |
|
67 |
|
68 switch (sortCriteria) { |
|
69 |
|
70 case FILE_TYPE: |
|
71 comparisonResult = f1.getFileType().compareToIgnoreCase( f2.getFileType() ); |
|
72 // when type is same, sort alphabetically |
|
73 if( comparisonResult == 0 ){ |
|
74 comparisonResult = numericSort( f2.getTimeAsLong(), f1.getTimeAsLong() ); |
|
75 } |
|
76 break; |
|
77 case FILENAME: |
|
78 comparisonResult = f1.getFileName().compareToIgnoreCase( f2.getFileName() ); |
|
79 break; |
|
80 case TIME: |
|
81 comparisonResult = numericSort( f2.getTimeAsLong(), f1.getTimeAsLong() ); |
|
82 if( comparisonResult == 0 ){ |
|
83 comparisonResult = numericSort( f2.getCycleNumberFromFileName(), f1.getCycleNumberFromFileName() ); |
|
84 } |
|
85 |
|
86 break; |
|
87 case CRITERIA_NO_SORT: |
|
88 comparisonResult = f2.getFileType().compareToIgnoreCase( f1.getFileType() ); |
|
89 // when type is same, sort by file time |
|
90 if( comparisonResult == 0 ){ |
|
91 comparisonResult = numericSort( f2.getTimeAsLong(), f1.getTimeAsLong() ); |
|
92 } |
|
93 break; |
|
94 default: |
|
95 break; |
|
96 } |
|
97 |
|
98 return comparisonResult; |
|
99 } |
|
100 |
|
101 } |