diff options
author | Uwe Stieber | 2013-11-05 13:42:49 +0000 |
---|---|---|
committer | Uwe Stieber | 2013-11-05 13:42:49 +0000 |
commit | 78874d15279c984aad10908e957fa660ad267fdc (patch) | |
tree | 29222fc1e63a6cb9a2dd08906f6be6558cf1612e /target_explorer/plugins | |
parent | a570e40c532061fcfb7025e4cdbe6b03424be94f (diff) | |
download | org.eclipse.tcf-78874d15279c984aad10908e957fa660ad267fdc.tar.gz org.eclipse.tcf-78874d15279c984aad10908e957fa660ad267fdc.tar.xz org.eclipse.tcf-78874d15279c984aad10908e957fa660ad267fdc.zip |
Target Explorer: Fix If tree viewer column is associated with a comparator, use the custom column comparator if both elements are from the main content provider.
Diffstat (limited to 'target_explorer/plugins')
6 files changed, 94 insertions, 68 deletions
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 9faea0f74..2d53be057 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 @@ -33,7 +33,7 @@ public class FSTreeViewerSorter extends TreeViewerSorterCaseInsensitive { @Override public int compare(Viewer viewer, Object e1, Object e2) { if (e1 instanceof FSTreeNode && e2 instanceof FSTreeNode) { - return comparator.compare((FSTreeNode) e1, (FSTreeNode) e2); + return comparator.compare(e1, e2); } return super.compare(viewer, e1, e2); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java index 26fd99dc4..3584097d1 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/columns/FSTreeNodeComparator.java @@ -1,58 +1,63 @@ -/*******************************************************************************
- * Copyright (c) 2011, 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.tcf.filesystem.ui.internal.columns;
-
-import java.io.Serializable;
-import java.util.Comparator;
-
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-
-/**
- * The base comparator for all the file system tree column.
- */
-public abstract class FSTreeNodeComparator implements Comparator<FSTreeNode>, Serializable {
- private static final long serialVersionUID = 1L;
-
- /*
- * (non-Javadoc)
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- @Override
- public int compare(FSTreeNode node1, FSTreeNode node2) {
- // Get the type labels
- String type1 = node1.type;
- String type2 = node2.type;
-
- // Group directories and files always together before sorting by name
- if ((node1.isRoot() || node1.isDirectory()) && !(node2.isRoot() || node2.isDirectory())) {
- return -1;
- }
-
- if ((node2.isRoot() || node2.isDirectory()) && !(node1.isRoot() || node1.isDirectory())) {
- return 1;
- }
-
- // If the nodes are of the same type and one entry starts
- // with a '.', it comes before the one without a '.'
- if (type1 != null && type2 != null && type1.equals(type2)) {
- return doCompare(node1, node2);
- }
- return 0;
- }
-
- /**
- * Sort the node1 and node2 when they are both directories or files.
- *
- * @param node1 The first node.
- * @param node2 The second node.
- * @return The comparison result.
- */
- public abstract int doCompare(FSTreeNode node1, FSTreeNode node2);
-}
+/******************************************************************************* + * Copyright (c) 2011, 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.tcf.filesystem.ui.internal.columns; + +import java.io.Serializable; +import java.util.Comparator; + +import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode; + +/** + * The base comparator for all the file system tree column. + */ +public abstract class FSTreeNodeComparator implements Comparator<Object>, Serializable { + private static final long serialVersionUID = 1L; + + /* + * (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @Override + public final int compare(Object o1, Object o2) { + if (!(o1 instanceof FSTreeNode) || !(o2 instanceof FSTreeNode)) return 0; + + FSTreeNode node1 = (FSTreeNode)o1; + FSTreeNode node2 = (FSTreeNode)o2; + + // Get the type labels + String type1 = node1.type; + String type2 = node2.type; + + // Group directories and files always together before sorting by name + if ((node1.isRoot() || node1.isDirectory()) && !(node2.isRoot() || node2.isDirectory())) { + return -1; + } + + if ((node2.isRoot() || node2.isDirectory()) && !(node1.isRoot() || node1.isDirectory())) { + return 1; + } + + // If the nodes are of the same type and one entry starts + // with a '.', it comes before the one without a '.' + if (type1 != null && type2 != null && type1.equals(type2)) { + return doCompare(node1, node2); + } + return 0; + } + + /** + * Sort the node1 and node2 when they are both directories or files. + * + * @param node1 The first node. + * @param node2 The second node. + * @return The comparison result. + */ + public abstract int doCompare(FSTreeNode node1, FSTreeNode node2); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/schema/viewers.exsd b/target_explorer/plugins/org.eclipse.tcf.te.ui/schema/viewers.exsd index a5960af9a..e2a003230 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/schema/viewers.exsd +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/schema/viewers.exsd @@ -753,7 +753,7 @@ </appinfo> <documentation> <p> -In the "column" element, the class referenced by the attribute "labelProvider" must implement <samp>org.eclipse.jface.viewers.ILabelProvider</samp>. The class referenced by the attribute "comparator" must implement <samp>java.util.Comparator</samp> that compares the elements of the tree viewer. +In the "column" element, the class referenced by the attribute "labelProvider" must implement <samp>org.eclipse.jface.viewers.ILabelProvider</samp>. The class referenced by the attribute "comparator" must implement <samp>java.util.Comparator&lt;Object&gt;</samp> that compares the elements of the tree viewer. <p> In the "filter" element, the class referenced by the attribute "class" must extend <samp>org.eclipse.jface.viewers.ViewerFilter</samp>. <p> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/ColumnDescriptor.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/ColumnDescriptor.java index 0ca14a843..ebd0975bf 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/ColumnDescriptor.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/ColumnDescriptor.java @@ -70,8 +70,7 @@ public class ColumnDescriptor { private ILabelProvider labelProvider; //The comparator of the column, used to sort the viewer. - @SuppressWarnings("rawtypes") - private Comparator comparator; + private Comparator<Object> comparator; //The corresponding tree column. Not intended to be changed by other callers. private TreeColumn treeColumn; @@ -131,8 +130,7 @@ public class ColumnDescriptor { * * @param comparator The new comparator. */ - @SuppressWarnings("rawtypes") - public void setComparator(Comparator comparator) { + public void setComparator(Comparator<Object> comparator) { this.comparator = comparator; } @@ -141,8 +139,7 @@ public class ColumnDescriptor { * * @return The new comparator. */ - @SuppressWarnings("rawtypes") - public Comparator getComparator() { + public Comparator<Object> getComparator() { return comparator; } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeControlSorter.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeControlSorter.java index ff46f6846..ca3f77917 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeControlSorter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeControlSorter.java @@ -9,8 +9,13 @@ *******************************************************************************/ package org.eclipse.tcf.te.ui.trees; +import java.util.Comparator; + import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; /** * The tree control sorter determines if the elements to sort are from the same @@ -62,6 +67,26 @@ public class TreeControlSorter extends TreeViewerSorterCaseInsensitive { } } + if (c1 == null && c2 == null && viewer instanceof TreeViewer) { + // Both elements are from the main content provider, check if + // the current column has an comparator associated. + Tree tree = ((TreeViewer) viewer).getTree(); + TreeColumn treeColumn = tree.getSortColumn(); + if (treeColumn == null) { + // If the sort column is not set, then use the first column. + treeColumn = tree.getColumn(0); + } + if (treeColumn != null && !treeColumn.isDisposed()) { + ColumnDescriptor column = (ColumnDescriptor) treeColumn.getData(); + if (column != null) { + Comparator<Object> comparator = column.getComparator(); + if (comparator != null) { + return inverter * comparator.compare(e1, e2); + } + } + } + } + if (c1 == null && c2 != null || c1 != null && c2 == null) { // At least one of the elements is from the main content provider return inverter * (c1 == null ? -1 : 1); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java index 148845c34..0c22ea533 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/trees/TreeViewerExtension.java @@ -389,7 +389,6 @@ public class TreeViewerExtension { * @param configuration The configuration element. * @throws CoreException Thrown during parsing. */ - @SuppressWarnings("rawtypes") void initColumn(ColumnDescriptor column, IConfigurationElement configuration) throws CoreException { String name = configuration.getAttribute("name"); //$NON-NLS-1$ Assert.isNotNull(name); @@ -439,7 +438,7 @@ public class TreeViewerExtension { } attribute = configuration.getAttribute("comparator"); //$NON-NLS-1$ if (attribute != null) { - Comparator comparator = (Comparator) configuration.createExecutableExtension("comparator"); //$NON-NLS-1$ + Comparator<Object> comparator = (Comparator<Object>) configuration.createExecutableExtension("comparator"); //$NON-NLS-1$ if (comparator != null) { column.setComparator(comparator); } |