Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 212525 Details for
Bug 350991
[content assist][api] Allow to re-sort proposals
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch for jface.text to enable proposal resorting after filtering
eclipse.platform.text.patch (text/plain), 7.85 KB, created by
Marcel Bruch
on 2012-03-13 03:35:52 EDT
(
hide
)
Description:
patch for jface.text to enable proposal resorting after filtering
Filename:
MIME Type:
Creator:
Marcel Bruch
Created:
2012-03-13 03:35:52 EDT
Size:
7.85 KB
patch
obsolete
>diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java >index 8644363..94c8e12 100644 >--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java >+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java >@@ -8,10 +8,13 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Sean Montgomery, sean_montgomery@comcast.net - https://bugs.eclipse.org/bugs/show_bug.cgi?id=116454 >+ * Marcel Bruch, bruch@cs.tu-darmstadt.de - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > *******************************************************************************/ > package org.eclipse.jface.text.contentassist; > > import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Comparator; > import java.util.List; > > import org.eclipse.osgi.util.TextProcessor; >@@ -429,6 +432,13 @@ > */ > private boolean fIsColoredLabelsSupportEnabled= false; > >+ /** >+ * The most recent sorter. Used when sorting proposals after filtering is requested by a completion engine. The sorter may >+ * be <code>null</code>. >+ * >+ * @since 3.8 >+ */ >+ private ICompletionProposalSorter fSorter; > > /** > * Creates a new completion proposal popup for the given elements. >@@ -553,7 +563,8 @@ > private ICompletionProposal[] computeProposals(int offset) { > if (fContentAssistSubjectControl != null) > return fContentAssistant.computeCompletionProposals(fContentAssistSubjectControl, offset); >- return fContentAssistant.computeCompletionProposals(fViewer, offset); >+ ICompletionProposal[] proposals= fContentAssistant.computeCompletionProposals(fViewer, offset); >+ return proposals; > } > > /** >@@ -1018,7 +1029,7 @@ > if (Helper.okToUse(fProposalShell)) { > > fContentAssistant.removeContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR); >- >+ fContentAssistant.setSorter(null); > fPopupCloser.uninstall(); > fProposalShell.setVisible(false); > fProposalShell.dispose(); >@@ -1105,6 +1116,8 @@ > fEmptyProposal.fDisplayString= fEmptyMessage != null ? fEmptyMessage : JFaceTextMessages.getString("CompletionProposalPopup.no_proposals"); //$NON-NLS-1$ > proposals= new ICompletionProposal[] { fEmptyProposal }; > } >+ >+ sortProposals(proposals); > > fFilteredProposals= proposals; > final int newLen= proposals.length; >@@ -1831,4 +1844,30 @@ > return new ProposalSelectionHandler(operationCode); > } > >+ /** >+ * Sets the sorter to use when reordering is required by one of the completion engines. >+ * >+ * @param sorter the new sorter to be used. May be <code>null</code>. >+ * @since 3.8 >+ */ >+ public void setSorter(ICompletionProposalSorter sorter) { >+ fSorter= sorter; >+ } >+ >+ /** >+ * Sorts the given proposal array if a sorter is configured. Does nothing otherwise. >+ * >+ * @param proposals the new proposals to display in the popup window >+ * @since 3.8 >+ */ >+ private void sortProposals(final ICompletionProposal[] proposals) { >+ if (fSorter != null) { >+ Arrays.sort(proposals, new Comparator() { >+ public int compare(Object o1, Object o2) { >+ return fSorter.compare((ICompletionProposal)o1, >+ (ICompletionProposal)o2); >+ } >+ }); >+ } >+ } > } >diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java >index e69d019..f0e6a22 100644 >--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java >+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Guy Gurfinkel, guy.g@zend.com - [content assist][api] provide better access to ContentAssistant - https://bugs.eclipse.org/bugs/show_bug.cgi?id=169954 > * 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 >+ * Marcel Bruch, bruch@cs.tu-darmstadt.de - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > *******************************************************************************/ > package org.eclipse.jface.text.contentassist; > >@@ -985,6 +986,12 @@ > */ > private boolean fIsColoredLabelsSupportEnabled= false; > >+ /** >+ * The sorter used to sort completion proposals when filtering was triggered. >+ * >+ * @since 3.8 >+ */ >+ private ICompletionProposalSorter fSorter; > > /** > * Creates a new content assistant. The content assistant is not automatically activated, >@@ -1374,6 +1381,7 @@ > > fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this); > fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller); >+ fProposalPopup.setSorter(fSorter); > > registerHandler(SELECT_NEXT_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_NEXT)); > registerHandler(SELECT_PREVIOUS_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_PREVIOUS)); >@@ -2462,4 +2470,18 @@ > fIsColoredLabelsSupportEnabled= isEnabled; > } > >+ /** >+ * Sets the sorter used to sort proposal completions after filtering is triggered. >+ * >+ * @param sorter the sorter that specifies the order how the proposals are presented to the >+ * user, or <code>null</code> if no proposal resorting after filtering is needed. >+ * @since 3.8 >+ * @see CompletionProposalPopup#setSorter(ICompletionProposalSorter) >+ */ >+ public void setSorter(ICompletionProposalSorter sorter) { >+ fSorter= sorter; >+ if (fProposalPopup != null) { >+ fProposalPopup.setSorter(fSorter); >+ } >+ } > } >diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java >new file mode 100644 >index 0000000..42c59ea >--- /dev/null >+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java >@@ -0,0 +1,41 @@ >+/** >+ * Copyright (c) 2012 Darmstadt University of Technology and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Marcel Bruch, bruch@cs.tu-darmstadt.de - [content assist] Allow to re-sort proposals - https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 >+ */ >+package org.eclipse.jface.text.contentassist; >+ >+import java.util.Comparator; >+ >+/** >+ * An <code>ICompletionProposalSorter</code> provides support for sorting proposals of a content >+ * assistant. >+ * <p> >+ * Implementors of this interface have to register this sorter with the content assist whenever >+ * needed. See {@link ContentAssistant#setSorter(ICompletionProposalSorter)} for more information on >+ * how to register a proposal sorter. >+ * </p> >+ * >+ * @since 3.8 >+ */ >+public interface ICompletionProposalSorter { >+ >+ /** >+ * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer >+ * as the first argument is less than, equal to, or greater than the second. >+ * >+ * @param p1 the first proposal to be compared. >+ * @param p2 the second proposal to be compared. >+ * @return a negative integer, zero, or a positive integer as the first argument is less than, >+ * equal to, or greater than the second. >+ * >+ * @see Comparator#compare(Object, Object) >+ */ >+ public int compare(ICompletionProposal p1, ICompletionProposal p2); >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 350991
:
211946
|
211947
|
211966
|
211967
|
211968
|
212115
|
212116
|
212117
|
212506
|
212507
|
212525
|
212588
|
212589