01: /*
02: * CloseResultTabAction.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.actions;
13:
14: import java.awt.event.ActionEvent;
15: import java.awt.event.InputEvent;
16: import java.awt.event.KeyEvent;
17: import javax.swing.JTabbedPane;
18: import javax.swing.JTabbedPane;
19: import javax.swing.KeyStroke;
20: import javax.swing.event.ChangeEvent;
21: import javax.swing.event.ChangeListener;
22: import workbench.gui.sql.SqlPanel;
23: import workbench.resource.ResourceMgr;
24:
25: /**
26: * An action to close the currently selected result tab of a SqlPanel.
27: *
28: * @author support@sql-workbench.net
29: */
30: public class CloseResultTabAction extends WbAction implements
31: ChangeListener {
32: private SqlPanel client;
33:
34: public CloseResultTabAction(SqlPanel aClient) {
35: super ();
36: this .client = aClient;
37: this .initMenuDefinition("MnuTxtCloseResultTab", KeyStroke
38: .getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK
39: | InputEvent.SHIFT_MASK));
40: this .setMenuItemName(ResourceMgr.MNU_TXT_DATA);
41: this .setIcon(null);
42: this .client.addResultTabChangeListener(this );
43: this .setEnabled(false);
44: }
45:
46: public void executeAction(ActionEvent e) {
47: client.closeCurrentResult();
48: }
49:
50: public void stateChanged(ChangeEvent evt) {
51: try {
52: JTabbedPane tab = (JTabbedPane) evt.getSource();
53: int index = tab.getSelectedIndex();
54: boolean resultTab = (index == tab.getTabCount() - 1);
55: this .setEnabled(!resultTab);
56: } catch (Exception e) {
57: e.printStackTrace();
58: }
59: }
60:
61: }
|