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 (-1 / +40 lines)
Lines 8-17 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Sean Montgomery, sean_montgomery@comcast.net - https://bugs.eclipse.org/bugs/show_bug.cgi?id=116454
10
 *     Sean Montgomery, sean_montgomery@comcast.net - https://bugs.eclipse.org/bugs/show_bug.cgi?id=116454
11
 *     Marcel Bruch, bruch@cs.tu-darmstadt.de - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.jface.text.contentassist;
13
package org.eclipse.jface.text.contentassist;
13
14
14
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.Comparator;
15
import java.util.List;
18
import java.util.List;
16
19
17
import org.eclipse.osgi.util.TextProcessor;
20
import org.eclipse.osgi.util.TextProcessor;
Lines 429-434 Link Here
429
	 */
432
	 */
430
	private boolean fIsColoredLabelsSupportEnabled= false;
433
	private boolean fIsColoredLabelsSupportEnabled= false;
431
434
435
	/**
436
	 * The most recent sorter. Used when sorting proposals after filtering is requested by a completion engine. The sorter may
437
	 * be <code>null</code>.
438
	 * 
439
	 * @since 3.8
440
	 */
441
	private ICompletionProposalSorter fSorter;
432
442
433
	/**
443
	/**
434
	 * Creates a new completion proposal popup for the given elements.
444
	 * Creates a new completion proposal popup for the given elements.
Lines 1084-1090 Link Here
1084
	}
1094
	}
1085
1095
1086
	/**
1096
	/**
1087
	 * Initializes the proposal selector with these given proposals.
1097
	 * Initializes the proposal selector with these given proposals. If a proposal sorter is
1098
	 * configured, the given proposals are sorted before.
1099
	 * 
1088
	 * @param proposals the proposals
1100
	 * @param proposals the proposals
1089
	 * @param isFilteredSubset if <code>true</code>, the proposal table is
1101
	 * @param isFilteredSubset if <code>true</code>, the proposal table is
1090
	 *        not cleared, but the proposals that are not in the passed array
1102
	 *        not cleared, but the proposals that are not in the passed array
Lines 1106-1111 Link Here
1106
				proposals= new ICompletionProposal[] { fEmptyProposal };
1118
				proposals= new ICompletionProposal[] { fEmptyProposal };
1107
			}
1119
			}
1108
1120
1121
			sortProposals(proposals);
1109
			fFilteredProposals= proposals;
1122
			fFilteredProposals= proposals;
1110
			final int newLen= proposals.length;
1123
			final int newLen= proposals.length;
1111
			if (USE_VIRTUAL) {
1124
			if (USE_VIRTUAL) {
Lines 1831-1834 Link Here
1831
		return new ProposalSelectionHandler(operationCode);
1844
		return new ProposalSelectionHandler(operationCode);
1832
	}
1845
	}
1833
1846
1847
	/**
1848
	 * Sets the sorter to use when resorting is required by one of the completion engines.
1849
	 * 
1850
	 * @param sorter the new sorter to be used, or <code>null</code> if no sorter is needed
1851
	 * @since 3.8
1852
	 */
1853
	public void setSorter(ICompletionProposalSorter sorter) {
1854
		fSorter= sorter;
1855
	}
1856
1857
	/**
1858
	 * Sorts the given proposal array if a sorter is configured. Does nothing otherwise.
1859
	 * 
1860
	 * @param proposals the new proposals to display in the popup window
1861
	 * @since 3.8
1862
	 */
1863
	private void sortProposals(final ICompletionProposal[] proposals) {
1864
		if (fSorter != null) {
1865
			Arrays.sort(proposals, new Comparator() {
1866
				public int compare(Object o1, Object o2) {
1867
					return fSorter.compare((ICompletionProposal)o1,
1868
							(ICompletionProposal)o2);
1869
				}
1870
			});
1871
		}
1872
	}
1834
}
1873
}
(-)a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java (+22 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Guy Gurfinkel, guy.g@zend.com - [content assist][api] provide better access to ContentAssistant - https://bugs.eclipse.org/bugs/show_bug.cgi?id=169954
10
 *     Guy Gurfinkel, guy.g@zend.com - [content assist][api] provide better access to ContentAssistant - https://bugs.eclipse.org/bugs/show_bug.cgi?id=169954
11
 *     Anton Leherbauer (Wind River Systems) - [content assist][api] ContentAssistEvent should contain information about auto activation - https://bugs.eclipse.org/bugs/show_bug.cgi?id=193728
11
 *     Anton Leherbauer (Wind River Systems) - [content assist][api] ContentAssistEvent should contain information about auto activation - https://bugs.eclipse.org/bugs/show_bug.cgi?id=193728
12
 *     Marcel Bruch, bruch@cs.tu-darmstadt.de - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jface.text.contentassist;
14
package org.eclipse.jface.text.contentassist;
14
15
Lines 985-990 Link Here
985
	 */
986
	 */
986
	private boolean fIsColoredLabelsSupportEnabled= false;
987
	private boolean fIsColoredLabelsSupportEnabled= false;
987
988
989
	/**
990
	 * The sorter used to sort completion proposals when filtering was triggered.
991
	 * 
992
	 * @since 3.8
993
	 */
994
	private ICompletionProposalSorter fSorter;
988
995
989
	/**
996
	/**
990
	 * Creates a new content assistant. The content assistant is not automatically activated,
997
	 * Creates a new content assistant. The content assistant is not automatically activated,
Lines 1374-1379 Link Here
1374
1381
1375
		fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
1382
		fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
1376
		fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller);
1383
		fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller);
1384
		fProposalPopup.setSorter(fSorter);
1377
1385
1378
		registerHandler(SELECT_NEXT_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_NEXT));
1386
		registerHandler(SELECT_NEXT_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_NEXT));
1379
		registerHandler(SELECT_PREVIOUS_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_PREVIOUS));
1387
		registerHandler(SELECT_PREVIOUS_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_PREVIOUS));
Lines 2462-2465 Link Here
2462
		fIsColoredLabelsSupportEnabled= isEnabled;
2470
		fIsColoredLabelsSupportEnabled= isEnabled;
2463
	}
2471
	}
2464
2472
2473
	/**
2474
	 * Sets the sorter used to sort proposal completions after filtering is triggered.
2475
	 * 
2476
	 * @param sorter the sorter used for reordering the proposals, or <code>null</code> if no
2477
	 *            proposal reordering is needed
2478
	 * @since 3.8
2479
	 * @see CompletionProposalPopup#setSorter(ICompletionProposalSorter)
2480
	 */
2481
	public void setSorter(ICompletionProposalSorter sorter) {
2482
		fSorter= sorter;
2483
		if (fProposalPopup != null) {
2484
			fProposalPopup.setSorter(fSorter);
2485
		}
2486
	}
2465
}
2487
}
(-)a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java (+39 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2012 Darmstadt University of Technology and others.
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, bruch@cs.tu-darmstadt.de - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991
10
 */
11
package org.eclipse.jface.text.contentassist;
12
13
14
/**
15
 * An <code>ICompletionProposalSorter</code> provides support for sorting proposals of a content
16
 * assistant.
17
 * <p>
18
 * Implementors of this interface have to register this sorter with the content assist whenever
19
 * needed. See {@link ContentAssistant#setSorter(ICompletionProposalSorter)} for more information on
20
 * how to register a proposal sorter.
21
 * </p>
22
 * 
23
 * @since 3.8
24
 */
25
public interface ICompletionProposalSorter {
26
27
	/**
28
	 * The orderings imposed by an implementation need not be consistent with equals.
29
	 * 
30
	 * @param p1 the first proposal to be compared
31
	 * @param p2 the second proposal to be compared
32
	 * @return a negative integer, zero, or a positive integer as the first argument is less than,
33
	 *         equal to, or greater than the second.
34
	 * 
35
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
36
	 */
37
	public int compare(ICompletionProposal p1, ICompletionProposal p2);
38
39
}

Return to bug 350991