trace/traceanalyser/com.nokia.s60tools.traceanalyser/src/com/nokia/s60tools/traceanalyser/ui/views/RuleTableDataSorter.java
changeset 9 14dc2103a631
equal deleted inserted replaced
8:15296fd0af4a 9:14dc2103a631
       
     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.traceanalyser.ui.views;
       
    20 import org.eclipse.jface.viewers.Viewer;
       
    21 import org.eclipse.jface.viewers.ViewerSorter;
       
    22 
       
    23 import com.nokia.s60tools.traceanalyser.containers.RuleInformation;
       
    24 
       
    25 
       
    26 /**
       
    27  * class RuleTableDataSorter
       
    28  * Data sorter for Trace Analyser's rule view.
       
    29  */
       
    30 
       
    31 public class RuleTableDataSorter extends ViewerSorter {
       
    32 
       
    33 	/**
       
    34 	 * Import function data is sorted by file name
       
    35 	 */
       
    36 	public static final int RULE_NAME = 2;
       
    37 	/**
       
    38 	 * 
       
    39 	 */
       
    40 	public static final int PASS = 3;
       
    41 	public static final int FAIL = 4;
       
    42 	public static final int PASSPERCENT = 5;
       
    43 	public static final int MIN = 6;
       
    44 	public static final int MAX = 7;
       
    45 	public static final int AVG = 8;
       
    46 	public static final int MED = 9;
       
    47 
       
    48 	private int sortCriteria;
       
    49 	
       
    50 	public RuleTableDataSorter(int sortCriteria) {
       
    51 		super();		
       
    52 		// By default set sort criterie
       
    53 		this.sortCriteria = sortCriteria;
       
    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 		RuleInformation f1 = (RuleInformation) e1;
       
    66 		RuleInformation f2 = (RuleInformation) e2;
       
    67 		
       
    68 		switch (sortCriteria) {
       
    69 		
       
    70 		case RULE_NAME:
       
    71 			comparisonResult = f1.getRule().getName().compareToIgnoreCase(f2.getRule().getName());
       
    72 			break;
       
    73 		case PASS:
       
    74 			if(f1.getPass() < f2.getPass()){
       
    75 				comparisonResult = 1;
       
    76 			}
       
    77 			else{
       
    78 				comparisonResult = -1;
       
    79 
       
    80 			}
       
    81 			break;
       
    82 		case FAIL:
       
    83 			if(f1.getFail() < f2.getFail()){
       
    84 				comparisonResult = 1;
       
    85 			}
       
    86 			else{
       
    87 				comparisonResult = -1;
       
    88 
       
    89 			}
       
    90 			break;
       
    91 
       
    92 		case PASSPERCENT:
       
    93 			if(f1.getPassPercent() < f2.getPassPercent()){
       
    94 				comparisonResult = 1;
       
    95 			}
       
    96 			else{
       
    97 				comparisonResult = -1;
       
    98  			}
       
    99 			break;
       
   100 
       
   101 		case MIN:
       
   102 			if(f1.getMin() < f2.getMin()){
       
   103 				comparisonResult = 1;
       
   104 			}
       
   105 			else{
       
   106 				comparisonResult = -1;
       
   107 
       
   108 			}
       
   109 			break;
       
   110 
       
   111 		case MAX:
       
   112 			if(f1.getMax() < f2.getMax()){
       
   113 				comparisonResult = 1;
       
   114 			}
       
   115 			else{
       
   116 				comparisonResult = -1;
       
   117 
       
   118 			}
       
   119 			break;
       
   120 
       
   121 		case MED:
       
   122 			if(f1.getMed() < f2.getMed()){
       
   123 				comparisonResult = 1;
       
   124 			}
       
   125 			else{
       
   126 				comparisonResult = -1;
       
   127 
       
   128 			}
       
   129 			break;
       
   130 		case AVG:
       
   131 			if(f1.getAvg() < f2.getAvg()){
       
   132 				comparisonResult = 1;
       
   133 			}
       
   134 			else{
       
   135 				comparisonResult = -1;
       
   136 
       
   137 			}
       
   138 			break;
       
   139 			
       
   140 
       
   141 		default:
       
   142 			break;
       
   143 		}
       
   144 		
       
   145 		return comparisonResult;
       
   146 	
       
   147 	}
       
   148 	
       
   149 
       
   150 
       
   151 }