01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package net.refractions.udig.internal.ui.operations;
11:
12: import net.refractions.udig.ui.operations.OpAction;
13:
14: import org.eclipse.jface.viewers.Viewer;
15: import org.eclipse.jface.viewers.ViewerSorter;
16: import org.eclipse.ui.internal.dialogs.DialogUtil;
17:
18: /**
19: * This is used to sort views in a RunOperationDialog.
20: */
21: public class OperationSorter extends ViewerSorter {
22:
23: public OperationSorter() {
24: super ();
25: }
26:
27: /**
28: * Returns a negative, zero, or positive number depending on whether
29: * the first element is less than, equal to, or greater than
30: * the second element.
31: */
32: public int compare(Viewer viewer, Object e1, Object e2) {
33:
34: //Categories are always greater than actions.
35: if (e1 instanceof OpAction && e2 instanceof OperationCategory) {
36: return 1;
37: }
38: if (e1 instanceof OperationCategory && e2 instanceof OpAction) {
39: return -1;
40: }
41:
42: String str1 = null;
43: String str2 = null;
44:
45: if (e1 instanceof OpAction) {
46: str1 = DialogUtil.removeAccel(((OpAction) e1).getText());
47: } else if (e1 instanceof OperationCategory) {
48: str1 = DialogUtil.removeAccel(((OperationCategory) e1)
49: .getMenuText());
50: }
51:
52: if (e2 instanceof OpAction) {
53: str2 = DialogUtil.removeAccel(((OpAction) e2).getText());
54: } else if (e2 instanceof OperationCategory) {
55: str2 = DialogUtil.removeAccel(((OperationCategory) e2)
56: .getMenuText());
57: }
58:
59: return collator.compare(str1, str2);
60: }
61: }
|