01: /*
02: * IgnoreErrorsAction.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: import javax.swing.JCheckBoxMenuItem;
18: import javax.swing.JMenu;
19: import javax.swing.JToggleButton;
20: import javax.swing.JToolBar;
21: import javax.swing.border.Border;
22: import workbench.gui.components.WbToolbarButton;
23:
24: import workbench.resource.ResourceMgr;
25: import workbench.resource.Settings;
26:
27: /**
28: * Toggle the "ignore errors" settings
29: * @author support@sql-workbench.net
30: */
31: public class IgnoreErrorsAction extends WbAction {
32: private boolean switchedOn = false;
33: private JCheckBoxMenuItem toggleMenu;
34: private JToggleButton toggleButton;
35:
36: public IgnoreErrorsAction() {
37: super ();
38: this .initMenuDefinition("MnuTxtIgnoreErrors");
39: this .setMenuItemName(ResourceMgr.MNU_TXT_SQL);
40: this .switchedOn = Settings.getInstance().getIgnoreErrors();
41: }
42:
43: public void executeAction(ActionEvent e) {
44: this .setSwitchedOn(!this .switchedOn);
45: }
46:
47: public JToggleButton createButton() {
48: this .toggleButton = new JToggleButton(this );
49: this .toggleButton.setText(null);
50: this .toggleButton.setMargin(WbToolbarButton.MARGIN);
51: this .toggleButton
52: .setIcon(ResourceMgr.getPicture("IgnoreError"));
53: this .toggleButton.setSelected(this .switchedOn);
54: return this .toggleButton;
55: }
56:
57: public void addToToolbar(JToolBar aToolbar) {
58: if (this .toggleButton == null)
59: this .createButton();
60: aToolbar.add(this .toggleButton);
61: }
62:
63: public boolean isSwitchedOn() {
64: return this .switchedOn;
65: }
66:
67: public void setSwitchedOn(boolean aFlag) {
68: this .switchedOn = aFlag;
69: if (this .toggleMenu != null)
70: this .toggleMenu.setSelected(aFlag);
71: if (this .toggleButton != null)
72: this .toggleButton.setSelected(aFlag);
73: Settings.getInstance().setIgnoreErrors(this .switchedOn);
74: }
75:
76: public void addToMenu(JMenu aMenu) {
77: if (this .toggleMenu == null) {
78: this .toggleMenu = new JCheckBoxMenuItem();
79: this .toggleMenu.setAction(this );
80: String text = this .getValue(Action.NAME).toString();
81: int pos = text.indexOf('&');
82: if (pos > -1) {
83: char mnemonic = text.charAt(pos + 1);
84: text = text.substring(0, pos) + text.substring(pos + 1);
85: this .toggleMenu.setMnemonic((int) mnemonic);
86: }
87: this.toggleMenu.setText(text);
88: this.toggleMenu.setSelected(this.switchedOn);
89: }
90: aMenu.add(this.toggleMenu);
91: }
92:
93: }
|