01: /*
02: * SpoolDataAction.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:
16: import workbench.interfaces.Exporter;
17: import workbench.resource.ResourceMgr;
18: import workbench.interfaces.TextSelectionListener;
19: import workbench.gui.sql.EditorPanel;
20:
21: /**
22: * @author support@sql-workbench.net
23: */
24: public class SpoolDataAction extends WbAction implements
25: TextSelectionListener {
26: private Exporter client;
27: private EditorPanel editor;
28: private boolean canExport = false;
29:
30: public SpoolDataAction(Exporter aClient) {
31: this (aClient, "MnuTxtSpoolData");
32: }
33:
34: public SpoolDataAction(Exporter aClient, String msgKey) {
35: super ();
36: this .client = aClient;
37: this .initMenuDefinition(msgKey);
38: this .setIcon(ResourceMgr.getImage("SpoolData"));
39: this .setMenuItemName(ResourceMgr.MNU_TXT_SQL);
40: this .setEnabled(false);
41: }
42:
43: public void canExport(boolean flag) {
44: this .canExport = flag;
45: checkEnabled();
46: }
47:
48: public void executeAction(ActionEvent e) {
49: this .client.exportData();
50: }
51:
52: public void setEditor(EditorPanel ed) {
53: this .editor = ed;
54: this .editor.addSelectionListener(this );
55: checkEnabled();
56: }
57:
58: private void checkEnabled() {
59: if (this .editor != null) {
60: this .setEnabled(editor.isTextSelected() && canExport);
61: } else {
62: this .setEnabled(false);
63: }
64: }
65:
66: public void selectionChanged(int newStart, int newEnd) {
67: checkEnabled();
68: }
69:
70: }
|