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 212116 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 reordering
bug350991_jface.text.patch (text/plain), 5.99 KB, created by
Marcel Bruch
on 2012-03-06 03:12:42 EST
(
hide
)
Description:
Patch for jface.text to enable reordering
Filename:
MIME Type:
Creator:
Marcel Bruch
Created:
2012-03-06 03:12:42 EST
Size:
5.99 KB
patch
obsolete
>From 44c3d6b4b1a60b34586cc6fa0bd7d5fe502387c8 Mon Sep 17 00:00:00 2001 >From: Marcel Bruch <marcel.bruch@gmail.com> >Date: Fri, 2 Mar 2012 14:41:13 +0100 >Subject: [PATCH] https://bugs.eclipse.org/bugs/show_bug.cgi?id=350991 > >--- > .../contentassist/CompletionProposalPopup.java | 31 ++++++++++++++++ > .../jface/text/contentassist/ContentAssistant.java | 26 +++++++++++++ > .../contentassist/ICompletionProposalSorter.java | 38 ++++++++++++++++++++ > 3 files changed, 95 insertions(+), 0 deletions(-) > create mode 100644 org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java > >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..57b162a 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 >@@ -12,6 +12,8 @@ > 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 +431,7 @@ class CompletionProposalPopup implements IContentAssistListener { > */ > private boolean fIsColoredLabelsSupportEnabled= false; > >+ private ICompletionProposalSorter fSorter; > > /** > * Creates a new completion proposal popup for the given elements. >@@ -1096,6 +1099,8 @@ class CompletionProposalPopup implements IContentAssistListener { > if (oldProposals != fFilteredProposals) // reentrant call was first - abort > return; > >+ sortProposals(proposals); >+ > if (Helper.okToUse(fProposalTable)) { > if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null) > ((ICompletionProposalExtension2) oldProposal).unselected(fViewer); >@@ -1831,4 +1836,30 @@ class CompletionProposalPopup implements IContentAssistListener { > return new ProposalSelectionHandler(operationCode); > } > >+ /** >+ * Sets the sorter to use when reordering is required by one of the completion engines. >+ * >+ * @param sorter the sorter 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 >+ */ >+ 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..431dc86 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 >@@ -985,6 +985,11 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt > */ > private boolean fIsColoredLabelsSupportEnabled= false; > >+ /** >+ * The sorter used to order completion proposals before presented. >+ */ >+ private ICompletionProposalSorter fSorter; >+ > > /** > * Creates a new content assistant. The content assistant is not automatically activated, >@@ -2462,4 +2467,25 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt > fIsColoredLabelsSupportEnabled= isEnabled; > } > >+ /** >+ * Sets the sorter used to reorder proposal completions on typing >+ * >+ * @param sorter the sorter that specifies the order how the proposals are presented to the user >+ * @since 3.8 >+ * @see CompletionProposalPopup#setSorter(ICompletionProposalSorter) >+ */ >+ public void setSorter(ICompletionProposalSorter sorter) { >+ fSorter= sorter; >+ registerSorterWithProposalPopup(); >+ } >+ >+ /** >+ * Registers the current sorter with the proposal popup - if the popup is already available. >+ * Does nothing otherwise. >+ */ >+ private void registerSorterWithProposalPopup() { >+ 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..f57e8f8 >--- /dev/null >+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalSorter.java >@@ -0,0 +1,38 @@ >+/** >+ * Copyright (c) 2011 Darmstadt University of Technology. >+ * 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 - Initial API >+ */ >+package org.eclipse.jface.text.contentassist; >+ >+import java.util.Comparator; >+ >+/** >+ * <p> >+ * An <code>ICompletionProposalSorter</code> provides support for sorting proposals of a content >+ * assistant. >+ * </p> >+ * <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. >+ * >+ * @see Comparator#compare(Object, Object) >+ */ >+ public int compare(ICompletionProposal p1, ICompletionProposal p2); >+ >+} >-- >1.7.5.4 >
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