]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElementSorter.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / wizards / buildpaths / CPListElementSorter.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.wizards.buildpaths;
12
13import org.eclipse.jface.viewers.ContentViewer;
14import org.eclipse.jface.viewers.IBaseLabelProvider;
15import org.eclipse.jface.viewers.ILabelProvider;
16import org.eclipse.jface.viewers.Viewer;
17import org.eclipse.jface.viewers.ViewerComparator;
18
19import org.eclipse.jdt.core.IAccessRule;
20import org.eclipse.jdt.core.IClasspathEntry;
21
22public class CPListElementSorter extends ViewerComparator {
23
24 private static final int SOURCE= 0;
25 private static final int PROJECT= 1;
26 private static final int LIBRARY= 2;
27 private static final int VARIABLE= 3;
28 private static final int CONTAINER= 4;
29
30 private static final int ATTRIBUTE= 5;
31 private static final int CONTAINER_ENTRY= 6;
32
33 private static final int OTHER= 7;
34
35 /*
36 * @see ViewerSorter#category(Object)
37 */
38 @Override
39 public int category(Object obj) {
40 if (obj instanceof CPListElement) {
41 CPListElement element= (CPListElement) obj;
42 if (element.getParentContainer() != null) {
43 return CONTAINER_ENTRY;
44 }
45 switch (element.getEntryKind()) {
46 case IClasspathEntry.CPE_LIBRARY:
47 return LIBRARY;
48 case IClasspathEntry.CPE_PROJECT:
49 return PROJECT;
50 case IClasspathEntry.CPE_SOURCE:
51 return SOURCE;
52 case IClasspathEntry.CPE_VARIABLE:
53 return VARIABLE;
54 case IClasspathEntry.CPE_CONTAINER:
55 return CONTAINER;
56 }
57 } else if (obj instanceof CPListElementAttribute) {
58 return ATTRIBUTE;
59 } else if (obj instanceof IAccessRule) {
60 return ATTRIBUTE;
61 }
62 return OTHER;
63 }
64
65 /* (non-Javadoc)
66 * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
67 */
68 @Override
69 public int compare(Viewer viewer, Object e1, Object e2) {
70
71 int cat1 = category(e1);
72 int cat2 = category(e2);
73
74 if (cat1 != cat2)
75 return cat1 - cat2;
76
77 if (cat1 == ATTRIBUTE || cat1 == CONTAINER_ENTRY) {
78 return 0; // do not sort attributes or container entries
79 }
80
81 if (viewer instanceof ContentViewer) {
82 IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
83 if (prov instanceof ILabelProvider) {
84 ILabelProvider lprov = (ILabelProvider) prov;
85 String name1 = lprov.getText(e1);
86 String name2 = lprov.getText(e2);
87 return getComparator().compare(name1, name2);
88 }
89 }
90 return 0;
91 }
92
93
94}