View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2005 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  
25  package com.mindtree.techworks.insight.model;
26  
27  import java.io.Serializable;
28  
29  import com.mindtree.techworks.insight.Controller;
30  import com.mindtree.techworks.insight.InsightConstants;
31  import com.mindtree.techworks.insight.eventsearch.SearchResults;
32  import com.mindtree.techworks.insight.filter.UniqueLogCriteria;
33  import com.mindtree.techworks.insight.gui.widgets.StatusBar;
34  import com.mindtree.techworks.insight.pagination.PageSet;
35  import com.mindtree.techworks.insight.spi.LogEvent;
36  
37  /**
38   * This is the model class for Insight that represents one Page
39   * 
40   * @author antonypulicken
41   * @version $Revision: 27 $ $Date: 2007-12-16 04:58:03 -0700 (Sun, 16 Dec 2007) $
42   * @see com.mindtree.techworks.insight.model.ILogEventModel ILogEventModel
43   * @see com.mindtree.techworks.insight.spi.LogEvent LogEvent
44   */
45  public class LogEventModel implements ILogEventModel, Serializable {
46  
47  	/**
48  	 * Used for object serialization
49  	 */
50  	private static final long serialVersionUID = -1474266642451017271L;
51  
52  	/**
53  	 * PageSet instance
54  	 */
55  	protected PageSet pageSet;
56  
57  	/**
58  	 * Controller instance
59  	 */
60  	protected Controller controller;
61  
62  	/**
63  	 * Previous LogEventModel
64  	 */
65  	private LogEventModel previousLogEventModel;
66  
67  	/**
68  	 * Unique criteria
69  	 */
70  	private UniqueLogCriteria uniqueLogCriteria;
71  	
72  	/**
73  	 * Search Results if any are performed on this model.
74  	 */
75  	private SearchResults searchResults;
76  
77  	/**
78  	 * log event index
79  	 */
80  	private long logEventIndex = -1;
81  
82  	/**
83  	 * Count of events processed by this LogEventModel
84  	 */
85  	private long processedEventCount;
86  
87  	/**
88  	 * Name of the LogEventModel
89  	 */
90  	private String logEventModelName;
91  
92  	/**
93  	 * Constructor that initializes this LogEventModel
94  	 * 
95  	 * @param controller the Controller instance for this class
96  	 */
97  	public LogEventModel (Controller controller) {
98  		this.controller = controller;
99  		this.pageSet = new PageSet();
100 		this.uniqueLogCriteria = new UniqueLogCriteria();
101 	}
102 
103 	/**
104 	 * Returns the PageSet instance
105 	 * 
106 	 * @return pageSet The PageSet instance
107 	 */
108 	public PageSet getPageSet () {
109 		return this.pageSet;
110 	}
111 
112 	/**
113 	 * Clears the contents of this LogEventModel
114 	 */
115 	public void clear () {
116 		this.pageSet.clear();
117 		this.pageSet = null;
118 		this.logEventIndex = -1;
119 		this.processedEventCount = 0;
120 		clearSearchResults();
121 		this.uniqueLogCriteria.initialize();
122 		StatusBar.getInstance().clearStatisticsDisplayText();
123 	}
124 
125 
126 	/**
127 	 * This method is called when a new event is added to the model.
128 	 * 
129 	 * @param logEvent LogEvent log event.
130 	 */
131 	public void fireLogEventAdded (LogEvent logEvent) {
132 		uniqueLogCriteria.add(logEvent);
133 		this.processedEventCount += 1;
134 		// inform the controller of events being added only if this model
135 		// is the current one
136 		if (this.controller.getCurrentLogEventModel() == this){
137 			this.controller.notifyLogEventOccurred(logEvent);
138 		} else {
139 			// inform the Controller to simply update the status
140 			this.controller.setStatus();
141 		}
142 	}
143 
144 	/**
145 	 * Returns unique logged values for the supported filter criteria.
146 	 * 
147 	 * @return uniqueLogCriteria UniqueLogCriteria an object containing set of
148 	 *         unique values for the supported filter criteria
149 	 */
150 	public UniqueLogCriteria getUniqueCriteria () {
151 		return uniqueLogCriteria;
152 	}
153 
154 	/**
155 	 * Sets the previous LogEventModel
156 	 * 
157 	 * @param logEventModel The current LogEventModel
158 	 */
159 	public void setPreviousLogEventModel (LogEventModel logEventModel) {
160 		this.previousLogEventModel = logEventModel;
161 	}
162 
163 	/**
164 	 * Returns the previous LogEventModel
165 	 * 
166 	 * @return previousLogEventModel
167 	 */
168 	public LogEventModel getPreviousLogEventModel () {
169 		return this.previousLogEventModel;
170 	}
171 
172 	/**
173 	 * @param pageSet The pageSet to set.
174 	 */
175 	public void setPageSet (PageSet pageSet) {
176 		this.pageSet = pageSet;
177 	}
178 
179 	/**
180 	 * @return Returns the logEventIndex.
181 	 */
182 	public long getLogEventIndex () {
183 		return logEventIndex;
184 	}
185 
186 	/**
187 	 * @param logEventIndex The logEventIndex to set.
188 	 */
189 	public void setLogEventIndex (long logEventIndex) {
190 		this.logEventIndex = logEventIndex;
191 	}
192 	
193 	/**
194 	 * @return Returns the logEventModelName.
195 	 */
196 	public String getLogEventModelName () {
197 		return logEventModelName;
198 	}
199 
200 	/**
201 	 * @param logEventModelName The logEventModelName to set.
202 	 */
203 	public void setLogEventModelName (String logEventModelName) {
204 		this.logEventModelName = logEventModelName;
205 	}
206 	
207 	/**
208 	 * Gets the status display text for this LogEventModel
209 	 * @return the status display text
210 	 */
211 	public String getStatus() {
212 		StringBuffer textToDisplay = new StringBuffer();
213   	    String currPageCnt = String.valueOf(getPageSet().getCurrentPageCnt());
214   	    String totPageCnt = String.valueOf(getPageSet().getTotalPageCnt());
215   	    textToDisplay.append(getContext());
216   	    textToDisplay.append(currPageCnt);
217   	    textToDisplay.append(InsightConstants.PAGE_STATUS_SEPARATOR);
218   	    textToDisplay.append(totPageCnt);
219   	    if (getSearchResults() != null) {
220   	    	SearchResults searchResults = getSearchResults();
221   	    	textToDisplay.append(InsightConstants.SEARCH_RESULT_DISP_STATUS_START);
222   	    	textToDisplay.append(InsightConstants.SEARCH_RESULT_DISP_STATUS);
223   	    	textToDisplay.append(String.valueOf(searchResults.getCurrentMatchingLogEventIndex() + 1));
224   	    	textToDisplay.append(InsightConstants.PAGE_STATUS_SEPARATOR);
225   	    	textToDisplay.append(String.valueOf(searchResults.getCountOfMatchingLogEvents()));
226   	    	textToDisplay.append(InsightConstants.SEARCH_RESULT_DISP_STATUS_END);
227   	    }
228   	    return textToDisplay.toString();
229 	}
230 
231 	/**
232 	 * @return Returns the processedEventCount.
233 	 */
234 	public long getProcessedEventCount () {
235 		return processedEventCount;
236 	}
237 
238 	/**
239 	 * @param processedEventCount The processedEventCount to set.
240 	 */
241 	public void setProcessedEventCount (long processedEventCount) {
242 		this.processedEventCount = processedEventCount;
243 	}
244 	
245 	/**
246 	 * @return Returns the searchResults.
247 	 */
248 	public SearchResults getSearchResults () {
249 		return searchResults;
250 	}
251 	
252 	/**
253 	 * @param searchResults The searchResults to set.
254 	 */
255 	public void setSearchResults (SearchResults searchResults) {
256 		this.searchResults = searchResults;
257 	}
258 
259 	/**
260 	 * Clears the search results associated with this log event model
261 	 */
262 	public void clearSearchResults () {
263 		this.searchResults = null;		
264 	}
265 	
266 	/**
267 	 * Method for constructing the context text while displaying the status
268 	 * @return context 
269 	 */
270 	private String getContext() {
271 		LogEventModel logEventModel = this; 
272 		String context = logEventModel.getLogEventModelName();		
273 		while(true){		
274 			if(logEventModel.getPreviousLogEventModel()!= null){
275 				logEventModel = logEventModel.getPreviousLogEventModel();
276 				context = logEventModel.getLogEventModelName() + InsightConstants.TEXT_SEPARATOR + context;
277 			}else{
278 				break;
279 			}
280 		}
281 		return context + InsightConstants.TEXT_INDENT;
282 	}
283 	
284 }