01: package net.sourceforge.squirrel_sql.fw.completion;
02:
03: public class CompletionCandidates {
04: private CompletionInfo[] _candidates;
05: private int _replacementStart;
06: private String _stringToReplace;
07:
08: public CompletionCandidates(CompletionInfo[] candidates,
09: int replacementStart, String stringToReplace) {
10: _candidates = candidates;
11: _replacementStart = replacementStart;
12: _stringToReplace = stringToReplace;
13: }
14:
15: /**
16: * This ctor can be used when the completion uses its own filter text field.
17: * @param candidates
18: */
19: public CompletionCandidates(CompletionInfo[] candidates) {
20: _candidates = candidates;
21: }
22:
23: public CompletionInfo[] getCandidates() {
24: return _candidates;
25: }
26:
27: public int getReplacementStart() {
28: return _replacementStart;
29: }
30:
31: public String getStringToReplace() {
32: return _stringToReplace;
33: }
34:
35: public String getAllCandidatesPrefix(boolean caseSensitive) {
36: if (0 == _candidates.length) {
37: return "";
38: }
39:
40: String prefix = null;
41: for (CompletionInfo _candidate : _candidates) {
42: String completionString = _candidate.getCompletionString();
43: if (null == prefix) {
44: prefix = completionString;
45: } else {
46: int ix;
47: int minLen = Math.min(prefix.length(), completionString
48: .length());
49:
50: prefix = prefix.substring(0, minLen);
51:
52: for (ix = 0; ix < minLen; ++ix) {
53: if (getCharAt(prefix, ix, caseSensitive) != getCharAt(
54: completionString, ix, caseSensitive)) {
55: prefix = prefix.substring(0, ix);
56: break;
57: }
58: }
59: }
60: }
61:
62: return prefix;
63: }
64:
65: private char getCharAt(String prefix, int ix, boolean caseSensitive) {
66: char c = prefix.charAt(ix);
67: return caseSensitive ? c : Character.toUpperCase(c);
68: }
69: }
|