use of org.eclipse.jface.fieldassist.ContentProposal in project dbeaver by serge-rider.
the class ResultSetFilterPanel method getProposals.
@Override
public IContentProposal[] getProposals(String contents, int position) {
if (!viewer.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_FILTER_AUTO_COMPLETE_PROPOSIAL)) {
return null;
}
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
DBPDataSource dataSource = viewer.getDataSource();
if (dataSource != null) {
syntaxManager.init(dataSource);
}
SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
String word = wordDetector.getFullWord();
final List<IContentProposal> proposals = new ArrayList<>();
if (CommonUtils.isEmptyTrimmed(word))
word = contents;
word = word.toLowerCase(Locale.ENGLISH);
String attrName = word;
final DBRRunnableWithProgress reader = monitor -> {
DBDAttributeBinding[] attributes = viewer.getModel().getAttributes();
for (DBDAttributeBinding attribute : attributes) {
if (attribute.isCustom()) {
continue;
}
final String name = DBUtils.getUnQuotedIdentifier(attribute.getDataSource(), attribute.getName());
if (CommonUtils.isEmpty(attrName) || name.toLowerCase(Locale.ENGLISH).startsWith(attrName)) {
final String content = DBUtils.getQuotedIdentifier(attribute) + " ";
proposals.add(new ContentProposalExt(content, attribute.getName(), DBInfoUtils.makeObjectDescription(monitor, attribute.getAttribute(), false), content.length(), DBValueFormatting.getObjectImage(attribute)));
}
}
};
SystemJob searchJob = new SystemJob("Extract attribute proposals", reader);
searchJob.schedule();
UIUtils.waitJobCompletion(searchJob);
String[] filterKeywords = { SQLConstants.KEYWORD_AND, SQLConstants.KEYWORD_OR, SQLConstants.KEYWORD_IS, SQLConstants.KEYWORD_NOT, SQLConstants.KEYWORD_NULL };
for (String kw : filterKeywords) {
if (attrName.isEmpty() || kw.startsWith(attrName.toUpperCase())) {
if (dataSource != null) {
kw = dataSource.getSQLDialect().storesUnquotedCase().transform(kw);
}
proposals.add(new ContentProposal(kw + " ", kw + ": SQL expression keyword"));
}
}
return proposals.toArray(new IContentProposal[0]);
}
use of org.eclipse.jface.fieldassist.ContentProposal in project dbeaver by serge-rider.
the class StringContentProposalProvider method getProposals.
public IContentProposal[] getProposals(String contents, int position) {
List<ContentProposal> list = new ArrayList<>();
int startPos = 0;
for (int i = position - 1; i >= 0; i--) {
char ch = Character.toUpperCase(contents.charAt(i));
if (!Character.isLetterOrDigit(ch) && possibleChars.indexOf(ch) == -1) {
startPos = i + 1;
break;
}
}
String word = contents.substring(startPos, position);
for (String proposal : proposals) {
if (proposal.length() >= word.length() && proposal.substring(0, word.length()).equalsIgnoreCase(word)) {
list.add(new ContentProposal(proposal));
}
}
return list.toArray(new IContentProposal[0]);
}
use of org.eclipse.jface.fieldassist.ContentProposal in project dbeaver by dbeaver.
the class ResultSetFilterPanel method getProposals.
@Override
public IContentProposal[] getProposals(String contents, int position) {
if (!viewer.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_FILTER_AUTO_COMPLETE_PROPOSIAL)) {
return null;
}
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
DBPDataSource dataSource = viewer.getDataSource();
if (dataSource != null) {
syntaxManager.init(dataSource);
}
SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
String word = wordDetector.getFullWord();
final List<IContentProposal> proposals = new ArrayList<>();
if (CommonUtils.isEmptyTrimmed(word))
word = contents;
word = word.toLowerCase(Locale.ENGLISH);
String attrName = word;
final DBRRunnableWithProgress reader = monitor -> {
DBDAttributeBinding[] attributes = viewer.getModel().getAttributes();
for (DBDAttributeBinding attribute : attributes) {
if (attribute.isCustom()) {
continue;
}
final String name = DBUtils.getUnQuotedIdentifier(attribute.getDataSource(), attribute.getName());
if (CommonUtils.isEmpty(attrName) || name.toLowerCase(Locale.ENGLISH).startsWith(attrName)) {
final String content = DBUtils.getQuotedIdentifier(attribute) + " ";
proposals.add(new ContentProposalExt(content, attribute.getName(), DBInfoUtils.makeObjectDescription(monitor, attribute.getAttribute(), false), content.length(), DBValueFormatting.getObjectImage(attribute)));
}
}
};
SystemJob searchJob = new SystemJob("Extract attribute proposals", reader);
searchJob.schedule();
UIUtils.waitJobCompletion(searchJob);
String[] filterKeywords = { SQLConstants.KEYWORD_AND, SQLConstants.KEYWORD_OR, SQLConstants.KEYWORD_IS, SQLConstants.KEYWORD_NOT, SQLConstants.KEYWORD_NULL };
for (String kw : filterKeywords) {
if (attrName.isEmpty() || kw.startsWith(attrName.toUpperCase())) {
if (dataSource != null) {
kw = dataSource.getSQLDialect().storesUnquotedCase().transform(kw);
}
proposals.add(new ContentProposal(kw + " ", kw + ": SQL expression keyword"));
}
}
return proposals.toArray(new IContentProposal[0]);
}
use of org.eclipse.jface.fieldassist.ContentProposal in project dbeaver by dbeaver.
the class StringContentProposalProvider method getProposals.
public IContentProposal[] getProposals(String contents, int position) {
List<ContentProposal> list = new ArrayList<>();
int startPos = 0;
for (int i = position - 1; i >= 0; i--) {
char ch = Character.toUpperCase(contents.charAt(i));
if (!Character.isLetterOrDigit(ch) && possibleChars.indexOf(ch) == -1) {
startPos = i + 1;
break;
}
}
String word = contents.substring(startPos, position);
for (String proposal : proposals) {
if (proposal.length() >= word.length() && proposal.substring(0, word.length()).equalsIgnoreCase(word)) {
list.add(new ContentProposal(proposal));
}
}
return list.toArray(new IContentProposal[0]);
}
Aggregations