Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.eclipse.ui.navigator/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.navigator; singleton:=true
Bundle-Version: 3.12.600.qualifier
Bundle-Version: 3.13.0.qualifier
Bundle-Activator: org.eclipse.ui.internal.navigator.NavigatorPlugin
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,27 @@ public boolean isEnabledForParent(Object aParent) {

/**
*
* @return An instance of the ViewerSorter defined by the extension. Callers
* of this method are responsible for managing the instantiated
* filter.
* @return An instance of the ViewerComparator defined by the extension. Callers
* of this method are responsible for managing the instantiated filter.
*/
public ViewerSorter createSorter() {
final ViewerSorter[] sorter = new ViewerSorter[1];
public ViewerComparator createComparator() {
final ViewerComparator[] sorter = new ViewerComparator[1];

SafeRunner.run(new NavigatorSafeRunnable(element) {
@Override
public void run() throws Exception {
sorter[0] = createSorterInstance();
sorter[0] = createComparatorInstance();
}
});
if (sorter[0] != null)
return sorter[0];
return SkeletonViewerSorter.INSTANCE;
}

private ViewerSorter createSorterInstance() throws CoreException {
private ViewerComparator createComparatorInstance() throws CoreException {
Object contributed = element.createExecutableExtension(ATT_CLASS);
if (contributed instanceof ViewerSorter) {
return (ViewerSorter) contributed;
}
if (contributed instanceof ViewerComparator) {
return new WrappedViewerComparator((ViewerComparator) contributed);
if (contributed instanceof ViewerComparator comparator) {
return comparator;
}
throw new ClassCastException("Class contributed by " + element.getNamespaceIdentifier() + //$NON-NLS-1$
" to " + INavigatorContentExtPtConstants.TAG_NAVIGATOR_CONTENT + //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 IBM Corporation and others.
* Copyright (c) 2006, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -40,7 +40,7 @@ public class CommonSorterDescriptorManager {

private static final CommonSorterDescriptor[] NO_SORTER_DESCRIPTORS = new CommonSorterDescriptor[0];

private final Map<INavigatorContentDescriptor, Set> sortersMap = new HashMap<>();
private final Map<INavigatorContentDescriptor, Set<CommonSorterDescriptor>> sortersMap = new HashMap<>();

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 IBM Corporation and others.
* Copyright (c) 2006, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;

import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.ui.internal.navigator.NavigatorContentService;
import org.eclipse.ui.internal.navigator.VisibilityAssistant.VisibilityListener;
Expand All @@ -37,7 +38,7 @@ public class NavigatorSorterService implements INavigatorSorterService, Visibili
private final NavigatorContentService contentService;

/* A map of (CommonSorterDescriptor, ViewerSorter)-pairs */
private final Map<CommonSorterDescriptor, ViewerSorter> sorters = new HashMap<>();
private final Map<CommonSorterDescriptor, ViewerComparator> sorters = new HashMap<>();

private INavigatorContentDescriptor[] sortOnlyDescriptors;

Expand Down Expand Up @@ -66,70 +67,94 @@ private synchronized void computeSortOnlyDescriptors() {
}

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

CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager
.getInstance().findApplicableSorters(contentService, aParent);
ViewerComparator comparator = findComparatorForParent(aParent);
if (comparator != null) {
return new CommonSorterDescriptor.WrappedViewerComparator(comparator);
}
return SkeletonViewerSorter.INSTANCE;
}

@Override
public ViewerComparator findComparatorForParent(Object aParent) {

CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager.getInstance()
.findApplicableSorters(contentService, aParent);
if (descriptors.length > 0) {
return getSorter(descriptors[0]);
return getComparator(descriptors[0]);
}
return SkeletonViewerSorter.INSTANCE;
}

private ViewerSorter getSorter(CommonSorterDescriptor descriptor) {
ViewerSorter sorter = null;

private ViewerComparator getComparator(CommonSorterDescriptor descriptor) {
ViewerComparator sorter = null;
synchronized (sorters) {
sorter = sorters.get(descriptor);
if (sorter == null) {
sorters.put(descriptor, sorter = descriptor.createSorter());
sorters.put(descriptor, sorter = descriptor.createComparator());
}
}
return sorter;
}

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

CommonSorterDescriptorManager dm = CommonSorterDescriptorManager
.getInstance();
ViewerComparator comparator = findComparator(source, parent, lvalue, rvalue);
if (comparator != null) {
return new CommonSorterDescriptor.WrappedViewerComparator(comparator);
}
return null;
}

@Override
public synchronized ViewerComparator findComparator(INavigatorContentDescriptor source, Object parent,
Object lvalue,
Object rvalue) {

CommonSorterDescriptorManager dm = CommonSorterDescriptorManager.getInstance();
CommonSorterDescriptor[] descriptors;

INavigatorContentDescriptor lookupDesc;
for (int i = 0; i < sortOnlyDescriptors.length; i++) {
lookupDesc = sortOnlyDescriptors[i];
if (source!= null && source.getSequenceNumber() < lookupDesc.getSequenceNumber()) {
if (source != null && source.getSequenceNumber() < lookupDesc.getSequenceNumber()) {
lookupDesc = source;
source = null;
i--;
}
descriptors = dm. findApplicableSorters(contentService, lookupDesc, parent);
descriptors = dm.findApplicableSorters(contentService, lookupDesc, parent);
if (descriptors.length > 0) {
return getSorter(descriptors[0]);
return getComparator(descriptors[0]);
}
}

if (source != null) {
descriptors = dm. findApplicableSorters(contentService, source, parent);
descriptors = dm.findApplicableSorters(contentService, source, parent);
if (descriptors.length > 0) {
return getSorter(descriptors[0]);
return getComparator(descriptors[0]);
}
}
return null;
}

@Override
public Map findAvailableSorters(INavigatorContentDescriptor theSource) {
public Map<String, ViewerComparator> findAvailableSorters(INavigatorContentDescriptor theSource) {

CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager.getInstance().findApplicableSorters(theSource);
Map<String, ViewerSorter> sorters = new HashMap<>();
Map<String, ViewerComparator> sorters = new HashMap<>();

int count = 0;
for (CommonSorterDescriptor descriptor : descriptors) {
if(descriptor.getId() != null && descriptor.getId().length() > 0)
sorters.put(descriptor.getId(), getSorter(descriptor));
sorters.put(descriptor.getId(), getComparator(descriptor));
else
sorters.put(theSource.getId()+".sorter."+ (++count), getSorter(descriptor)); //$NON-NLS-1$
sorters.put(theSource.getId() + ".sorter." + (++count), getComparator(descriptor)); //$NON-NLS-1$
}
return sorters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void createPartControl(Composite aParent) {
commonViewer.addFilter(visibleFilter);
}

commonViewer.setSorter(new CommonViewerSorter());
commonViewer.setComparator(new CommonViewerSorter());

/*
* make sure input is set after sorters and filters to avoid unnecessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.events.DisposeEvent;
Expand Down Expand Up @@ -263,10 +264,11 @@ public void dispose() {
* Sets this viewer's sorter and triggers refiltering and resorting of this
* viewer's element. Passing <code>null</code> turns sorting off.
*
* @param sorter
* a viewer sorter, or <code>null</code> if none
* @param sorter a viewer sorter, or <code>null</code> if none
* @deprecated Use {@link #setComparator(ViewerComparator)} instead.
*/
@Override
@Deprecated(forRemoval = true, since = "2025-03")
public void setSorter(ViewerSorter sorter) {
if (sorter != null && sorter instanceof CommonViewerSorter commonSorter) {
commonSorter.setContentService(contentService);
Expand All @@ -275,6 +277,21 @@ public void setSorter(ViewerSorter sorter) {
super.setSorter(sorter);
}

/**
* Sets this viewer's sorter and triggers refiltering and resorting of this
* viewer's element. Passing <code>null</code> turns sorting off.
*
* @param comparator a viewer sorter, or <code>null</code> if none
*/
@Override
public void setComparator(ViewerComparator comparator) {
if (comparator != null && comparator instanceof CommonViewerSorter commonSorter) {
commonSorter.setContentService(contentService);
}

super.setComparator(comparator);
}

/**
* <p>
* The {@link INavigatorContentService}provides the hook into the framework
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 IBM Corporation and others.
* Copyright (c) 2006, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -19,7 +19,7 @@
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreePathViewerSorter;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
import org.eclipse.ui.internal.navigator.NavigatorContentService;
Expand Down Expand Up @@ -99,15 +99,15 @@ public int compare(Viewer viewer, TreePath parentPath, Object e1, Object e2) {
return -1;
}

ViewerSorter sorter = null;
ViewerComparator sorter = null;

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

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

private ViewerSorter findApplicableSorter(INavigatorContentDescriptor descriptor, Object parent,
private ViewerComparator findApplicableSorter(INavigatorContentDescriptor descriptor, Object parent,
Object e1,
Object e2) {
ViewerSorter sorter = sorterService.findSorter(descriptor, parent, e1, e2);
ViewerComparator sorter = sorterService.findComparator(descriptor, parent, e1, e2);
if (!descriptor.isSortOnly()) { // for compatibility
if (!(descriptor.isTriggerPoint(e1) && descriptor.isTriggerPoint(e2))) {
return null;
Expand All @@ -155,7 +155,7 @@ public boolean isSorterProperty(TreePath parentPath, Object element, String prop
INavigatorContentDescriptor contentDesc = getSource(element);
if (parentPath.getSegmentCount() == 0)
return false;
ViewerSorter sorter = sorterService.findSorter(contentDesc, parentPath.getLastSegment(), element, null);
ViewerComparator sorter = sorterService.findComparator(contentDesc, parentPath.getLastSegment(), element, null);
if (sorter != null)
return sorter.isSorterProperty(element, property);
return false;
Expand Down
Loading
Loading