From eade832e0345596d9da905d22c400773dba2b13a Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Tue, 30 Apr 2013 14:20:11 +0200 Subject: Target Explorer: Fix sorting in tree should be case insensitive --- .../filesystem/ui/controls/FSTreeViewerSorter.java | 6 +- .../org.eclipse.tcf.te.tcf.processes.ui/plugin.xml | 2 +- .../plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml | 1182 ++++++++++---------- .../tcf/te/ui/views/navigator/ViewerSorter.java | 74 +- .../eclipse/tcf/te/ui/trees/TreeViewerSorter.java | 29 +- .../ui/trees/TreeViewerSorterCaseInsensitive.java | 26 + 6 files changed, 685 insertions(+), 634 deletions(-) create mode 100644 target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorterCaseInsensitive.java (limited to 'target_explorer') diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSTreeViewerSorter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSTreeViewerSorter.java index 657dc9378..1f548ab3a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSTreeViewerSorter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/controls/FSTreeViewerSorter.java @@ -3,7 +3,7 @@ * 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 http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ @@ -12,12 +12,12 @@ package org.eclipse.tcf.te.tcf.filesystem.ui.controls; import org.eclipse.jface.viewers.Viewer; import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; import org.eclipse.tcf.te.tcf.filesystem.ui.internal.columns.FSTreeElementComparator; -import org.eclipse.tcf.te.ui.trees.TreeViewerSorter; +import org.eclipse.tcf.te.ui.trees.TreeViewerSorterCaseInsensitive; /** * File system tree control viewer sorter implementation. */ -public class FSTreeViewerSorter extends TreeViewerSorter { +public class FSTreeViewerSorter extends TreeViewerSorterCaseInsensitive { private final FSTreeElementComparator comparator; /** diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml index c8139601f..04bb35434 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.processes.ui/plugin.xml @@ -104,7 +104,7 @@ + class="org.eclipse.tcf.te.ui.trees.TreeViewerSorterCaseInsensitive"> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml index bc33b3b03..5c85661e6 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml @@ -1,591 +1,591 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %NewTargetWizard.description - - - - - - - - - - - - %ImportWizards.PeerDescription - - - - - - - - - - - %ExportWizards.PeerDescription - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %NewTargetWizard.description + + + + + + + + + + + + %ImportWizards.PeerDescription + + + + + + + + + + + %ExportWizards.PeerDescription + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/navigator/ViewerSorter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/navigator/ViewerSorter.java index 4ed28b38c..e957a385a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/navigator/ViewerSorter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/navigator/ViewerSorter.java @@ -1,37 +1,37 @@ -/******************************************************************************* - * Copyright (c) 2012 Wind River Systems, Inc. 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 http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.ui.views.navigator; - -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.tcf.te.ui.trees.TreeViewerSorter; -import org.eclipse.tcf.te.ui.views.interfaces.ICategory; - -/** - * Category viewer sorter implementation. - */ -public class ViewerSorter extends TreeViewerSorter { - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.ui.trees.TreeViewerSorter#doCompare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object, java.lang.String, int, int) - */ - @Override - protected int doCompare(Viewer viewer, Object node1, Object node2, String sortColumn, int index, int inverter) { - if (node1 instanceof ICategory && node2 instanceof ICategory) { - int rank1 = ((ICategory)node1).getRank(); - int rank2 = ((ICategory)node2).getRank(); - - if (rank1 != -1 && rank2 != -1 && rank1 != rank2) { - return (rank1 - rank2) * inverter; - } - } - - return super.doCompare(viewer, node1, node2, sortColumn, index, inverter); - } -} +/******************************************************************************* + * Copyright (c) 2012, 2013 Wind River Systems, Inc. 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 http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.views.navigator; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.tcf.te.ui.trees.TreeViewerSorterCaseInsensitive; +import org.eclipse.tcf.te.ui.views.interfaces.ICategory; + +/** + * Category viewer sorter implementation. + */ +public class ViewerSorter extends TreeViewerSorterCaseInsensitive { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.trees.TreeViewerSorter#doCompare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object, java.lang.String, int, int) + */ + @Override + protected int doCompare(Viewer viewer, Object node1, Object node2, String sortColumn, int index, int inverter) { + if (node1 instanceof ICategory && node2 instanceof ICategory) { + int rank1 = ((ICategory)node1).getRank(); + int rank2 = ((ICategory)node2).getRank(); + + if (rank1 != -1 && rank2 != -1 && rank1 != rank2) { + return (rank1 - rank2) * inverter; + } + } + + return super.doCompare(viewer, node1, node2, sortColumn, index, inverter); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorter.java index 3e6dd2217..f6bd0d998 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorter.java @@ -28,9 +28,23 @@ import org.eclipse.swt.widgets.Tree; /** * Common sorter implementation. + *

+ * Note: The default implementation is implementing a case sensitive sorting. Numbers comes + * first, than uppercase before lowercase. */ public class TreeViewerSorter extends TreePathViewerSorter { + /** + * If or if not the sorting should happen case sensitive. + *

+ * The default implementation returns true. + * + * @return True if the sorting is case sensitive, false otherwise. + */ + protected boolean isCaseSensitve() { + return true; + } + /* (non-Javadoc) * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) */ @@ -147,13 +161,24 @@ public class TreeViewerSorter extends TreePathViewerSorter { */ protected int doCompare(Viewer viewer, Object node1, Object node2, String sortColumn, int index, int inverter) { if (node1 == null && node2 == null) return 0; - if (node1 != null && node2 == null) return 1; - if (node1 == null && node2 != null) return -1; + if (node1 != null && node2 == null) return 1 * inverter; + if (node1 == null && node2 != null) return -1 * inverter; // Get the labels String text1 = doGetText(viewer, node1, index); String text2 = doGetText(viewer, node2, index); + // If we fail to determine the labels, we cannot continue + if (text1 == null && text2 == null) return 0; + if (text1 != null && text2 == null) return 1 * inverter; + if (text1 == null && text2 != null) return -1 * inverter; + + // Convert the labels to compare to lowercase if the sorting is case-insensitive + if (!isCaseSensitve()) { + text1 = text1.toLowerCase(); + text2 = text2.toLowerCase(); + } + // The tree sorts not strictly alphabetical. First comes entries starting with numbers, // second entries starting with uppercase and than all the rest. Additional, if a label contains // uppercase characters, it is sorted in before any labels being lowercase only. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorterCaseInsensitive.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorterCaseInsensitive.java new file mode 100644 index 000000000..b28955ef2 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerSorterCaseInsensitive.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2013 Wind River Systems, Inc. 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 http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.trees; + + +/** + * Case insensitive common sorter implementation. + */ +public class TreeViewerSorterCaseInsensitive extends TreeViewerSorter { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.trees.TreeViewerSorter#isCaseSensitve() + */ + @Override + protected boolean isCaseSensitve() { + return false; + } + +} -- cgit v1.2.3