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 package com.mindtree.techworks.insight.eventsearch;
26
27 import java.io.Serializable;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 import com.mindtree.techworks.insight.Controller;
34 import com.mindtree.techworks.insight.InsightConstants;
35 import com.mindtree.techworks.insight.gui.EventDetailsPresentation;
36 import com.mindtree.techworks.insight.gui.widgets.StatusBar;
37
38
39
40
41
42
43
44
45
46 public class SearchResults implements Serializable {
47
48
49
50
51 private static final long serialVersionUID = 2164352117429657476L;
52
53
54
55
56
57
58
59
60 private Controller controller;
61
62
63
64
65 private EventDetailsPresentation eventDetailsPresentation;
66
67
68
69
70 private SearchCriteria searchCriteria;
71
72
73
74
75 private List matchingLogEvents;
76
77
78
79
80 private Map pagedMatchingLogEvents;
81
82
83
84
85 private int currentMatchingLogEventIndex = -1;
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100 public SearchResults (Controller controller, SearchCriteria searchCriteria,
101 EventDetailsPresentation eventDetailsPresentation) {
102
103 this.controller = controller;
104 this.searchCriteria = searchCriteria;
105 this.eventDetailsPresentation = eventDetailsPresentation;
106 this.matchingLogEvents = new ArrayList();
107 this.pagedMatchingLogEvents = new HashMap();
108 }
109
110
111
112
113
114
115
116
117
118
119 public SearchCriteria getSearchCriteria () {
120
121 return this.searchCriteria;
122 }
123
124
125
126
127
128
129 public int getCurrentMatchingLogEventIndex () {
130
131 return currentMatchingLogEventIndex;
132 }
133
134
135
136
137
138
139 public int getCountOfMatchingLogEvents () {
140
141 return matchingLogEvents.size();
142 }
143
144
145
146
147
148
149 public void addMatcingLogEvent (MatchingLogEvent matchingLogEvent) {
150
151 this.matchingLogEvents.add(matchingLogEvent);
152
153
154 Long pageNum = new Long(matchingLogEvent.getPageNumber());
155 List pageList = null;
156 if (this.pagedMatchingLogEvents.containsKey(pageNum)) {
157 pageList = (List) this.pagedMatchingLogEvents.get(pageNum);
158 } else {
159 pageList = new ArrayList();
160 this.pagedMatchingLogEvents.put(pageNum, pageList);
161 }
162 pageList.add(matchingLogEvent);
163 }
164
165
166
167
168
169
170 public MatchingLogEvent getNextMatchingLogEvent () {
171
172 if ((currentMatchingLogEventIndex + 1) < matchingLogEvents.size()) {
173 return (MatchingLogEvent) matchingLogEvents
174 .get(++currentMatchingLogEventIndex);
175 } else {
176 return null;
177 }
178 }
179
180
181
182
183
184
185 public MatchingLogEvent getPrevMatchingLogEvent () {
186
187 if ((currentMatchingLogEventIndex - 1) >= 0) {
188 return (MatchingLogEvent) matchingLogEvents
189 .get(--currentMatchingLogEventIndex);
190 } else {
191 return null;
192 }
193 }
194
195
196
197
198
199
200
201 public List getMatchedEventsForPage (int pageNumber) {
202
203 return (List) this.pagedMatchingLogEvents.get(new Long(pageNumber));
204 }
205
206
207
208
209
210
211
212
213
214
215 public void navigate (String direction) {
216
217 MatchingLogEvent matchingLogEvent = null;
218 if (direction.equals(InsightConstants.getLiteral("FIRST_SEARCH_MATCH"))) {
219 if (matchingLogEvents.size() > 0) {
220 matchingLogEvent = (MatchingLogEvent) matchingLogEvents.get(0);
221 currentMatchingLogEventIndex = 0;
222 }
223 } else if (direction.equals(InsightConstants
224 .getLiteral("PREV_SEARCH_MATCH"))) {
225 matchingLogEvent = getPrevMatchingLogEvent();
226 } else if (direction.equals(InsightConstants
227 .getLiteral("NEXT_SEARCH_MATCH"))) {
228 matchingLogEvent = getNextMatchingLogEvent();
229 }
230
231 if (null != matchingLogEvent) {
232 controller.setSelectedEvent(matchingLogEvent.getPageNumber(),
233 matchingLogEvent.getEventSequenceNumber());
234 this.eventDetailsPresentation.highlightText(this.searchCriteria
235 .getSearchString(), this.searchCriteria.getSearchType());
236 } else {
237 StatusBar.getInstance().setDisplayText(0,
238 InsightConstants.getLiteral("NO_NAVIGATE"), false);
239 }
240 }
241
242 }