01: /*
02: * Copyright (C) 2003 Gerd Wagner
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: */
18: package net.sourceforge.squirrel_sql.plugins.sqlbookmark;
19:
20: import net.sourceforge.squirrel_sql.client.IApplication;
21: import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
22: import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
23: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
24: import net.sourceforge.squirrel_sql.client.session.ISession;
25: import net.sourceforge.squirrel_sql.fw.completion.CompletionInfo;
26: import net.sourceforge.squirrel_sql.fw.completion.Completor;
27: import net.sourceforge.squirrel_sql.fw.completion.CompletorListener;
28:
29: import javax.swing.text.JTextComponent;
30: import java.awt.event.ActionEvent;
31: import java.awt.*;
32:
33: public class CompleteBookmarkAction extends SquirrelAction {
34: private ISQLEntryPanel _sqlEntryPanel;
35: private Completor _cc;
36: private SQLBookmarkPlugin _plugin;
37:
38: public CompleteBookmarkAction(IApplication app,
39: PluginResources rsrc, ISQLEntryPanel sqlEntryPanel,
40: SQLBookmarkPlugin plugin) {
41: super (app, rsrc);
42: _sqlEntryPanel = sqlEntryPanel;
43: _plugin = plugin;
44:
45: _cc = new Completor(_sqlEntryPanel.getTextComponent(), plugin
46: .getBookmarkManager(), new Color(204, 255, 255), true);
47:
48: _cc.addCodeCompletorListener(new CompletorListener() {
49: public void completionSelected(CompletionInfo completion,
50: int replaceBegin, int keyCode, int modifiers) {
51: performCompletionSelected(completion);
52: }
53: });
54: }
55:
56: public void actionPerformed(ActionEvent evt) {
57: _cc.show();
58: }
59:
60: private void performCompletionSelected(CompletionInfo completion) {
61: Bookmark bm = ((BookmarkCompletionInfo) completion)
62: .getBookmark();
63: new RunBookmarkCommand(getApplication().getMainFrame(),
64: _sqlEntryPanel.getSession(), bm, _plugin,
65: _sqlEntryPanel).execute();
66: }
67: }
|