01: /*
02: * OptimizeAllColumnsAction.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:
18: import javax.swing.KeyStroke;
19: import workbench.gui.components.TableColumnOptimizer;
20:
21: import workbench.gui.components.WbTable;
22: import workbench.resource.Settings;
23: import workbench.util.WbThread;
24:
25: /**
26: * @author support@sql-workbench.net
27: */
28: public class OptimizeAllColumnsAction extends WbAction {
29: protected TableColumnOptimizer optimizer;
30:
31: public OptimizeAllColumnsAction(WbTable client) {
32: super ();
33: this .setClient(client);
34: this .initMenuDefinition("MnuTxtOptimizeAllCol", KeyStroke
35: .getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK));
36: }
37:
38: public void disableShortcut() {
39: this .setAccelerator(null);
40: }
41:
42: public void executeAction(ActionEvent e) {
43: if (optimizer == null)
44: return;
45: final boolean shiftPressed = isShiftPressed(e);
46: Thread t = new WbThread("OptimizeAllCols Thread") {
47: public void run() {
48: optimizer.optimizeAllColWidth(shiftPressed
49: || Settings.getInstance()
50: .getIncludeHeaderInOptimalWidth());
51: }
52: };
53: t.start();
54: }
55:
56: public boolean hasShiftModifier() {
57: return true;
58: }
59:
60: public void setClient(WbTable client) {
61: this .optimizer = (client != null ? new TableColumnOptimizer(
62: client) : null);
63: this.setEnabled(client != null);
64: }
65: }
|