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.codecompletion;
19:
20: import net.sourceforge.squirrel_sql.client.session.ISession;
21: import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
22: import net.sourceforge.squirrel_sql.fw.id.IIdentifier;
23: import net.sourceforge.squirrel_sql.fw.completion.CompletionCandidates;
24: import net.sourceforge.squirrel_sql.fw.completion.ICompletorModel;
25:
26: public class CodeCompletorModel implements ICompletorModel {
27: private StandardCompletorModel _standardCompletorModel;
28: private CompletionFunctionsModel _completionFunctionsModel;
29: private boolean _functionsAdded;
30:
31: CodeCompletorModel(ISession session, CodeCompletionPlugin plugin,
32: CodeCompletionInfoCollection codeCompletionInfos,
33: IIdentifier sqlEntryPanelIdentifier) {
34: _completionFunctionsModel = new CompletionFunctionsModel(
35: session);
36: _standardCompletorModel = new StandardCompletorModel(session,
37: plugin, codeCompletionInfos, sqlEntryPanelIdentifier);
38:
39: }
40:
41: public CompletionCandidates getCompletionCandidates(
42: String textTillCarret) {
43: if (false == _functionsAdded) {
44: // This is here because addCompletionsAtListBegin() won't work when
45: // schema info is still loading
46: _functionsAdded = _standardCompletorModel
47: .getCodeCompletionInfoCollection()
48: .addCompletionsAtListBegin(null, null,
49: _completionFunctionsModel.getCompletions());
50: }
51:
52: CompletionCandidates functionResult = _completionFunctionsModel
53: .getCompletionCandidates(textTillCarret);
54:
55: if (null == functionResult) {
56: return _standardCompletorModel
57: .getCompletionCandidates(textTillCarret);
58: } else {
59: return functionResult;
60: }
61: }
62:
63: public SQLTokenListener getSQLTokenListener() {
64: return _standardCompletorModel.getSQLTokenListener();
65: }
66:
67: }
|