01: package net.sourceforge.squirrel_sql.client.gui.session;
02:
03: import java.awt.Color;
04: import java.awt.event.ActionEvent;
05: import java.util.prefs.Preferences;
06:
07: import javax.swing.Action;
08: import javax.swing.text.JTextComponent;
09:
10: import net.sourceforge.squirrel_sql.client.IApplication;
11: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
12: import net.sourceforge.squirrel_sql.client.session.ISession;
13: import net.sourceforge.squirrel_sql.client.session.mainpanel.SQLPanel;
14: import net.sourceforge.squirrel_sql.fw.completion.CompletionInfo;
15: import net.sourceforge.squirrel_sql.fw.completion.Completor;
16: import net.sourceforge.squirrel_sql.fw.completion.CompletorListener;
17: import net.sourceforge.squirrel_sql.fw.util.StringManager;
18: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
19:
20: public class ToolsPopupController {
21: private ToolsPopupCompletorModel _toolsPopupCompletorModel;
22: private ISQLEntryPanel _sqlEntryPanel;
23: private ISession _session;
24: private Completor _toolsCompletor;
25: private static final String PREFS_KEY_CTRL_T_COUNT = "squirrelSql_toolsPopup_ctrl_t_count";
26: private int _ctrlTCount;
27:
28: /** Internationalized strings for this class. */
29: private static final StringManager s_stringMgr = StringManagerFactory
30: .getStringManager(ToolsPopupController.class);
31:
32: public ToolsPopupController(ISession session,
33: ISQLEntryPanel sqlEntryPanel) {
34: _sqlEntryPanel = sqlEntryPanel;
35: _session = session;
36:
37: _toolsPopupCompletorModel = new ToolsPopupCompletorModel();
38: _toolsCompletor = new Completor(_sqlEntryPanel
39: .getTextComponent(), _toolsPopupCompletorModel,
40: new Color(255, 204, 204), true);
41:
42: _toolsCompletor
43: .addCodeCompletorListener(new CompletorListener() {
44: public void completionSelected(
45: CompletionInfo completion,
46: int replaceBegin, int keyCode, int modifiers) {
47: onToolsPopupActionSelected(completion);
48: }
49: });
50:
51: _ctrlTCount = Preferences.userRoot().getInt(
52: PREFS_KEY_CTRL_T_COUNT, 0);
53:
54: if (3 > _ctrlTCount) {
55: // i18n[ToolsPopupController.toolspopupmsg=Please try out the Tools popup by hitting ctrl+t in the SQL Editor. Do it three times to stop this message.]
56: _session.showMessage(s_stringMgr
57: .getString("ToolsPopupController.toolspopupmsg"));
58: }
59: }
60:
61: private void onToolsPopupActionSelected(CompletionInfo completion) {
62: final ToolsPopupCompletionInfo toExecute = (ToolsPopupCompletionInfo) completion;
63: toExecute.getAction().actionPerformed(
64: new ActionEvent(_sqlEntryPanel.getTextComponent(),
65: _session.getIdentifier().hashCode(),
66: "ToolsPopupSelected"));
67: }
68:
69: public void showToolsPopup() {
70: if (3 > _ctrlTCount) {
71: int ctrlTCount = Preferences.userRoot().getInt(
72: PREFS_KEY_CTRL_T_COUNT, 0);
73: Preferences.userRoot().putInt(PREFS_KEY_CTRL_T_COUNT,
74: ++ctrlTCount);
75: }
76:
77: _toolsCompletor.show();
78: }
79:
80: public void addAction(String selectionString, Action action) {
81: _toolsPopupCompletorModel.addAction(selectionString, action);
82: }
83: }
|