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 (-2 / +41 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 553-559 Link Here
553
	private ICompletionProposal[] computeProposals(int offset) {
563
	private ICompletionProposal[] computeProposals(int offset) {
554
		if (fContentAssistSubjectControl != null)
564
		if (fContentAssistSubjectControl != null)
555
			return fContentAssistant.computeCompletionProposals(fContentAssistSubjectControl, offset);
565
			return fContentAssistant.computeCompletionProposals(fContentAssistSubjectControl, offset);
556
		return fContentAssistant.computeCompletionProposals(fViewer, offset);
566
		ICompletionProposal[] proposals= fContentAssistant.computeCompletionProposals(fViewer, offset);
567
		return proposals;
557
	}
568
	}
558
569
559
	/**
570
	/**
Lines 1018-1024 Link Here
1018
		if (Helper.okToUse(fProposalShell)) {
1029
		if (Helper.okToUse(fProposalShell)) {
1019
1030
1020
			fContentAssistant.removeContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR);
1031
			fContentAssistant.removeContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR);
1021
1032
			fContentAssistant.setSorter(null);
1022
			fPopupCloser.uninstall();
1033
			fPopupCloser.uninstall();
1023
			fProposalShell.setVisible(false);
1034
			fProposalShell.setVisible(false);
1024
			fProposalShell.dispose();
1035
			fProposalShell.dispose();
Lines 1105-1110 Link Here
1105
				fEmptyProposal.fDisplayString= fEmptyMessage != null ? fEmptyMessage : JFaceTextMessages.getString("CompletionProposalPopup.no_proposals"); //$NON-NLS-1$
1116
				fEmptyProposal.fDisplayString= fEmptyMessage != null ? fEmptyMessage : JFaceTextMessages.getString("CompletionProposalPopup.no_proposals"); //$NON-NLS-1$
1106
				proposals= new ICompletionProposal[] { fEmptyProposal };
1117
				proposals= new ICompletionProposal[] { fEmptyProposal };
1107
			}
1118
			}
1119
1120
			sortProposals(proposals);
1108
1121
1109
			fFilteredProposals= proposals;
1122
			fFilteredProposals= proposals;
1110
			final int newLen= proposals.length;
1123
			final int newLen= proposals.length;
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 reordering is required by one of the completion engines.
1849
	 * 
1850
	 * @param sorter the new sorter to be used. May be <code>null</code>.
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 that specifies the order how the proposals are presented to the
2477
	 *            user, or <code>null</code> if no proposal resorting after filtering 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 (+41 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
import java.util.Comparator;
14
15
/**
16
 * An <code>ICompletionProposalSorter</code> provides support for sorting proposals of a content
17
 * assistant.
18
 * <p>
19
 * Implementors of this interface have to register this sorter with the content assist whenever
20
 * needed. See {@link ContentAssistant#setSorter(ICompletionProposalSorter)} for more information on
21
 * how to register a proposal sorter.
22
 * </p>
23
 * 
24
 * @since 3.8
25
 */
26
public interface ICompletionProposalSorter {
27
28
	/**
29
	 * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer
30
	 * as the first argument is less than, equal to, or greater than the second.
31
	 * 
32
	 * @param p1 the first proposal to be compared.
33
	 * @param p2 the second proposal to be compared.
34
	 * @return a negative integer, zero, or a positive integer as the first argument is less than,
35
	 *         equal to, or greater than the second.
36
	 * 
37
	 * @see Comparator#compare(Object, Object)
38
	 */
39
	public int compare(ICompletionProposal p1, ICompletionProposal p2);
40
41
}

Return to bug 350991