Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 350991 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java (+31 lines)
Lines 12-17 Link Here
12
package org.eclipse.jface.text.contentassist;
12
package org.eclipse.jface.text.contentassist;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Comparator;
15
import java.util.List;
17
import java.util.List;
16
18
17
import org.eclipse.osgi.util.TextProcessor;
19
import org.eclipse.osgi.util.TextProcessor;
Lines 429-434 class CompletionProposalPopup implements IContentAssistListener { Link Here
429
	 */
431
	 */
430
	private boolean fIsColoredLabelsSupportEnabled= false;
432
	private boolean fIsColoredLabelsSupportEnabled= false;
431
433
434
	private ICompletionProposalSorter fSorter;
432
435
433
	/**
436
	/**
434
	 * Creates a new completion proposal popup for the given elements.
437
	 * Creates a new completion proposal popup for the given elements.
Lines 1096-1101 class CompletionProposalPopup implements IContentAssistListener { Link Here
1096
		if (oldProposals != fFilteredProposals) // reentrant call was first - abort
1099
		if (oldProposals != fFilteredProposals) // reentrant call was first - abort
1097
			return;
1100
			return;
1098
1101
1102
		sortProposals(proposals);
1103
1099
		if (Helper.okToUse(fProposalTable)) {
1104
		if (Helper.okToUse(fProposalTable)) {
1100
			if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
1105
			if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
1101
				((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
1106
				((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
Lines 1831-1834 class CompletionProposalPopup implements IContentAssistListener { Link Here
1831
		return new ProposalSelectionHandler(operationCode);
1836
		return new ProposalSelectionHandler(operationCode);
1832
	}
1837
	}
1833
1838
1839
	/**
1840
	 * Sets the sorter to use when reordering is required by one of the completion engines.
1841
	 * 
1842
	 * @param sorter the sorter new sorter to be used. May be <code>null</code>.
1843
	 * 
1844
	 * @since 3.8
1845
	 */
1846
	public void setSorter(ICompletionProposalSorter sorter) {
1847
		fSorter= sorter;
1848
	}
1849
1850
	/**
1851
	 * Sorts the given proposal array if a sorter is configured. Does nothing otherwise.
1852
	 * 
1853
	 * @param proposals the new proposals to display in the popup window
1854
	 */
1855
	private void sortProposals(final ICompletionProposal[] proposals) {
1856
		if (fSorter != null) {
1857
			Arrays.sort(proposals, new Comparator() {
1858
				public int compare(Object o1, Object o2) {
1859
					return fSorter.compare((ICompletionProposal)o1,
1860
							(ICompletionProposal)o2);
1861
				}
1862
			});
1863
		}
1864
	}
1834
}
1865
}
(-)a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java (+26 lines)
Lines 985-990 public class ContentAssistant implements IContentAssistant, IContentAssistantExt Link Here
985
	 */
985
	 */
986
	private boolean fIsColoredLabelsSupportEnabled= false;
986
	private boolean fIsColoredLabelsSupportEnabled= false;
987
987
988
	/**
989
	 * The sorter used to order completion proposals before presented.
990
	 */
991
	private ICompletionProposalSorter fSorter;
992
988
993
989
	/**
994
	/**
990
	 * Creates a new content assistant. The content assistant is not automatically activated,
995
	 * Creates a new content assistant. The content assistant is not automatically activated,
Lines 2462-2465 public class ContentAssistant implements IContentAssistant, IContentAssistantExt Link Here
2462
		fIsColoredLabelsSupportEnabled= isEnabled;
2467
		fIsColoredLabelsSupportEnabled= isEnabled;
2463
	}
2468
	}
2464
2469
2470
	/**
2471
	 * Sets the sorter used to reorder proposal completions on typing
2472
	 * 
2473
	 * @param sorter the sorter that specifies the order how the proposals are presented to the user
2474
	 * @since 3.8
2475
	 * @see CompletionProposalPopup#setSorter(ICompletionProposalSorter)
2476
	 */
2477
	public void setSorter(ICompletionProposalSorter sorter) {
2478
		fSorter= sorter;
2479
		registerSorterWithProposalPopup();
2480
	}
2481
2482
	/**
2483
	 * Registers the current sorter with the proposal popup - if the popup is already available.
2484
	 * Does nothing otherwise.
2485
	 */
2486
	private void registerSorterWithProposalPopup() {
2487
		if (fProposalPopup != null) {
2488
			fProposalPopup.setSorter(fSorter);
2489
		}
2490
	}
2465
}
2491
}
(-)a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java (-1 / +38 lines)
Added Link Here
0
- 
1
/**
2
 * Copyright (c) 2011 Darmstadt University of Technology.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Marcel Bruch - Initial API
10
 */
11
package org.eclipse.jface.text.contentassist;
12
13
import java.util.Comparator;
14
15
/**
16
 * <p>
17
 * An <code>ICompletionProposalSorter</code> provides support for sorting proposals of a content
18
 * assistant.
19
 * </p>
20
 * <p>
21
 * Implementors of this interface have to register this sorter with the content assist whenever
22
 * needed. See {@link ContentAssistant#setSorter(ICompletionProposalSorter)} for more information on
23
 * how to register a proposal sorter.
24
 * </p>
25
 * 
26
 * @since 3.8
27
 */
28
public interface ICompletionProposalSorter {
29
30
	/**
31
	 * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer
32
	 * as the first argument is less than, equal to, or greater than the second.
33
	 * 
34
	 * @see Comparator#compare(Object, Object)
35
	 */
36
	public int compare(ICompletionProposal p1, ICompletionProposal p2);
37
38
}

Return to bug 350991