use of org.eclipse.jface.fieldassist.IContentProposal in project dbeaver by serge-rider.
the class ResultSetFilterPanel method getProposals.
@Override
public IContentProposal[] getProposals(String contents, int position) {
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
if (viewer.getDataContainer() != null) {
syntaxManager.init(viewer.getDataContainer().getDataSource());
}
SQLWordPartDetector wordDetector = new SQLWordPartDetector(new Document(contents), syntaxManager, position);
final String word = wordDetector.getFullWord().toLowerCase(Locale.ENGLISH);
List<IContentProposal> proposals = new ArrayList<>();
for (DBDAttributeBinding attribute : viewer.getModel().getAttributes()) {
final String name = attribute.getName();
if (CommonUtils.isEmpty(word) || name.toLowerCase(Locale.ENGLISH).startsWith(word)) {
final String content = name.substring(word.length()) + " ";
proposals.add(new ContentProposal(content, attribute.getName(), SQLContextInformer.makeObjectDescription(null, attribute.getAttribute(), false), content.length()));
}
}
return proposals.toArray(new IContentProposal[proposals.size()]);
}
use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class TalendEditorComponentCreationAssist method initListeners.
private void initListeners() {
assistText.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
if (e.stateMask == SWT.NONE) {
if (e.keyCode == SWT.ESC) {
disposeAssistText();
} else if (e.keyCode == SWT.CR) {
acceptProposal();
}
}
}
@Override
public void keyPressed(KeyEvent e) {
}
});
assistText.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!(contentProposalAdapter.isProposalPopupOpen())) {
disposeAssistText();
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
contentProposalAdapter.addContentProposalListener(new IContentProposalListener2() {
@Override
public void proposalPopupOpened(ContentProposalAdapter adapter) {
}
@Override
public void proposalPopupClosed(ContentProposalAdapter adapter) {
if (assistText != null && !assistText.isFocusControl()) {
disposeAssistText();
}
}
});
contentProposalAdapter.addContentProposalListener(new IContentProposalListener() {
@Override
public void proposalAccepted(IContentProposal proposal) {
acceptProposal();
}
});
}
use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class ExpressionProposalProvider method getProposals.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
*/
public IContentProposal[] getProposals(String contents, int position) {
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
TableEntryLocation sourceEntryLocation = new TableEntryLocation();
// Proposals based on process context
for (IDataMapTable table : this.tables) {
// proposals.add(new TableContentProposal(table, this.currentLanguage));
List<IColumnEntry> dataMapTableEntries = table.getColumnEntries();
for (IColumnEntry entrySource : dataMapTableEntries) {
sourceEntryLocation.tableName = entrySource.getParentName();
sourceEntryLocation.columnName = entrySource.getName();
if (mapperManager.getUiManager().checkSourceLocationIsValid(entrySource, currentModifiedEntry)) {
proposals.add(new EntryContentProposal(entrySource, this.currentLanguage));
}
}
}
for (IContentProposalProvider contentProposalProvider : otherContentProposalProviders) {
proposals.addAll(Arrays.asList(contentProposalProvider.getProposals(contents, position)));
}
IContentProposal[] res = new IContentProposal[proposals.size()];
res = proposals.toArray(res);
return res;
}
use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class CategoryComposite method getProposals.
/**
* yzhang Comment method "getProposals".
*
* @return
*/
public IContentProposal[] getProposals(String categoryFunction, int position) {
String category = null;
String function = null;
boolean displayFunction = false;
if (categoryFunction.indexOf(".") != -1) {
//$NON-NLS-1$
//$NON-NLS-1$
String[] cf = categoryFunction.split("\\.");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < cf.length - 1; i++) {
buffer.append(cf[i]);
if (i != cf.length - 2) {
//$NON-NLS-1$
buffer.append(".");
}
}
if (cf.length == 1) {
category = cf[cf.length - 1];
} else {
function = cf[cf.length - 1];
category = buffer.toString();
}
displayFunction = true;
} else {
category = categoryFunction;
}
java.util.List<IContentProposal> proposals = new LinkedList<IContentProposal>();
java.util.List<Category> categories = manager.getInputCategory("java");
//$NON-NLS-1$
boolean addAllCategory = category.equals("*C") ? true : false;
if (!displayFunction) {
for (Category cg : categories) {
if (!cg.getName().startsWith("*") && (addAllCategory || cg.getName().startsWith(category))) {
//$NON-NLS-1$
//$NON-NLS-1$
proposals.add(new ExpressionContentProposal(cg.getName(), "", position));
}
}
java.util.List<Variable> vars = ExpressionBuilderDialog.getTestComposite().getVariableList();
for (Variable var : vars) {
if (addAllCategory || var.getName().startsWith(category)) {
proposals.add(new ExpressionContentProposal(var.getName(), var.getValue(), position));
}
}
} else {
for (Category cg : categories) {
if (cg.getName().equals(category)) {
java.util.List<Function> funs = cg.getFunctions();
boolean addAll = (function == null ? true : false);
for (Function fun : funs) {
if (addAll || fun.getName().startsWith(function)) {
proposals.add(new //$NON-NLS-1$
ExpressionContentProposal(//$NON-NLS-1$
fun.getName() + "()", //$NON-NLS-1$
fun.getDescription(), position));
}
}
}
}
}
Collections.sort(proposals, new CategoryFunctionCompartor());
String replaceString;
if (displayFunction) {
//$NON-NLS-1$
replaceString = function == null ? "" : function;
} else {
replaceString = category;
}
ExpressionBuilderDialog.getExpressionComposite().setReplacedText(replaceString);
return proposals.toArray(new IContentProposal[proposals.size()]);
}
use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class JSONXPathProposalProvider method getProposals4JsonPath.
private IContentProposal[] getProposals4JsonPath(String contents, int position) {
AbstractTreePopulator treePopulator = linker.getTreePopulator();
if (!(treePopulator instanceof JsonTreePopulator)) {
return null;
}
XmlNodeRetriever nodeRetriever = linker.getNodeRetriever();
if (!(nodeRetriever instanceof JsonNodeRetriever)) {
return null;
}
JsonNodeRetriever jsonNodeRetriever = (JsonNodeRetriever) nodeRetriever;
String beforeCursorExp = null;
boolean isAbsoluteExpression = contents.trim().startsWith(linker.getRootSeperator());
beforeCursorExp = contents.substring(0, position);
int lastIndexFieldSeperator = beforeCursorExp.lastIndexOf(linker.getFieldSeperator());
String currentExpr = null;
if (0 <= lastIndexFieldSeperator) {
currentExpr = beforeCursorExp.substring(0, lastIndexFieldSeperator);
} else {
currentExpr = beforeCursorExp;
}
currentExpr = currentExpr.trim();
String currentWord = extractLastWord(beforeCursorExp);
if (!isAbsoluteExpression && lastIndexFieldSeperator < 0) {
currentWord = currentExpr;
currentExpr = "";
}
if (currentWord != null) {
currentWord = currentWord.trim();
}
List<JsonTreeNode> proposalNodes = jsonNodeRetriever.retrieveProposalJsonTreeNode((JsonTreePopulator) treePopulator, currentExpr, currentWord, isRelativeTable, isAbsoluteExpression);
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
if (proposalNodes != null && !proposalNodes.isEmpty()) {
Iterator<JsonTreeNode> iter = proposalNodes.iterator();
while (iter.hasNext()) {
JsonTreeNode jsonTreeNode = iter.next();
JsonPathContentProposal proposal = new JsonPathContentProposal(jsonTreeNode.getLabel());
proposals.add(proposal);
}
}
return proposals.toArray(new IContentProposal[proposals.size()]);
}
Aggregations