|
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 package com.nokia.s60tools.swmtanalyser.editors; |
|
18 |
|
19 import java.util.ArrayList; |
|
20 import java.util.Arrays; |
|
21 import java.util.List; |
|
22 |
|
23 import org.eclipse.jface.viewers.Viewer; |
|
24 import org.eclipse.jface.viewers.ViewerFilter; |
|
25 |
|
26 import com.nokia.s60tools.swmtanalyser.analysers.AnalyserConstants; |
|
27 import com.nokia.s60tools.swmtanalyser.analysers.ResultElements; |
|
28 import com.nokia.s60tools.swmtanalyser.dialogs.AdvancedFilterDialog.FilterInput; |
|
29 |
|
30 /** |
|
31 * Customized ViewerFilter for TableViewer in Analysis tab. |
|
32 * |
|
33 */ |
|
34 public class IssuesFilter extends ViewerFilter { |
|
35 |
|
36 //Filter text |
|
37 private String search_key = null; |
|
38 //Settings selected in the advanced filter options dialog |
|
39 private FilterInput adv_options = null; |
|
40 |
|
41 /** |
|
42 * Set filter text |
|
43 * @param value |
|
44 */ |
|
45 public void setFilterText(String value) |
|
46 { |
|
47 search_key = value; |
|
48 } |
|
49 |
|
50 /** |
|
51 * Set advanced filter to issues |
|
52 * @param adv_option |
|
53 */ |
|
54 public void setAdvancedSearchOptions(FilterInput adv_option) |
|
55 { |
|
56 this.adv_options = adv_option; |
|
57 } |
|
58 |
|
59 /* (non-Javadoc) |
|
60 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
|
61 */ |
|
62 public boolean select(Viewer viewer, Object parentElement, Object element) { |
|
63 |
|
64 //If the search is done using the advanced filter options dialog |
|
65 if(adv_options!=null) |
|
66 { |
|
67 int filter_option = adv_options.getName_Filter_option(); |
|
68 String filter_text = adv_options.getFilter_text(); |
|
69 List<String> events = new ArrayList<String>(); |
|
70 if(adv_options.getEvents()!=null) |
|
71 events = Arrays.asList(adv_options.getEvents()); |
|
72 |
|
73 List<AnalyserConstants.Priority> severities = new ArrayList<AnalyserConstants.Priority>(); |
|
74 if(adv_options.getSeverities()!=null) |
|
75 severities = Arrays.asList(adv_options.getSeverities()); |
|
76 |
|
77 int delta_bytes_option = adv_options.getDelta_bytes_option(); |
|
78 long s1 = adv_options.getStart_size(); |
|
79 long e1 = adv_options.getEnd_size(); |
|
80 |
|
81 int delta_count_option = adv_options.getDelta_count_option(); |
|
82 long s2 = adv_options.getStart_count(); |
|
83 long e2 = adv_options.getEnd_count(); |
|
84 |
|
85 if(element instanceof ResultElements) |
|
86 { |
|
87 ResultElements item = (ResultElements)element; |
|
88 String item_name = item.getItemName(); |
|
89 String event = item.getEvent(); |
|
90 long delta = item.getDeltaValue(); |
|
91 AnalyserConstants.Priority p = item.getPriority(); |
|
92 |
|
93 boolean flag = true; |
|
94 |
|
95 if(filter_option == 0 && filter_text!=null && !item_name.toLowerCase().startsWith(filter_text.toLowerCase())) |
|
96 return false; |
|
97 if(filter_option == 1 && filter_text!=null && item_name.toLowerCase().indexOf(filter_text.toLowerCase()) == -1) |
|
98 return false; |
|
99 if(events.size()>0 && !events.contains(event)) |
|
100 return false; |
|
101 if(severities.size()>0 && !severities.contains(p)) |
|
102 return false; |
|
103 if(item.getType().compareTo(AnalyserConstants.DeltaType.SIZE)==0) |
|
104 { |
|
105 switch (delta_bytes_option) { |
|
106 case 0: |
|
107 //flag = flag && true; |
|
108 break; |
|
109 case 1: |
|
110 if(delta < s1 || delta > e1) |
|
111 return false; |
|
112 break; |
|
113 case 2: |
|
114 if(delta != s1) |
|
115 return false; |
|
116 break; |
|
117 case 3: |
|
118 if(delta < s1) |
|
119 return false; |
|
120 break; |
|
121 case 4: |
|
122 if(delta > s1) |
|
123 return false; |
|
124 break; |
|
125 |
|
126 default: |
|
127 break; |
|
128 } |
|
129 } |
|
130 else if(item.getType().compareTo(AnalyserConstants.DeltaType.COUNT)==0) |
|
131 { |
|
132 switch (delta_count_option) { |
|
133 case 0: |
|
134 //flag = flag && true; |
|
135 break; |
|
136 case 1: |
|
137 if(delta < s2 || delta > e2) |
|
138 return false; |
|
139 break; |
|
140 case 2: |
|
141 if(delta != s2) |
|
142 return false; |
|
143 break; |
|
144 case 3: |
|
145 if(delta < s2) |
|
146 return false; |
|
147 break; |
|
148 case 4: |
|
149 if(delta > s2) |
|
150 return false; |
|
151 break; |
|
152 |
|
153 default: |
|
154 break; |
|
155 } |
|
156 } |
|
157 |
|
158 return flag; |
|
159 } |
|
160 } |
|
161 |
|
162 //If searching is cancelled. |
|
163 if(search_key == null) |
|
164 return true; |
|
165 |
|
166 //If search is done using the severity dropdown in the Analysis tab. |
|
167 if(element instanceof ResultElements) |
|
168 { |
|
169 ResultElements item = (ResultElements)element; |
|
170 AnalyserConstants.Priority p = item.getPriority(); |
|
171 if(p.name().toLowerCase().matches(search_key.toLowerCase())) |
|
172 return true; |
|
173 else |
|
174 return false; |
|
175 } |
|
176 return true; |
|
177 } |
|
178 } |