Source code: com/klavergne/jext/plugins/clearcase/actions/AbstractClearCaseAction.java
1 /*
2 * 12/13/2001 - 15:41:35
3 *
4 * ClearCasePlugin.java - Plugin for Jext to integrate ClearCase
5 * Copyright (C) 2001 Kevin LaVergne
6 * klavergne@earthling.net
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22 package com.klavergne.jext.plugins.clearcase.actions;
23
24 import java.io.File;
25 import java.awt.event.ActionEvent;
26 import javax.swing.AbstractAction;
27 import javax.swing.SwingUtilities;
28 import javax.swing.SwingWorker;
29
30 import org.jext.JextFrame;
31 import org.jext.JextTextArea;
32
33 /**
34 * This is an abstract version of AbstractAction for use in Jext menus and toolbars.
35 * @author Kevin LaVergne
36 * @version 1.0
37 */
38 public abstract class AbstractClearCaseAction extends AbstractAction {
39
40 /**
41 * The JextFrame that is the parent to this Action.
42 */
43 protected JextFrame frame = null;
44
45 /**
46 * Creates a new Action with the given name and JextFrame as a parent.
47 * @param name the name of this Action
48 * @param aFrame the parent JextFrame for this Action
49 */
50 public AbstractClearCaseAction(String name, JextFrame aFrame) {
51 super(name);
52 frame = aFrame;
53 }
54
55 /**
56 * Implementation of the ActionListener class. Uses the SwingWorker class to execute
57 * functionality in a separate thread so that the Jext GUI will repaint before or
58 * while this is running.
59 * @param event the event
60 */
61 public void actionPerformed(final ActionEvent event) {
62 final SwingWorker worker = new SwingWorker() {
63 public Object construct() {
64 frame.showWaitCursor();
65 Boolean result = new Boolean(performAction(event));
66 frame.hideWaitCursor();
67 return result;
68 }
69
70 public void finished() {
71 Boolean reload = (Boolean) get();
72 if (reload != null && reload.booleanValue())
73 reloadFile();
74 }
75 };
76 worker.start();
77 }
78
79 /**
80 * Subclasses of this abstract class must implement this method and perform the
81 * functionality that they require in this method.
82 * @param event the event
83 * @return a boolean value indicating whether Jext should reload the current file
84 */
85 public abstract boolean performAction(ActionEvent event);
86
87 /**
88 * Returns the full path to the currently selected file in Jext.
89 * @return the full path to the currently selected file in Jext
90 */
91 protected String getSelectedFileName() {
92 JextTextArea textArea = frame.getTextArea();
93 File file = textArea.getFile();
94 return file.getAbsolutePath();
95 }
96
97 /**
98 * Reloads the current file in Jext.
99 */
100 protected void reloadFile() {
101 JextTextArea textArea = frame.getTextArea();
102 String fileName = textArea.getCurrentFile();
103 if (fileName != null && fileName.length() > 0)
104 textArea.open(fileName);
105 textArea.requestFocus();
106 }
107 }