Search in sources :

Example 6 with ICompletionProposal

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

the class SQLCompletionProcessor method getProposalsByNode2.

/**
     * DOC dev Comment method "getProposalsByNode2".
     * 
     * @param documentOffset
     * @param lastPart
     * @param node
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] getProposalsByNode2(int documentOffset, String lastPart, INode node) {
    String[] proposalsString = dictionary.matchTablePrefix(lastPart.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;
            TableFolderNode totn = (TableFolderNode) tbNode.getParent();
            INode catSchema = (INode) totn.getParent();
            if (catSchema == node) {
                if (tbNode.isView()) {
                    tmpImage = viewImage;
                } else if (tbNode.isTable()) {
                    tmpImage = tableImage;
                }
                ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - lastPart.length(), lastPart.length(), proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
                propList.add(cmp);
            }
        }
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size()];
    System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
    return res;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) 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) TableFolderNode(org.talend.sqlbuilder.dbstructure.nodes.TableFolderNode)

Example 7 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal 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 8 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project bndtools by bndtools.

the class BaselineErrorHandler method getProposals.

@Override
public List<ICompletionProposal> getProposals(IMarker marker) {
    List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
    String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
    int start = marker.getAttribute(IMarker.CHAR_START, 0);
    int end = marker.getAttribute(IMarker.CHAR_END, 0);
    CompletionProposal proposal = new CompletionProposal("version " + suggestedVersion, start, end - start, end, null, "Change package version to " + suggestedVersion, null, null);
    proposals.add(proposal);
    return proposals;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) LinkedList(java.util.LinkedList)

Example 9 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project bndtools by bndtools.

the class BundleVersionErrorHandler method getProposals.

@Override
public List<ICompletionProposal> getProposals(IMarker marker) {
    List<ICompletionProposal> result = new LinkedList<ICompletionProposal>();
    String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
    int start = marker.getAttribute(IMarker.CHAR_START, 0);
    int end = marker.getAttribute(IMarker.CHAR_END, 0);
    CompletionProposal proposal = new CompletionProposal(Constants.BUNDLE_VERSION + ": " + suggestedVersion, start, end - start, end, null, "Change bundle version to " + suggestedVersion, null, null);
    result.add(proposal);
    return result;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) LinkedList(java.util.LinkedList)

Example 10 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project bndtools by bndtools.

the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
    List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
    ISourceViewer viewer = context.getSourceViewer();
    @SuppressWarnings("unused") IDocument document = viewer.getDocument();
    IAnnotationModel model = viewer.getAnnotationModel();
    @SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
    while (iter.hasNext()) {
        Annotation annotation = (Annotation) iter.next();
        if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
            Position position = model.getPosition(annotation);
            if (isAtPosition(context.getOffset(), position)) {
                IMarker marker = ((MarkerAnnotation) annotation).getMarker();
                String errorType = marker.getAttribute("$bndType", null);
                if (errorType != null) {
                    BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
                    if (handler != null) {
                        proposals.addAll(handler.getProposals(marker));
                    }
                }
            }
        }
    }
    if (proposals.isEmpty()) {
        proposals.add(new NoCompletionsProposal());
    }
    return proposals.toArray(new ICompletionProposal[0]);
}
Also used : Position(org.eclipse.jface.text.Position) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) LinkedList(java.util.LinkedList) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IMarker(org.eclipse.core.resources.IMarker) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)17 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)5 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)5 BadLocationException (org.eclipse.jface.text.BadLocationException)4 Point (org.eclipse.swt.graphics.Point)4 TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)4 Image (org.eclipse.swt.graphics.Image)3 Iterator (java.util.Iterator)2 BuildErrorDetailsHandler (org.bndtools.build.api.BuildErrorDetailsHandler)2 IMarker (org.eclipse.core.resources.IMarker)2 SourceField (org.eclipse.jdt.internal.core.SourceField)2 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)2 IDocument (org.eclipse.jface.text.IDocument)2 IMarkerResolution (org.eclipse.ui.IMarkerResolution)2 INode (org.talend.sqlbuilder.dbstructure.nodes.INode)2 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1 Model (com.reprezen.swagedit.core.model.Model)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1