01: /*
02: * SqlTabPopup.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.menu;
13:
14: import javax.swing.JPopupMenu;
15: import workbench.gui.MainWindow;
16: import workbench.gui.actions.AddTabAction;
17: import workbench.gui.actions.FileDiscardAction;
18: import workbench.gui.actions.NewDbExplorerPanelAction;
19: import workbench.gui.actions.RemoveTabAction;
20: import workbench.gui.actions.RenameTabAction;
21: import workbench.gui.sql.EditorPanel;
22: import workbench.gui.sql.SqlPanel;
23: import workbench.interfaces.MainPanel;
24: import workbench.gui.actions.InsertTabAction;
25: import workbench.gui.actions.MoveSqlTabLeft;
26: import workbench.gui.actions.MoveSqlTabRight;
27: import workbench.gui.actions.ToggleExtraConnection;
28:
29: /**
30: * @author support@sql-workbench.net
31: */
32: public class SqlTabPopup extends JPopupMenu {
33: private AddTabAction add;
34: private NewDbExplorerPanelAction newDbExp;
35: private RemoveTabAction remove;
36: private RenameTabAction rename;
37: private MoveSqlTabLeft moveLeft;
38: private MoveSqlTabRight moveRight;
39: private InsertTabAction insert;
40:
41: public SqlTabPopup(MainWindow aClient) {
42: this .add = new AddTabAction(aClient);
43: this .add(add.getMenuItem());
44: this .insert = new InsertTabAction(aClient);
45: this .add(insert.getMenuItem());
46:
47: this .remove = new RemoveTabAction(aClient);
48: this .add(remove.getMenuItem());
49:
50: if (aClient.canRenameTab()) {
51: this .rename = new RenameTabAction(aClient);
52: this .add(rename.getMenuItem());
53: }
54:
55: this .addSeparator();
56:
57: this .newDbExp = new NewDbExplorerPanelAction(aClient,
58: "MnuTxtAddExplorerPanel");
59: this .newDbExp.setIcon(null);
60: this .add(newDbExp);
61:
62: if (aClient.canUseSeparateConnection()) {
63: ToggleExtraConnection toggle = new ToggleExtraConnection(
64: aClient);
65: this .add(toggle.getMenuItem());
66: }
67:
68: MainPanel panel = aClient.getCurrentPanel();
69: if (panel instanceof SqlPanel) {
70: this .addSeparator();
71:
72: SqlPanel spanel = (SqlPanel) panel;
73: int currentIndex = aClient.getCurrentPanelIndex();
74: moveLeft = new MoveSqlTabLeft(aClient);
75: moveLeft.setEnabled(currentIndex > 0);
76: this .add(moveLeft.getMenuItem());
77: int lastIndex = aClient.getLastSqlPanelIndex();
78: moveRight = new MoveSqlTabRight(aClient);
79: moveRight.setEnabled(currentIndex < lastIndex);
80: this .add(moveRight);
81:
82: this .addSeparator();
83:
84: EditorPanel editor = spanel.getEditor();
85:
86: this .add(editor.getFileSaveAction().getMenuItem());
87: this .add(editor.getFileOpenAction().getMenuItem());
88: this .add(editor.getReloadAction().getMenuItem());
89: this .addSeparator();
90: FileDiscardAction discard = new FileDiscardAction(spanel);
91: discard.removeIcon();
92: this.add(discard.getMenuItem());
93: this.remove.setEnabled(aClient.canCloseTab());
94: }
95: }
96:
97: }
|