X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=case-study%2Fjdt-before%2Fui%2Forg%2Feclipse%2Fjdt%2Finternal%2Fui%2Fworkingsets%2FWorkingSetComparator.java;fp=case-study%2Fjdt-before%2Fui%2Forg%2Feclipse%2Fjdt%2Finternal%2Fui%2Fworkingsets%2FWorkingSetComparator.java;h=a27412b11328293b8e3f89afe8df2f84b2dbe0e8;hb=1b2798f607d741df30e5197f427381cbff326adc;hp=0000000000000000000000000000000000000000;hpb=246231e4bd9b24345490f369747c0549ca308c4d;p=ifi-stolz-refaktor.git diff --git a/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetComparator.java b/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetComparator.java new file mode 100644 index 00000000..a27412b1 --- /dev/null +++ b/case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetComparator.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2009, 2011 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.workingsets; + +import java.util.Comparator; + +import com.ibm.icu.text.Collator; + +import org.eclipse.ui.IWorkingSet; + + +/** + * Comparator class to sort working sets, optionally keeping the default working set at the top. + * + * @since 3.5 + */ +public class WorkingSetComparator implements Comparator { + + private Collator fCollator= Collator.getInstance(); + + /** + * Boolean value to determine whether to keep default working set on the top while sorting. + */ + private boolean fIsOtherWorkingSetOnTop; + + + /** + * Creates new instance of the working set comparator. + */ + public WorkingSetComparator() { + fIsOtherWorkingSetOnTop= false; + } + + /** + * Creates a new instance of working set comparator and initializes the boolean field value to + * the given value, which determines whether or not the default working set is kept on top while + * sorting the working sets. + * + * @param isOtherWorkingSetOnTop true if default working set is to be retained at + * the top, false otherwise + */ + public WorkingSetComparator(boolean isOtherWorkingSetOnTop) { + fIsOtherWorkingSetOnTop= isOtherWorkingSetOnTop; + } + + /** + * Returns -1 if the first argument is the default working set, 1 if + * the second argument is the default working set and if the boolean + * fIsOtherWorkingSetOnTop is set, to keep the default working set on top while + * sorting. + * + * @see Comparator#compare(Object, Object) + */ + public int compare(IWorkingSet w1, IWorkingSet w2) { + + if (fIsOtherWorkingSetOnTop && IWorkingSetIDs.OTHERS.equals(w1.getId())) + return -1; + + if (fIsOtherWorkingSetOnTop && IWorkingSetIDs.OTHERS.equals(w2.getId())) + return 1; + + return fCollator.compare(w1.getLabel(), w2.getLabel()); + } +} +