Search in sources :

Example 1 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method inputNotContainDot.

/**
     * DOC dev Comment method "inputNotContainDot".
     * 
     * @param documentOffset
     * @param string
     * @param length
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] inputNotContainDot(int documentOffset, String string, int length) {
    // The string does not contain "."
    String[] keywordProposal = Dictionary.matchKeywordsPrefix(string);
    ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length];
    for (int i = 0; i < keywordProposal.length; i++) {
        resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null);
    }
    String[] proposalsString = dictionary.matchTablePrefix(string.toLowerCase());
    ArrayList propList = new ArrayList();
    for (int i = 0; i < proposalsString.length; i++) {
        ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
        for (int j = 0; j < ls.size(); j++) {
            TableNode tbNode = (TableNode) ls.get(j);
            Image tmpImage = null;
            if (tbNode.isView()) {
                tmpImage = viewImage;
            } else if (tbNode.isTable()) {
                tmpImage = tableImage;
            }
            ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - length, length, proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
            propList.add(cmp);
        }
    }
    String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase());
    ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length];
    for (int i = 0; i < proposalsString2.length; i++) {
        resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null);
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length];
    System.arraycopy(resKey, 0, res, 0, resKey.length);
    System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size());
    System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length);
    Arrays.sort(res, new ICompletionProposalComparator());
    return res;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 2 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method computeCompletionProposals.

/**
     * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
     * int)
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    if (dictionary == null) {
        return null;
    }
    String text = viewer.getDocument().get();
    String string = text.substring(0, documentOffset);
    if (string.equals("")) {
        //$NON-NLS-1$
        return null;
    }
    int position = string.length() - 1;
    char character;
    while (position > 0) {
        character = string.charAt(position);
        if (!Character.isJavaIdentifierPart(character) && (character != '.')) {
            break;
        }
        --position;
    }
    if (position == 0) {
        position = -1;
    }
    string = string.substring(position + 1);
    // JFaceDbcPlugin.error("String: "+string,new Exception());
    if (string == null || string.equals("")) {
        //$NON-NLS-1$
        return null;
    }
    string = string.toLowerCase();
    int length = string.length();
    if (length < 1) {
        return null;
    }
    //$NON-NLS-1$
    int dotIndex = string.lastIndexOf(".");
    if (string.charAt(length - 1) == ' ') {
        return null;
    } else if (string.charAt(length - 1) == '.') {
        // Last typed character
        // is '.'
        String name = string.substring(0, length - 1);
        if (name == null) {
            return null;
        }
        //$NON-NLS-1$
        int otherDot = name.lastIndexOf(".");
        if (otherDot != -1) {
            name = name.substring(otherDot + 1);
        }
        if (name == null || name.equals("")) {
            //$NON-NLS-1$
            return null;
        }
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(name);
        if (st != null) {
            ArrayList list = (ArrayList) dictionary.getByTableName(name);
            if (list == null) {
                return null;
            }
            TableNode nd = null;
            if (list.size() == 1) {
                nd = (TableNode) list.get(0);
            } else {
                return null;
            }
            Object[] obj = st.toArray();
            String[] arr = new String[obj.length];
            System.arraycopy(obj, 0, arr, 0, obj.length);
            ICompletionProposal[] result = new ICompletionProposal[arr.length];
            String tableDesc = null;
            if (nd != null) {
                tableDesc = nd.getTableDesc();
            }
            for (int i = 0; i < arr.length; i++) {
                result[i] = new CompletionProposal(arr[i], documentOffset, 0, arr[i].length(), colImage, arr[i], null, tableDesc);
            }
            return result;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(name);
        if (node != null) {
            return getProposalsByNode(documentOffset, node);
        }
    } else if (dotIndex == -1) {
        return inputNotContainDot(documentOffset, string, length);
    } else if (dotIndex != -1) {
        String firstPart = string.substring(0, dotIndex);
        //$NON-NLS-1$
        int otherDot = firstPart.indexOf(".");
        if (otherDot != -1) {
            firstPart = firstPart.substring(otherDot + 1);
        }
        String lastPart = string.substring(dotIndex + 1);
        if (//$NON-NLS-1$
        lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals("")) {
            //$NON-NLS-1$
            return null;
        }
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(firstPart);
        if (st != null) {
            Iterator iter = st.iterator();
            ArrayList propList = new ArrayList();
            while (iter.hasNext()) {
                String colName = (String) iter.next();
                int length2 = lastPart.length();
                if (colName.length() >= length2) {
                    if ((colName.substring(0, lastPart.length())).equalsIgnoreCase(lastPart)) {
                        CompletionProposal cmp = new CompletionProposal(colName, documentOffset - length2, length2, colName.length(), colImage, colName, null, null);
                        propList.add(cmp);
                    }
                }
            }
            ICompletionProposal[] res = new ICompletionProposal[propList.size()];
            System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
            return res;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(firstPart);
        if (node != null) {
            return getProposalsByNode2(documentOffset, lastPart, node);
        }
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Iterator(java.util.Iterator) Point(org.eclipse.swt.graphics.Point)

Example 3 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project eclipse.platform.text by eclipse.

the class DefaultContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    String text = viewer.getDocument().get();
    String[] tokens = text.split(NON_ALPHANUMERIC_REGEXP);
    // remove duplicates
    Set<String> tokenSet = new HashSet<String>(Arrays.asList(tokens));
    // wordStartIndex is the index of the last non-alphanumeric before 'offset' in text 'text'
    int wordStartIndex = findStartingPoint(text, offset);
    String prefix = text.substring(wordStartIndex, offset);
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    for (String token : tokenSet) {
        if ((token == null) || (token.length() < 2)) {
            continue;
        }
        if (token.equals(prefix)) {
            continue;
        }
        if (token.startsWith(prefix)) {
            String completion = token.substring(prefix.length());
            CompletionProposal proposal = new CompletionProposal(completion, offset, 0, completion.length(), null, token, null, null);
            proposals.add(proposal);
        }
    }
    return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 4 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project linuxtools by eclipse.

the class SuppressionsContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    List<ICompletionProposal> completions = new ArrayList<>();
    IDocument doc = viewer.getDocument();
    try {
        // check if we're in the middle of a word
        String prefix = completionWord(doc, offset);
        int replacementOffset = offset;
        int replacementLength = 0;
        if (prefix != null) {
            // replacing what's been typed so far
            replacementLength = prefix.length();
            // subtract prefix length from offset
            replacementOffset -= replacementLength;
        }
        String toolName = getToolName(doc, replacementOffset);
        String[] words = getCompletionStrings(prefix, toolName);
        for (String word : words) {
            completions.add(new CompletionProposal(word, replacementOffset, replacementLength, word.length()));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    return completions.toArray(new ICompletionProposal[completions.size()]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 5 with CompletionProposal

use of org.eclipse.jface.text.contentassist.CompletionProposal in project erlide_eclipse by erlang.

the class AbstractErlContentAssistProcessor method toProposal.

protected ICompletionProposal toProposal(final CompletionData data) {
    if (data instanceof FunctionCompletionData) {
        final FunctionCompletionData fdata = (FunctionCompletionData) data;
        String info = fdata.getAdditionalProposalInfo();
        StringBuffer buffer = new StringBuffer(info == null ? "" : info);
        return new ErlCompletionProposal(fdata.getOffsetsAndLengths(), fdata.getDisplayString(), fdata.getReplacementString(), fdata.getReplacementOffset(), fdata.getReplacementLength(), fdata.getCursorPosition(), null, null, HoverUtil.getHTML(buffer), sourceViewer);
    }
    return new CompletionProposal(data.getReplacementString(), data.getReplacementOffset(), data.getReplacementLength(), data.getCursorPosition());
}
Also used : FunctionCompletionData(org.erlide.engine.services.codeassist.FunctionCompletionData) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Aggregations

CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)41 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)39 ArrayList (java.util.ArrayList)28 Iterator (java.util.Iterator)8 List (java.util.List)8 BadLocationException (org.eclipse.jface.text.BadLocationException)6 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)3 Set (java.util.Set)3 CoreException (org.eclipse.core.runtime.CoreException)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IType (org.eclipse.jdt.core.IType)3 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)3 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)3 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)3 Image (org.eclipse.swt.graphics.Image)3 Point (org.eclipse.swt.graphics.Point)3 KindedName (abs.frontend.typechecker.KindedName)2 ResolvedName (abs.frontend.typechecker.ResolvedName)2 Map (java.util.Map)2