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  package com.mindtree.techworks.insight.gui.action;
25  
26  import java.awt.event.ActionEvent;
27  
28  import javax.swing.AbstractAction;
29  
30  import com.mindtree.techworks.insight.Controller;
31  import com.mindtree.techworks.insight.InsightConstants;
32  import com.mindtree.techworks.insight.gui.widgets.StatusBar;
33  import com.mindtree.techworks.insight.preferences.util.PreferenceInterpreter;
34  
35  /**
36  *
37  * The <code>LocateAction</code> class is an AbstractAction derivative that
38  * locates the selected LogEvent
39  *
40  * @author  Antony 
41  * @version 1.0, 04/10/25
42  * @see     com.mindtree.techworks.insight.gui.Insight
43  */
44  
45  public class LocateAction extends AbstractAction {
46  	
47  
48  	/**
49  	 * Used for object serialization
50  	 */
51  	private static final long serialVersionUID = -3578056532882836648L;
52  
53  	/**
54  	 * The LocateAction instance
55  	 */
56  	private static LocateAction instance;
57  	
58  	/**
59  	 * The Controller instance
60  	 */
61  	private Controller controller;
62  	
63  	/**
64  	 * Private constructor for this class to prevent multiple instances
65  	 * @param controller 
66  	 */
67  	private LocateAction(Controller controller) {
68  		this.controller = controller;
69  	}
70  	
71  	
72  	/**
73  	 * Accessor method for getting the singleton instance of this class
74  	 * @param controller 
75  	 */
76  	public static synchronized LocateAction getInstance(Controller controller){
77  		if(instance == null){
78  			instance = new LocateAction(controller);
79  		}
80  		return instance;
81  	}
82  	
83  	/**
84  	 * Overriden super class method. 
85  	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
86  	 */
87  	public void actionPerformed(ActionEvent e) {		
88  		if (controller.getCurrentLogEventModel() == null) {
89  			return;
90  		}		
91  		long eventSequenceNumber = controller.getCurrentLogEventModel().getLogEventIndex();
92  		if (eventSequenceNumber < 0) {
93  			StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_LOCATE_FAILURE"),false);
94  			return;
95  		}
96  	
97  		long eventsPerPage = PreferenceInterpreter.getCachePageSize();		
98  		int pageNumber = (int)((eventSequenceNumber-1)/eventsPerPage+1);
99  		if(!controller.getCurrentLogEventModel().equals(controller.getRootLogEventModel())){
100 			controller.clearCurrentModel();	
101 		}
102 		controller.setCurrentLogEventModel(controller.getRootLogEventModel(),pageNumber,eventSequenceNumber);
103 		
104 	}
105 }