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.gui.Insight;
31 import com.mindtree.techworks.insight.receiver.AbstractReceiver;
32
33 /**
34 * The <code>StopReceiverAction</code> class is an AbstractAction derivative
35 * that stops the currently active events receiver
36 *
37 * @author Regunath B
38 * @version 1.0, 05/07/13
39 * @see com.mindtree.techworks.insight.gui.Insight
40 */
41
42 public class StopReceiverAction extends AbstractAction {
43
44 /**
45 * UID for serialized form
46 */
47 private static final long serialVersionUID = 2541505596023741695L;
48
49 /**
50 * The Insight instance that created this Action instance
51 */
52 private Insight insight;
53
54 /**
55 * Constructor for this class
56 *
57 * @param insight
58 * the Insight that created an instance of this class
59 */
60 public StopReceiverAction (Insight insight) {
61
62 this.insight = insight;
63 }
64
65 /**
66 * Overriden super class method. It stops the tailing receivers if they are
67 * listening. The two currently known tail capable receiver actions are
68 * {@link LoadLocalFileAction LoadLocalFileAction} and
69 * {@link RemoteProtocolListenerAction RemoteProtocolListenerAction} (always
70 * tailing).
71 *
72 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
73 */
74 public void actionPerformed (ActionEvent e) {
75
76 AbstractReceiver receiver = LoadLocalFileAction.getInstance ()
77 .getReceiver ();
78
79 if (null != receiver) {
80 receiver.shutdown ();
81 }
82
83 // Do the same for the remote protocol receiver
84 // SF.net defect id: 1931487, this is a work around as the receivers
85 // from the LoadLocalFileAction is never removed, hence if a local file
86 // is loaded first, and then the remote receiver started, in the old
87 // way of doing things, the remote receiver can never be stopped.
88 receiver = RemoteProtocolListenerAction.getInstance ().getReceiver ();
89 if (null != receiver) {
90 receiver.shutdown ();
91 }
92 }
93
94 /**
95 * @return the insight
96 */
97 public Insight getInsight() {
98 return insight;
99 }
100 }