]>
git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/ArtifactNamesComparator.java
1 package org
.argeo
.slc
.client
.ui
.dist
.utils
;
3 import org
.argeo
.eclipse
.ui
.TreeParent
;
4 import org
.eclipse
.jface
.viewers
.Viewer
;
5 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
8 * Enable comparison of two names with form org.argeo.slc-1.2.x
11 public class ArtifactNamesComparator
extends ViewerComparator
{
14 public int category(Object element
) {
15 if (element
instanceof String
) {
16 int lastInd
= ((String
) element
).lastIndexOf('-');
20 // unvalid names always last
25 public int compare(Viewer viewer
, Object e1
, Object e2
) {
26 int cat1
= category(e1
);
27 int cat2
= category(e2
);
37 if (e1
instanceof TreeParent
) {
38 s1
= ((TreeParent
) e1
).getName();
39 s2
= ((TreeParent
) e2
).getName();
46 int i1
= s1
.lastIndexOf('-');
47 int i2
= s2
.lastIndexOf('-');
50 // Specific cases, unvalid Strings
53 return s1
.compareTo(s2
);
60 String aPref
= s1
.substring(0, s1
.lastIndexOf('-'));
61 String aSuf
= s1
.substring(s1
.lastIndexOf('-'));
63 String bPref
= s2
.substring(0, s2
.lastIndexOf('-'));
64 String bSuf
= s2
.substring(s2
.lastIndexOf('-'));
66 result
= aPref
.compareTo(bPref
);
70 return bSuf
.compareTo(aSuf
);