KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > navigator > SortViewAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11 package org.eclipse.ui.views.navigator;
12
13 import org.eclipse.ui.PlatformUI;
14 import org.eclipse.ui.internal.views.navigator.ResourceNavigatorMessages;
15
16 /**
17  * Implementation of the view sorting actions.
18  * @since 2.0
19  */

20 public class SortViewAction extends ResourceNavigatorAction {
21     private int sortCriteria;
22
23     /**
24      * Creates the action.
25      *
26      * @param navigator the resource navigator
27      * @param sortByType <code>true</code> for sort by type, <code>false</code> for sort by name
28      */

29     public SortViewAction(IResourceNavigator navigator, boolean sortByType) {
30         super(
31                 navigator,
32                 sortByType ? ResourceNavigatorMessages.SortView_byType : ResourceNavigatorMessages.SortView_byName);
33         if (sortByType) {
34             setToolTipText(ResourceNavigatorMessages.SortView_toolTipByType);
35         } else {
36             setToolTipText(ResourceNavigatorMessages.SortView_toolTipByName);
37         }
38         setEnabled(true);
39         sortCriteria = sortByType ? ResourceComparator.TYPE : ResourceComparator.NAME;
40         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
41                 INavigatorHelpContextIds.SORT_VIEW_ACTION);
42     }
43
44     public void run() {
45         IResourceNavigator navigator = getNavigator();
46         ResourceComparator comparator = navigator.getComparator();
47
48         if (comparator == null) {
49             navigator.setComparator(new ResourceComparator(sortCriteria));
50         } else {
51             comparator.setCriteria(sortCriteria);
52             navigator.setComparator(comparator);
53         }
54
55     }
56 }
57
Popular Tags