Search in sources :

Example 11 with ICompletionProposal

use of org.eclipse.jface.text.contentassist.ICompletionProposal in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    List<IMarker> markers;
    try {
        markers = getMarkersFor(invocationContext.getSourceViewer(), invocationContext.getOffset());
    } catch (BadLocationException e) {
        errorMessage = e.getMessage();
        return new ICompletionProposal[0];
    }
    List<ICompletionProposal> result = Lists.newArrayList();
    for (IMarker marker : markers) {
        for (IMarkerResolution markerResolution : quickFixer.getResolutions(marker)) {
            result.add(new MarkerResolutionProposal(marker, markerResolution, invocationContext.getSourceViewer()));
        }
    }
    return result.toArray(new ICompletionProposal[0]);
}
Also used : IMarkerResolution(org.eclipse.ui.IMarkerResolution) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IMarker(org.eclipse.core.resources.IMarker) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 12 with ICompletionProposal

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

the class TalendJavaCompletionProcessor method sortProposals.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor#filterAndSortProposals(java.util.List,
     * org.eclipse.core.runtime.IProgressMonitor, org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext)
     */
@Override
protected List<ICompletionProposal> sortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
    proposals = super.sortProposals(proposals, monitor, context);
    Map<String, ICompletionProposal> completionProposalMap = new HashMap<String, ICompletionProposal>();
    boolean globalFieldsDone = false;
    for (Object o : proposals) {
        ICompletionProposal proposal = (ICompletionProposal) o;
        String longna = proposal.getDisplayString();
        //$NON-NLS-1$
        int indexna = longna.indexOf("-");
        boolean shouldRemove = false;
        if (indexna > 0) {
            if (longna.substring(indexna + 2, longna.length()).equals(TalendJavaSourceViewer.getClassName())) {
                shouldRemove = true;
            }
        }
        if (proposal instanceof JavaCompletionProposal) {
            JavaCompletionProposal javaProposal = ((JavaCompletionProposal) proposal);
            if (javaProposal.getJavaElement() instanceof SourceField) {
                globalFieldsDone = true;
            }
            if (javaProposal.getJavaElement() == null && globalFieldsDone) {
                shouldRemove = true;
            }
        }
        if (proposal.getDisplayString().startsWith(TalendJavaSourceViewer.VIEWER_CLASS_NAME)) {
            shouldRemove = true;
        }
        if (!shouldRemove) {
            completionProposalMap.put(longna, proposal);
        }
    }
    List<ICompletionProposal> newProposals = new ArrayList<ICompletionProposal>(completionProposalMap.values());
    Collections.sort(newProposals, new Comparator<ICompletionProposal>() {

        @Override
        public int compare(ICompletionProposal arg0, ICompletionProposal arg1) {
            if (arg1 instanceof TalendCompletionProposal && (!(arg0 instanceof TalendCompletionProposal))) {
                return 1;
            } else if (arg0 instanceof TalendCompletionProposal && (!(arg1 instanceof TalendCompletionProposal))) {
                return -1;
            } else if (arg1 instanceof TalendCompletionProposal && (arg0 instanceof TalendCompletionProposal)) {
                TalendCompletionProposal a = (TalendCompletionProposal) arg0;
                TalendCompletionProposal b = (TalendCompletionProposal) arg1;
                return a.getType().compareTo(b.getType());
            }
            return 0;
        }
    });
    return newProposals;
}
Also used : HashMap(java.util.HashMap) SourceField(org.eclipse.jdt.internal.core.SourceField) ArrayList(java.util.ArrayList) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TalendCompletionProposal(org.talend.designer.core.ui.viewer.proposal.TalendCompletionProposal) JavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)

Example 13 with ICompletionProposal

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

the class TalendJavaSourceViewer method createViewerForComponent.

public static ISourceViewer createViewerForComponent(Composite composite, int styles, CompilationUnitEditor editor, List<Variable> variableList, String uniqueName, String codePart) {
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String selectedPart = "[" + uniqueName + " " + codePart + " ] start";
    IDocument originalDocument = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    int documentOffset = -1;
    //$NON-NLS-1$
    String globalFields = "";
    //$NON-NLS-1$
    String localFields = "";
    //$NON-NLS-1$
    globalFields = "\tprivate static java.util.Properties context = new java.util.Properties();\n";
    //$NON-NLS-1$
    globalFields += "\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n";
    IDocument newDoc = new Document();
    boolean checkCode = false;
    FindReplaceDocumentAdapter frda = null;
    // hywang modified for bug 9180
    String documentText = originalDocument.get();
    if (documentText != null && !documentText.equals("") && documentText.length() > 0) {
        //$NON-NLS-1$
        frda = new FindReplaceDocumentAdapter(originalDocument);
    }
    try {
        Region region = null;
        if (frda != null) {
            region = (Region) frda.find(0, selectedPart, true, false, false, false);
        }
        if (region != null) {
            checkCode = true;
            documentOffset = region.getOffset();
            documentOffset = originalDocument.getLineOffset(originalDocument.getLineOfOffset(documentOffset) + 2);
            JavaCompletionProcessor processor = new JavaCompletionProcessor(editor, new ContentAssistant(), IDocument.DEFAULT_CONTENT_TYPE);
            boolean globalFieldsDone = false;
            //$NON-NLS-1$
            globalFields = "";
            String className = editor.getPartName().substring(0, editor.getPartName().indexOf('.') + 1);
            ICompletionProposal[] proposals = processor.computeCompletionProposals(editor.getViewer(), documentOffset);
            for (ICompletionProposal curProposal : proposals) {
                if (curProposal instanceof JavaCompletionProposal) {
                    JavaCompletionProposal javaProposal = ((JavaCompletionProposal) curProposal);
                    if (javaProposal.getJavaElement() instanceof SourceField) {
                        globalFieldsDone = true;
                        SourceField sourceField = (SourceField) javaProposal.getJavaElement();
                        //$NON-NLS-1$ //$NON-NLS-2$
                        globalFields += "\t" + sourceField.getSource() + "\n";
                    // System.out.println();
                    }
                    if (javaProposal.getJavaElement() == null && !globalFieldsDone) {
                        //$NON-NLS-1$
                        String[] str = javaProposal.getSortString().split(" ");
                        //$NON-NLS-1$
                        String variable = "";
                        for (int i = str.length - 1; i >= 0; i--) {
                            //$NON-NLS-1$
                            variable += str[i].length() == 0 ? " " : str[i];
                        }
                        if (variable.contains(className)) {
                            continue;
                        }
                        //$NON-NLS-1$
                        variable += ";";
                        //$NON-NLS-1$ //$NON-NLS-2$
                        localFields += "\t\t" + variable + "\n";
                    // System.out.println(variable);
                    }
                }
            }
        }
    } catch (BadLocationException e) {
        ExceptionHandler.process(e);
    } catch (JavaModelException e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    StringBuffer buff = new StringBuffer();
    //$NON-NLS-1$
    buff.append("package internal;\n\n");
    buff.append(getImports());
    //$NON-NLS-1$ //$NON-NLS-2$
    buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
    buff.append(globalFields);
    //$NON-NLS-1$
    buff.append("\tpublic void myFunction(){\n");
    buff.append(localFields);
    documentOffset = buff.toString().length();
    //$NON-NLS-1$
    buff.append("\n\t\n}\n}");
    newDoc.set(buff.toString());
    return initializeViewer(composite, styles, checkCode, newDoc, documentOffset);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) SourceField(org.eclipse.jdt.internal.core.SourceField) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Region(org.eclipse.jface.text.Region) JavaCompletionProcessor(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor) IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) BadLocationException(org.eclipse.jface.text.BadLocationException) JavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)

Example 14 with ICompletionProposal

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

the class SQLCompletionProcessor method compare.

public int compare(Object o1, Object o2) {
    ICompletionProposal i1 = (ICompletionProposal) o1;
    ICompletionProposal i2 = (ICompletionProposal) o2;
    String s1 = i1.getDisplayString();
    String s2 = i2.getDisplayString();
    return Collator.getInstance().compare(s1, s2);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 15 with ICompletionProposal

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

the class ProposalComputer method addAttributeProposal.

private void addAttributeProposal(final ContentAssistRequest contentAssistRequest, ProposalDescription proposalDescription) {
    String replacementString = proposalDescription.getInsertionText();
    int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
    int replacementLength = contentAssistRequest.getReplacementLength();
    int cursorPosition = getCursorPositionForProposedText(replacementString);
    ICompletionProposal proposal = new MarkupCompletionProposal(replacementString.toString(), replacementOffset, replacementLength, cursorPosition, SharedImages.SIGHTLY_ICON.createImage(), proposalDescription.getLabel(), null, proposalDescription.getAdditionalInfo(), XMLRelevanceConstants.R_TAG_NAME);
    contentAssistRequest.addProposal(proposal);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) MarkupCompletionProposal(org.eclipse.wst.xml.ui.internal.contentassist.MarkupCompletionProposal)

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