1 11 12 package org.eclipse.ui.internal.navigator.sorters; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.jface.viewers.ViewerSorter; 18 import org.eclipse.ui.internal.navigator.NavigatorContentService; 19 import org.eclipse.ui.navigator.INavigatorContentDescriptor; 20 import org.eclipse.ui.navigator.INavigatorSorterService; 21 22 29 public class NavigatorSorterService implements INavigatorSorterService { 30 31 private final NavigatorContentService contentService; 32 33 34 private final Map sorters = new HashMap (); 35 36 43 public NavigatorSorterService(NavigatorContentService aContentService) { 44 contentService = aContentService; 45 } 46 47 52 public ViewerSorter findSorterForParent(Object aParent) { 53 54 CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager 55 .getInstance().findApplicableSorters(contentService, aParent); 56 if (descriptors.length > 0) { 57 return getSorter(descriptors[0]); 58 } 59 return SkeletonViewerSorter.INSTANCE; 60 } 61 62 private ViewerSorter getSorter(CommonSorterDescriptor descriptor) { 63 ViewerSorter sorter = null; 64 synchronized (sorters) { 65 sorter = (ViewerSorter) sorters.get(descriptor); 66 if (sorter == null) { 67 sorters.put(descriptor, sorter = descriptor.createSorter()); 68 } 69 } 70 return sorter; 71 } 72 73 79 public ViewerSorter findSorter(INavigatorContentDescriptor source, 80 Object parent, Object lvalue, Object rvalue) { 81 82 CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager 83 .getInstance().findApplicableSorters(contentService, source, parent, lvalue, rvalue); 84 if(descriptors.length > 0) { 85 return getSorter(descriptors[0]); 86 } 87 return null; 88 } 89 90 93 public Map findAvailableSorters(INavigatorContentDescriptor theSource) { 94 95 CommonSorterDescriptor[] descriptors = CommonSorterDescriptorManager.getInstance().findApplicableSorters(theSource); 96 Map sorters = new HashMap (); 97 98 int count = 0; 99 for (int i = 0; i < descriptors.length; i++) { 100 if(descriptors[i].getId() != null && descriptors[i].getId().length() > 0) 101 sorters.put(descriptors[i].getId(), getSorter(descriptors[i])); 102 else 103 sorters.put(theSource.getId()+".sorter."+ (++count), getSorter(descriptors[i])); } 105 return sorters; 106 } 107 108 109 } 110 | Popular Tags |