01: /*
02: * ToggleExtraConnection.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 workbench.gui.MainWindow;
16: import workbench.resource.ResourceMgr;
17:
18: /**
19: *
20: * @author support@sql-workbench.net
21: */
22: public class ToggleExtraConnection extends CheckBoxAction {
23: private MainWindow window;
24:
25: public ToggleExtraConnection(MainWindow client) {
26: super ("MnuTxtUseExtraConn", null);
27: this .setMenuItemName(ResourceMgr.MNU_TXT_FILE);
28: this .setEnabled(false);
29: this .window = client;
30: checkState();
31: }
32:
33: @Override
34: public void executeAction(ActionEvent e) {
35: if (this .window == null)
36: return;
37: if (window.canUseSeparateConnection()) {
38: if (window.usesSeparateConnection()) {
39: this .window.disconnectCurrentPanel();
40: this .setSwitchedOn(false);
41: } else {
42: this .window.createNewConnectionForCurrentPanel();
43: this .setSwitchedOn(true);
44: }
45: }
46: }
47:
48: public void checkState() {
49: if (this .window == null) {
50: this .setEnabled(false);
51: this .setSwitchedOn(false);
52: } else {
53: this.setEnabled(window.canUseSeparateConnection());
54: this.setSwitchedOn(window.usesSeparateConnection());
55: }
56: }
57:
58: }
|