From b0794da4f1e5c519b28a24cb1d47e57033d03b04 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Thu, 8 Oct 2009 13:50:15 +0400 Subject: [PATCH] =?UTF-8?q?[RUBY-4423]=20Rails=20view:=20Logical=20sorting?= =?UTF-8?q?=20in=20db=E2=80=8B/=E2=80=8Bmigrate=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ide/projectView/ProjectViewNode.java | 21 +++++++++++++++++++ .../impl/GroupByTypeComparator.java | 13 +++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java b/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java index 474ccc011d33..e7bfc33f8af5 100644 --- a/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java +++ b/platform/lang-api/src/com/intellij/ide/projectView/ProjectViewNode.java @@ -165,11 +165,32 @@ public abstract class ProjectViewNode extends AbstractTreeNode { return 0; } + /** + * When nodes are sorted by type all objects with same weigh will be sorted using + * some common algorithm (e.g alpha comparator). This method allows to perform custom + * sorting for such objects. And default comparison will be applied only if nodes are equal + * from custom comparator's point of view. Also comparison will be applied only if both objects + * have not null comparable keys. + * @return Comparable object. + */ @Nullable public Comparable getTypeSortKey() { return null; } + /** + * When nodes aren't sorted by type all objects with same weigh will be sorted using + * some common algorithm (e.g alpha comparator). This method allows to perform custom + * sorting for such objects. And default comparison will be applied only if nodes are equal + * from custom comparator's point of view. Also comparison will be applied only if both objects + * have not null comparable keys. + * @return Comparable object. + */ + @Nullable + public Comparable getSortKey() { + return null; + } + @Nullable public String getQualifiedNameSortKey() { return null; diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/GroupByTypeComparator.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/GroupByTypeComparator.java index ac88f0939c08..8fa21d67fb2f 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/GroupByTypeComparator.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/GroupByTypeComparator.java @@ -58,10 +58,17 @@ public class GroupByTypeComparator implements Comparator { } if (isSortByType()) { - Comparable typeSortKey1 = node1.getTypeSortKey(); - Comparable typeSortKey2 = node2.getTypeSortKey(); + final Comparable typeSortKey1 = node1.getTypeSortKey(); + final Comparable typeSortKey2 = node2.getTypeSortKey(); if (typeSortKey1 != null && typeSortKey2 != null) { - int result = typeSortKey1.compareTo(typeSortKey2); + final int result = typeSortKey1.compareTo(typeSortKey2); + if (result != 0) return result; + } + } else { + final Comparable typeSortKey1 = node1.getSortKey(); + final Comparable typeSortKey2 = node2.getSortKey(); + if (typeSortKey1 != null && typeSortKey2 != null) { + final int result = typeSortKey1.compareTo(typeSortKey2); if (result != 0) return result; } }