@Override public int compare(Viewer viewer, Object e1, Object e2) { // Status at the end of the list if (e1 instanceof IStatus && !(e2 instanceof IStatus)) { return 1; } if (e2 instanceof IStatus && !(e1 instanceof IStatus)) { return -1; } return super.compare(viewer, e1, e2); } });
@Override public ViewerComparator createOutlineComparator() { return new ViewerComparator(); }
@Override public void sort(Viewer viewer, Object[] elements) { if (elements.length > 0 && elements[0] instanceof GenModel) { super.sort(viewer, elements); } } });
int cat1 = category(e1); int cat2 = category(e2); String name1 = getLabel(viewer, e1); String name2 = getLabel(viewer, e2); return getComparator().compare(name1, name2);
int cat1 = category(e1); int cat2 = category(e2); return getComparator().compare(name1, name2);
public int category(Object element) { if (fEnvironment == null) { return super.category(element); } else { if (fEnvironment.isStrictlyCompatible((IVMInstall) element)) { return 0; } else { return 1; } } }
public int category(Object element) { if (element instanceof IHelpResource) { IHelpResource r = (IHelpResource)element; String c = context.getCategory(r); if (c!=null) { return -5; } } return super.category(element); }
int cat1 = category(e1); int cat2 = category(e2); String name1 = getLabel(viewer, e1); String name2 = getLabel(viewer, e2); return getComparator().compare(name1, name2);
@Override public int compare(Viewer viewer, Object e1, Object e2) { String s1 = e1.toString(); String s2 = e2.toString(); if (s1.indexOf(" ") != -1) //$NON-NLS-1$ s1 = s1.substring(0, s1.indexOf(" ")); //$NON-NLS-1$ if (s2.indexOf(" ") != -1) //$NON-NLS-1$ s2 = s2.substring(0, s2.indexOf(" ")); //$NON-NLS-1$ return super.compare(viewer, s1, s2); } });
@Override protected ViewerComparator createViewerComparator() { return new ViewerComparator(); }
@Override public void sort(final Viewer viewer, Object[] elements) { /* * https://bugs.eclipse.org/371354 * * This ordering is inherently unstable, since it relies on * modifiable properties of the elements: E.g. the default * implementation in JobTreeElement compares getDisplayString(), * many of whose implementations use getPercentDone(). * * JavaSE 7+'s TimSort introduced a breaking change: It now throws a * new IllegalArgumentException for bad comparators. Workaround is * to retry a few times. */ for (int retries = 3; retries > 0; retries--) { try { Arrays.sort(elements, (a, b) -> ProgressViewerComparator.this.compare(viewer, a, b)); return; // success } catch (IllegalArgumentException e) { // retry } } // One last try that will log and throw TimSort's IAE if it happens: super.sort(viewer, elements); } }
@Override public int category(Object element) { if (element instanceof WizardCollectionElement){ String id = ((WizardCollectionElement)element).getId(); if (WizardsRegistryReader.GENERAL_WIZARD_CATEGORY.equals(id)) { return 1; } if (WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY.equals(id)) { return 3; } return 2; } return super.category(element); }
@Override public int compare(Viewer viewer, Object e1, Object e2) { String s1 = e1.toString(); String s2 = e2.toString(); if (s1.indexOf(" ") != -1) //$NON-NLS-1$ s1 = s1.substring(0, s1.indexOf(" ")); //$NON-NLS-1$ if (s2.indexOf(" ") != -1) //$NON-NLS-1$ s2 = s2.substring(0, s2.indexOf(" ")); //$NON-NLS-1$ return super.compare(viewer, s1, s2); } });
@Override public ViewerComparator createDefaultOutlineComparator() { return new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof IDocumentKey) && (e2 instanceof IDocumentKey)) { IDocumentKey key1 = (IDocumentKey) e1; IDocumentKey key2 = (IDocumentKey) e2; return Integer.compare(key1.getOffset(), key2.getOffset()); } // Bundle manifest header elements // Do not sort by default return 0; } }; }
public void selectFirstElement() { Object element = null; if (fViewerComparator != null) { Object[] arr = fElements.toArray(); fViewerComparator.sort(fTable, arr); if (arr.length > 0) { element = arr[0]; } } else { if (fElements.size() > 0) { element = fElements.get(0); } } if (element != null) { selectElements(new StructuredSelection(element)); } }
@Override public int category(Object element) { if (element instanceof WorkbenchWizardElement) { return -1; } if (element instanceof WizardCollectionElement){ String id = ((WizardCollectionElement)element).getId(); if (WizardsRegistryReader.GENERAL_WIZARD_CATEGORY.equals(id)) { return 1; } if (WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY.equals(id)) { return 3; } if (WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY.equals(id)) { return 4; } return 2; } return super.category(element); }
public int compare(Viewer viewer, Object e1, Object e2) { fEnvironment = (IExecutionEnvironment) viewer.getInput(); int result = super.compare(viewer, e1, e2); fEnvironment = null; return result; }
public BasicPartList(Shell parent, int shellStyle, int treeStyler, EPartService partService, MElementContainer<?> input, StackRenderer renderer, ISWTResourceUtilities utils, boolean alphabetical) { super(parent, shellStyle, treeStyler); this.partService = partService; this.input = input; this.renderer = renderer; this.utils = utils; if (alphabetical && getTableViewer() != null) { getTableViewer().setComparator(new ViewerComparator()); } }
public void selectFirstElement() { Object element= null; if (fViewerComparator != null) { Object[] arr= fElements.toArray(); fViewerComparator.sort(fTable, arr); if (arr.length > 0) { element= arr[0]; } } else { if (fElements.size() > 0) { element= fElements.get(0); } } if (element != null) { selectElements(new StructuredSelection(element)); } }
@Override public int category(Object element) { if (element instanceof WorkbenchWizardElement) { return -1; } if (element instanceof WizardCollectionElement) { String id = ((WizardCollectionElement) element).getId(); if (WizardsRegistryReader.GENERAL_WIZARD_CATEGORY.equals(id)) { return 1; } if (WizardsRegistryReader.UNCATEGORIZED_WIZARD_CATEGORY.equals(id)) { return 3; } if (WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY.equals(id)) { return 4; } return 2; } return super.category(element); }