Search in sources :

Example 1 with TalendCompletionProposal

use of org.talend.designer.core.ui.viewer.proposal.TalendCompletionProposal 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SourceField (org.eclipse.jdt.internal.core.SourceField)1 JavaCompletionProposal (org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 TalendCompletionProposal (org.talend.designer.core.ui.viewer.proposal.TalendCompletionProposal)1