Skip to content

Commit 448a25d

Browse files
committed
Add ViewerComparator methods in INavigatorSorterService
As every ViewerSorter is ViewerComparator the new default methods can be trivially added to implementors. There are expected to be none as the interface is marked as noimplement and noextend.
1 parent de8c667 commit 448a25d

File tree

8 files changed

+121
-47
lines changed

8 files changed

+121
-47
lines changed

bundles/org.eclipse.ui.navigator/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Plugin.name
44
Bundle-SymbolicName: org.eclipse.ui.navigator; singleton:=true
5-
Bundle-Version: 3.12.600.qualifier
5+
Bundle-Version: 3.13.0.qualifier
66
Bundle-Activator: org.eclipse.ui.internal.navigator.NavigatorPlugin
77
Bundle-Vendor: %Plugin.providerName
88
Bundle-Localization: plugin

bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/sorters/NavigatorSorterService.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020
import java.util.Map;
2121

22+
import org.eclipse.jface.viewers.ViewerComparator;
2223
import org.eclipse.jface.viewers.ViewerSorter;
2324
import org.eclipse.ui.internal.navigator.NavigatorContentService;
2425
import org.eclipse.ui.internal.navigator.VisibilityAssistant.VisibilityListener;
@@ -66,6 +67,7 @@ private synchronized void computeSortOnlyDescriptors() {
6667
}
6768

6869
@Override
70+
@Deprecated(forRemoval = true, since = "2025-03")
6971
public ViewerSorter findSorterForParent(Object aParent) {
7072

7173
CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager
@@ -76,6 +78,17 @@ public ViewerSorter findSorterForParent(Object aParent) {
7678
return SkeletonViewerSorter.INSTANCE;
7779
}
7880

81+
@Override
82+
public ViewerComparator findComparatorForParent(Object aParent) {
83+
84+
CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager.getInstance()
85+
.findApplicableSorters(contentService, aParent);
86+
if (descriptors.length > 0) {
87+
return getSorter(descriptors[0]);
88+
}
89+
return SkeletonViewerSorter.INSTANCE;
90+
}
91+
7992
private ViewerSorter getSorter(CommonSorterDescriptor descriptor) {
8093
ViewerSorter sorter = null;
8194
synchronized (sorters) {
@@ -88,6 +101,7 @@ private ViewerSorter getSorter(CommonSorterDescriptor descriptor) {
88101
}
89102

90103
@Override
104+
@Deprecated(forRemoval = true, since = "2025-03")
91105
public synchronized ViewerSorter findSorter(INavigatorContentDescriptor source,
92106
Object parent, Object lvalue, Object rvalue) {
93107

@@ -119,10 +133,41 @@ public synchronized ViewerSorter findSorter(INavigatorContentDescriptor source,
119133
}
120134

121135
@Override
122-
public Map findAvailableSorters(INavigatorContentDescriptor theSource) {
136+
public synchronized ViewerComparator findComparator(INavigatorContentDescriptor source, Object parent,
137+
Object lvalue,
138+
Object rvalue) {
139+
140+
CommonSorterDescriptorManager dm = CommonSorterDescriptorManager.getInstance();
141+
CommonSorterDescriptor[] descriptors;
142+
143+
INavigatorContentDescriptor lookupDesc;
144+
for (int i = 0; i < sortOnlyDescriptors.length; i++) {
145+
lookupDesc = sortOnlyDescriptors[i];
146+
if (source != null && source.getSequenceNumber() < lookupDesc.getSequenceNumber()) {
147+
lookupDesc = source;
148+
source = null;
149+
i--;
150+
}
151+
descriptors = dm.findApplicableSorters(contentService, lookupDesc, parent);
152+
if (descriptors.length > 0) {
153+
return getSorter(descriptors[0]);
154+
}
155+
}
156+
157+
if (source != null) {
158+
descriptors = dm.findApplicableSorters(contentService, source, parent);
159+
if (descriptors.length > 0) {
160+
return getSorter(descriptors[0]);
161+
}
162+
}
163+
return null;
164+
}
165+
166+
@Override
167+
public Map<String, ViewerComparator> findAvailableSorters(INavigatorContentDescriptor theSource) {
123168

124169
CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager.getInstance().findApplicableSorters(theSource);
125-
Map<String, ViewerSorter> sorters = new HashMap<>();
170+
Map<String, ViewerComparator> sorters = new HashMap<>();
126171

127172
int count = 0;
128173
for (CommonSorterDescriptor descriptor : descriptors) {

bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/CommonViewerSorter.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2015 IBM Corporation and others.
2+
* Copyright (c) 2006, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -19,7 +19,7 @@
1919
import org.eclipse.jface.viewers.TreePath;
2020
import org.eclipse.jface.viewers.TreePathViewerSorter;
2121
import org.eclipse.jface.viewers.Viewer;
22-
import org.eclipse.jface.viewers.ViewerSorter;
22+
import org.eclipse.jface.viewers.ViewerComparator;
2323
import org.eclipse.osgi.util.NLS;
2424
import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
2525
import org.eclipse.ui.internal.navigator.NavigatorContentService;
@@ -99,15 +99,15 @@ public int compare(Viewer viewer, TreePath parentPath, Object e1, Object e2) {
9999
return -1;
100100
}
101101

102-
ViewerSorter sorter = null;
102+
ViewerComparator sorter = null;
103103

104104
// shortcut if contributed by same source
105105
if (sourceOfLvalue == sourceOfRvalue) {
106-
sorter = sorterService.findSorter(sourceOfLvalue, parent, e1, e2);
106+
sorter = sorterService.findComparator(sourceOfLvalue, parent, e1, e2);
107107
} else {
108108
// findSorter returns the sorter specified at the source or if it has a higher priority a sortOnly sorter that is registered for the parent
109-
ViewerSorter lSorter = findApplicableSorter(sourceOfLvalue, parent, e1, e2);
110-
ViewerSorter rSorter = findApplicableSorter(sourceOfRvalue, parent, e1, e2);
109+
ViewerComparator lSorter = findApplicableSorter(sourceOfLvalue, parent, e1, e2);
110+
ViewerComparator rSorter = findApplicableSorter(sourceOfRvalue, parent, e1, e2);
111111
sorter = rSorter;
112112

113113
if (rSorter == null || (lSorter != null && sourceOfLvalue.getSequenceNumber() < sourceOfRvalue.getSequenceNumber())) {
@@ -126,10 +126,10 @@ public int compare(Viewer viewer, TreePath parentPath, Object e1, Object e2) {
126126
return categoryDelta;
127127
}
128128

129-
private ViewerSorter findApplicableSorter(INavigatorContentDescriptor descriptor, Object parent,
129+
private ViewerComparator findApplicableSorter(INavigatorContentDescriptor descriptor, Object parent,
130130
Object e1,
131131
Object e2) {
132-
ViewerSorter sorter = sorterService.findSorter(descriptor, parent, e1, e2);
132+
ViewerComparator sorter = sorterService.findComparator(descriptor, parent, e1, e2);
133133
if (!descriptor.isSortOnly()) { // for compatibility
134134
if (!(descriptor.isTriggerPoint(e1) && descriptor.isTriggerPoint(e2))) {
135135
return null;
@@ -155,7 +155,7 @@ public boolean isSorterProperty(TreePath parentPath, Object element, String prop
155155
INavigatorContentDescriptor contentDesc = getSource(element);
156156
if (parentPath.getSegmentCount() == 0)
157157
return false;
158-
ViewerSorter sorter = sorterService.findSorter(contentDesc, parentPath.getLastSegment(), element, null);
158+
ViewerComparator sorter = sorterService.findComparator(contentDesc, parentPath.getLastSegment(), element, null);
159159
if (sorter != null)
160160
return sorter.isSorterProperty(element, property);
161161
return false;

bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/INavigatorSorterService.java

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2015 IBM Corporation and others.
2+
* Copyright (c) 2006, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,6 +16,7 @@
1616

1717
import java.util.Map;
1818

19+
import org.eclipse.jface.viewers.ViewerComparator;
1920
import org.eclipse.jface.viewers.ViewerSorter;
2021

2122
/**
@@ -31,7 +32,7 @@
3132
* </p>
3233
*
3334
* @see INavigatorContentService#getSorterService()
34-
* @see ViewerSorter
35+
* @see ViewerComparator
3536
*
3637
* @noimplement This interface is not intended to be implemented by clients.
3738
* @noextend This interface is not intended to be extended by clients.
@@ -44,46 +45,74 @@ public interface INavigatorSorterService {
4445
* associated {@link INavigatorContentService} and whose <b>parentExpression</b>
4546
* matches the given parent.
4647
*
47-
* @param aParent
48-
* An element from the tree
48+
* @param aParent An element from the tree
4949
* @return An applicable ViewerSorter or simple {@link ViewerSorter} if no
5050
* sorter is found.
51+
* @deprecated Use {@link #findComparatorForParent(Object)} instead
5152
*/
53+
@Deprecated(since = "2025-03", forRemoval = true)
5254
ViewerSorter findSorterForParent(Object aParent);
5355

56+
/**
57+
* Return a {@link ViewerComparator} from an extension which is visible to the
58+
* associated {@link INavigatorContentService} and whose <b>parentExpression</b>
59+
* matches the given parent.
60+
*
61+
* @param aParent An element from the tree
62+
* @return An applicable ViewerComparator or simple {@link ViewerComparator} if
63+
* no sorter is found.
64+
* @since 3.13
65+
*/
66+
ViewerComparator findComparatorForParent(Object aParent);
67+
5468
/**
5569
* Return a {@link ViewerSorter} from an extension which is visible to the
5670
* associated {@link INavigatorContentService} and whose <b>parentExpression</b>
5771
* matches the given parent.
5872
*
59-
* @param source
60-
* The source of the element.
61-
* @param parent
62-
* An element from the tree
63-
* @param lvalue
64-
* An element from the tree
65-
* @param rvalue
66-
* An element from the tree
73+
* @param source The source of the element.
74+
* @param parent An element from the tree
75+
* @param lvalue An element from the tree
76+
* @param rvalue An element from the tree
6777
* @return An applicable ViewerSorter or simple {@link ViewerSorter} if no
6878
* sorter is found.
79+
* @deprecated Use
80+
* {@link #findComparator(INavigatorContentDescriptor, Object, Object, Object)}
81+
* instead.
6982
*/
83+
@Deprecated(since = "2025-03", forRemoval = true)
7084
ViewerSorter findSorter(INavigatorContentDescriptor source, Object parent,
7185
Object lvalue, Object rvalue);
7286

87+
/**
88+
* Return a {@link ViewerComparator} from an extension which is visible to the
89+
* associated {@link INavigatorContentService} and whose <b>parentExpression</b>
90+
* matches the given parent.
91+
*
92+
* @param source The source of the element.
93+
* @param parent An element from the tree
94+
* @param lvalue An element from the tree
95+
* @param rvalue An element from the tree
96+
* @return An applicable ViewerComparator or simple {@link ViewerComparator} if
97+
* no sorter is found.
98+
* @since 3.13
99+
*/
100+
ViewerComparator findComparator(INavigatorContentDescriptor source, Object parent, Object lvalue,
101+
Object rvalue);
102+
73103
/**
74104
* Find and return all viewer sorters associated with the given descriptor.
75105
*
76106
* <p>
77-
* The <i>commonSorter</i> element is not required to have an id, so in
78-
* some cases, an auto-generated id, using the content extension id as a
79-
* base, is generated to ensure the map is properly filled with all
80-
* available sorters. No guarantees are given as to the order or consistency
81-
* of these generated ids between invocations.
107+
* The <i>commonSorter</i> element is not required to have an id, so in some
108+
* cases, an auto-generated id, using the content extension id as a base, is
109+
* generated to ensure the map is properly filled with all available sorters. No
110+
* guarantees are given as to the order or consistency of these generated ids
111+
* between invocations.
82112
* </p>
83113
*
84-
* @param theSource
85-
* A descriptor that identifies a particular content extension
86-
* @return A Map[String sorterDescriptorId, ViewerSorter instance] where the
114+
* @param theSource A descriptor that identifies a particular content extension
115+
* @return A Map[String sorterDescriptorId, ViewerComparator instance] where the
87116
* key is the id defined in the extension and the value is the
88117
* instantiated sorter.
89118
*
@@ -92,6 +121,6 @@ ViewerSorter findSorter(INavigatorContentDescriptor source, Object parent,
92121
* @see INavigatorContentExtension#getDescriptor()
93122
* @since 3.3
94123
*/
95-
public Map findAvailableSorters(INavigatorContentDescriptor theSource);
124+
public Map<String, ViewerComparator> findAvailableSorters(INavigatorContentDescriptor theSource);
96125

97126
}

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/SorterTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2008, 2023 Oakland Software Incorporated and others.
2+
* Copyright (c) 2008, 2025 Oakland Software Incorporated and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -131,7 +131,7 @@ public void DISABLED_testSorterContentOverride() throws Exception {
131131

132132
// Make it sort backwards so we can tell
133133
TestSorterResource sorter = (TestSorterResource) _contentService
134-
.getSorterService().findSorter(desc, _project, null, null);
134+
.getSorterService().findComparator(desc, _project, null, null);
135135
sorter._forward = false;
136136

137137
_contentService.bindExtensions(
@@ -258,7 +258,7 @@ public void testSorterContentOverrideNoSort() throws Exception {
258258

259259
// Make it sort backwards so we can tell
260260
TestSorterDataAndResource sorter = (TestSorterDataAndResource) _contentService
261-
.getSorterService().findSorter(desc, _project, null, null);
261+
.getSorterService().findComparator(desc, _project, null, null);
262262
sorter._forward = false;
263263

264264
_viewer.setExpandedState(_project, true);
@@ -326,7 +326,7 @@ public void testComparatorAsSorter() throws Exception {
326326

327327
INavigatorContentDescriptor desc = _contentService.getContentDescriptorById(TEST_CONTENT_COMPARATOR_MODEL);
328328

329-
ViewerComparator sorter = _contentService.getSorterService().findSorter(desc, _project, null, null);
329+
ViewerComparator sorter = _contentService.getSorterService().findComparator(desc, _project, null, null);
330330
assertNotNull(sorter);
331331
WrappedViewerComparator wrapper = (WrappedViewerComparator) sorter;
332332
TestComparatorData original = (TestComparatorData) wrapper.getWrappedComparator();
@@ -423,7 +423,7 @@ public void testSorterResource() throws Exception {
423423
.getContentDescriptorById(TEST_CONTENT_SORTER_RESOURCE);
424424

425425
TestSorterResource sorter = (TestSorterResource) _contentService
426-
.getSorterService().findSorter(desc, _p2, null, null);
426+
.getSorterService().findComparator(desc, _p2, null, null);
427427
sorter._forward = false;
428428

429429
IStructuredSelection sel;

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/extension/TestSorterData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2018 IBM Corporation and others.
2+
* Copyright (c) 2005, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,9 +16,9 @@
1616
import java.text.Collator;
1717

1818
import org.eclipse.jface.viewers.Viewer;
19-
import org.eclipse.jface.viewers.ViewerSorter;
19+
import org.eclipse.jface.viewers.ViewerComparator;
2020

21-
public class TestSorterData extends ViewerSorter {
21+
public class TestSorterData extends ViewerComparator {
2222

2323
public static String _sorterProperty;
2424
public static Object _sorterElement;

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/extension/TestSorterDataAndResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009 Oakland Software Incorporated and others.
2+
* Copyright (c) 2009, 2025 Oakland Software Incorporated and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,9 +17,9 @@
1717

1818
import org.eclipse.core.resources.IResource;
1919
import org.eclipse.jface.viewers.Viewer;
20-
import org.eclipse.jface.viewers.ViewerSorter;
20+
import org.eclipse.jface.viewers.ViewerComparator;
2121

22-
public class TestSorterDataAndResource extends ViewerSorter {
22+
public class TestSorterDataAndResource extends ViewerComparator {
2323

2424
public boolean _forward = true;
2525

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/extension/TestSorterResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009 Oakland Software Incorporated and others.
2+
* Copyright (c) 2009, 2025 Oakland Software Incorporated and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,9 +17,9 @@
1717

1818
import org.eclipse.core.resources.IResource;
1919
import org.eclipse.jface.viewers.Viewer;
20-
import org.eclipse.jface.viewers.ViewerSorter;
20+
import org.eclipse.jface.viewers.ViewerComparator;
2121

22-
public class TestSorterResource extends ViewerSorter {
22+
public class TestSorterResource extends ViewerComparator {
2323

2424
public static String _sorterProperty;
2525
public static Object _sorterElement;

0 commit comments

Comments
 (0)