01: package net.sourceforge.squirrel_sql.plugins.codecompletion;
02:
03: import net.sourceforge.squirrel_sql.client.session.ISession;
04: import net.sourceforge.squirrel_sql.plugins.codecompletion.completionfunctions.*;
05: import net.sourceforge.squirrel_sql.fw.completion.CompletionCandidates;
06:
07: public class CompletionFunctionsModel {
08: CodeCompletionFunction[] _completionFunctions;
09:
10: CompletionFunctionsModel(ISession session) {
11:
12: _completionFunctions = new CodeCompletionFunction[] {
13: //new TestCompletionFunction(),
14: new Join(session), new InnerJoin(session),
15: new LeftJoin(session), new RightJoin(session) };
16: }
17:
18: public CodeCompletionInfo[] getCompletions() {
19: return _completionFunctions;
20: }
21:
22: public CompletionCandidates getCompletionCandidates(
23: String textTillCarret) {
24: int lastIndexOfLineFeed = textTillCarret.lastIndexOf('\n');
25: int lastIndexOfHash = textTillCarret.lastIndexOf('#');
26:
27: if (lastIndexOfHash <= lastIndexOfLineFeed) {
28: return null;
29: }
30:
31: String functionSting = textTillCarret
32: .substring(lastIndexOfHash);
33:
34: for (int i = 0; i < _completionFunctions.length; i++) {
35: CodeCompletionInfo[] functionResults = _completionFunctions[i]
36: .getFunctionResults(functionSting);
37:
38: if (null != functionResults) {
39: return new CompletionCandidates(functionResults,
40: lastIndexOfHash, functionSting);
41: }
42: }
43: return null;
44: }
45: }
|