01: /*
02: * RunMacroAction.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 javax.swing.Action;
17:
18: import workbench.gui.MainWindow;
19: import workbench.gui.sql.SqlPanel;
20: import workbench.log.LogMgr;
21: import workbench.resource.ResourceMgr;
22: import workbench.util.NumberStringCache;
23: import workbench.util.StringUtil;
24:
25: /**
26: * @author support@sql-workbench.net
27: */
28: public class RunMacroAction extends WbAction {
29: private MainWindow client;
30: private String macroName;
31:
32: public RunMacroAction(MainWindow aClient, String aName, int index) {
33: super ();
34: this .macroName = aName;
35: this .client = aClient;
36: String menuTitle = aName;
37:
38: if (index < 10) {
39: menuTitle = "&" + NumberStringCache.getNumberString(index)
40: + " - " + aName;
41: }
42: this .setMenuText(menuTitle);
43: this .setMenuItemName(ResourceMgr.MNU_TXT_MACRO);
44: String desc = ResourceMgr
45: .getDescription("MnuTxtRunMacro", true);
46: desc = StringUtil.replace(desc, "%macro%", aName);
47: this .putValue(Action.SHORT_DESCRIPTION, desc);
48: this .setIcon(null);
49: }
50:
51: public void executeAction(ActionEvent e) {
52: if (this .client != null && this .macroName != null) {
53: boolean shiftPressed = isShiftPressed(e);
54: SqlPanel sql = this .client.getCurrentSqlPanel();
55: if (sql != null) {
56: sql.executeMacro(macroName, shiftPressed);
57: } else {
58: LogMgr.logWarning("RunMacroAction.actionPerformed()",
59: "Don't have a curretn SqlPanel!");
60: }
61: }
62: }
63:
64: }
|