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 (+32 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 class CompletionProposalPopup implements IContentAssistListener { Link Here
429
	 */
432
	 */
430
	private boolean fIsColoredLabelsSupportEnabled= false;
433
	private boolean fIsColoredLabelsSupportEnabled= false;
431
434
435
	private ICompletionProposalSorter fSorter;
432
436
433
	/**
437
	/**
434
	 * Creates a new completion proposal popup for the given elements.
438
	 * 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
1100
		if (oldProposals != fFilteredProposals) // reentrant call was first - abort
1097
			return;
1101
			return;
1098
1102
1103
		sortProposals(proposals);
1104
1099
		if (Helper.okToUse(fProposalTable)) {
1105
		if (Helper.okToUse(fProposalTable)) {
1100
			if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
1106
			if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
1101
				((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
1107
				((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
Lines 1831-1834 class CompletionProposalPopup implements IContentAssistListener { Link Here
1831
		return new ProposalSelectionHandler(operationCode);
1837
		return new ProposalSelectionHandler(operationCode);
1832
	}
1838
	}
1833
1839
1840
	/**
1841
	 * Sets the sorter to use when reordering is required by one of the completion engines.
1842
	 * 
1843
	 * @param sorter the sorter new sorter to be used. May be <code>null</code>.
1844
	 * 
1845
	 * @since 3.8
1846
	 */
1847
	public void setSorter(ICompletionProposalSorter sorter) {
1848
		fSorter= sorter;
1849
	}
1850
1851
	/**
1852
	 * Sorts the given proposal array if a sorter is configured. Does nothing otherwise.
1853
	 * 
1854
	 * @param proposals the new proposals to display in the popup window
1855
	 */
1856
	private void sortProposals(final ICompletionProposal[] proposals) {
1857
		if (fSorter != null) {
1858
			Arrays.sort(proposals, new Comparator() {
1859
				public int compare(Object o1, Object o2) {
1860
					return fSorter.compare((ICompletionProposal)o1,
1861
							(ICompletionProposal)o2);
1862
				}
1863
			});
1864
		}
1865
	}
1834
}
1866
}
(-)a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java (+29 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 public class ContentAssistant implements IContentAssistant, IContentAssistantExt Link Here
985
	 */
986
	 */
986
	private boolean fIsColoredLabelsSupportEnabled= false;
987
	private boolean fIsColoredLabelsSupportEnabled= false;
987
988
989
	/**
990
	 * The sorter used to order completion proposals before presented.
991
	 */
992
	private ICompletionProposalSorter fSorter;
993
988
994
989
	/**
995
	/**
990
	 * Creates a new content assistant. The content assistant is not automatically activated,
996
	 * Creates a new content assistant. The content assistant is not automatically activated,
Lines 1375-1380 public class ContentAssistant implements IContentAssistant, IContentAssistantExt Link Here
1375
		fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
1381
		fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
1376
		fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller);
1382
		fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller);
1377
1383
1384
		registerSorterWithProposalPopup();
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));
1380
1388
Lines 2462-2465 public class ContentAssistant implements IContentAssistant, IContentAssistantExt Link Here
2462
		fIsColoredLabelsSupportEnabled= isEnabled;
2470
		fIsColoredLabelsSupportEnabled= isEnabled;
2463
	}
2471
	}
2464
2472
2473
	/**
2474
	 * Sets the sorter used to reorder proposal completions on typing
2475
	 * 
2476
	 * @param sorter the sorter that specifies the order how the proposals are presented to the user
2477
	 * @since 3.8
2478
	 * @see CompletionProposalPopup#setSorter(ICompletionProposalSorter)
2479
	 */
2480
	public void setSorter(ICompletionProposalSorter sorter) {
2481
		fSorter= sorter;
2482
		registerSorterWithProposalPopup();
2483
	}
2484
2485
	/**
2486
	 * Registers the current sorter with the proposal popup - if the popup is already available.
2487
	 * Does nothing otherwise.
2488
	 */
2489
	private void registerSorterWithProposalPopup() {
2490
		if (fProposalPopup != null) {
2491
			fProposalPopup.setSorter(fSorter);
2492
		}
2493
	}
2465
}
2494
}
(-)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 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
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