Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2016-09-02 18:19:59 +0000
committerAndrey Loskutov - on the beach till 12.092016-09-07 13:14:43 +0000
commit7defd6d25ecbb5f3e4c88ba228056cdff3b53677 (patch)
treeb963fc3fbe1aee5d3c054fa85dcde730191cc35a
parent37ed33f1bf34d8d0948dd78e12012664bfee24f7 (diff)
downloadeclipse.platform.ui-7defd6d25ecbb5f3e4c88ba228056cdff3b53677.tar.gz
eclipse.platform.ui-7defd6d25ecbb5f3e4c88ba228056cdff3b53677.tar.xz
eclipse.platform.ui-7defd6d25ecbb5f3e4c88ba228056cdff3b53677.zip
Bug 364735 - [Viewers] ViewerComparator violates its general contract
Don't use DecoratingLabelProvider for sorting, see bug 364735 comment 60. The results from this label provider are unstable by design and may change during the sort operation. Instead, use the original label provider enclosed by the DecoratingLabelProvider. A new system property is introduced to restore the old behavior in case someone relies on the decorations for sorting: "eclipse.disable.fix.for.bug364735". If this system property is set to "true", this fix will be disabled. Change-Id: I67dd03e62b8d32913aacc5670c4b864264d8bc1e Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerComparator.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerComparator.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerComparator.java
index ea67e76a288..6fba2f92622 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerComparator.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerComparator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2015 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 IBM Corporation 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 430873
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 364735
******************************************************************************/
package org.eclipse.jface.viewers;
@@ -43,6 +44,9 @@ import org.eclipse.jface.util.Policy;
* @since 3.2
*/
public class ViewerComparator {
+
+ private static final boolean DISABLE_FIX_FOR_364735 = Boolean.getBoolean("eclipse.disable.fix.for.bug364735"); //$NON-NLS-1$
+
/**
* The comparator to use to sort a viewer's contents.
*/
@@ -145,6 +149,14 @@ public class ViewerComparator {
.getLabelProvider();
if (prov instanceof ILabelProvider) {
ILabelProvider lprov = (ILabelProvider) prov;
+ if (lprov instanceof DecoratingLabelProvider && !DISABLE_FIX_FOR_364735) {
+ // Bug 364735: use the real label provider to avoid unstable
+ // sort behavior if the decoration is running while sorting.
+ // decorations are usually visual aids to the user and
+ // shouldn't be used in ordering.
+ DecoratingLabelProvider dprov = (DecoratingLabelProvider) lprov;
+ lprov = dprov.getLabelProvider();
+ }
name1 = lprov.getText(e1);
} else {
name1 = e1.toString();

Back to the top