Search in sources :

Example 1 with IContentProposal

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()]);
}
Also used : ContentProposal(org.eclipse.jface.fieldassist.ContentProposal) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) SQLWordPartDetector(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLWordPartDetector) SQLSyntaxManager(org.jkiss.dbeaver.model.sql.SQLSyntaxManager) ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Example 2 with IContentProposal

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();
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) KeyListener(org.eclipse.swt.events.KeyListener) IContentProposalListener(org.eclipse.jface.fieldassist.IContentProposalListener) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) IContentProposalListener2(org.eclipse.jface.fieldassist.IContentProposalListener2) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter)

Example 3 with IContentProposal

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;
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) ArrayList(java.util.ArrayList) TableEntryLocation(org.talend.designer.dbmap.model.tableentry.TableEntryLocation) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry)

Example 4 with IContentProposal

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()]);
}
Also used : Category(org.talend.expressionbuilder.model.Category) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) ExpressionContentProposal(org.talend.expressionbuilder.ui.proposal.ExpressionContentProposal) LinkedList(java.util.LinkedList) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) Function(org.talend.designer.rowgenerator.data.Function)

Example 5 with IContentProposal

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()]);
}
Also used : JsonTreeNode(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreeNode) XmlNodeRetriever(org.talend.commons.runtime.xml.XmlNodeRetriever) ArrayList(java.util.ArrayList) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) AbstractTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.AbstractTreePopulator) JsonTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator)

Aggregations

IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)12 ArrayList (java.util.ArrayList)8 IContentProposalProvider (org.eclipse.jface.fieldassist.IContentProposalProvider)3 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)2 IContentProposalListener (org.eclipse.jface.fieldassist.IContentProposalListener)2 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)2 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)2 Function (org.talend.designer.rowgenerator.data.Function)2 JsonTreeNode (org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreeNode)2 JavaContentProposal (bndtools.utils.JavaContentProposal)1 JavaContentProposalLabelProvider (bndtools.utils.JavaContentProposalLabelProvider)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 KeyStroke (org.eclipse.jface.bindings.keys.KeyStroke)1