KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > actions > LexicalSortingAction


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.jdt.internal.ui.actions;
12
13 import org.eclipse.swt.custom.BusyIndicator;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.viewers.StructuredViewer;
17
18 import org.eclipse.ui.PlatformUI;
19
20 import org.eclipse.jdt.ui.JavaElementComparator;
21
22 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
23 import org.eclipse.jdt.internal.ui.JavaPlugin;
24 import org.eclipse.jdt.internal.ui.JavaPluginImages;
25 import org.eclipse.jdt.internal.ui.browsing.JavaBrowsingMessages;
26 import org.eclipse.jdt.internal.ui.viewsupport.SourcePositionComparator;
27
28 /*
29  * XXX: This class should become part of the MemberFilterActionGroup
30  * which should be renamed to MemberActionsGroup
31  */

32 public class LexicalSortingAction extends Action {
33     private JavaElementComparator fComparator= new JavaElementComparator();
34     private SourcePositionComparator fSourcePositonComparator= new SourcePositionComparator();
35     private StructuredViewer fViewer;
36     private String JavaDoc fPreferenceKey;
37
38     public LexicalSortingAction(StructuredViewer viewer, String JavaDoc id) {
39         super();
40         fViewer= viewer;
41         fPreferenceKey= "LexicalSortingAction." + id + ".isChecked"; //$NON-NLS-1$ //$NON-NLS-2$
42
setText(JavaBrowsingMessages.LexicalSortingAction_label);
43         JavaPluginImages.setLocalImageDescriptors(this, "alphab_sort_co.gif"); //$NON-NLS-1$
44
setToolTipText(JavaBrowsingMessages.LexicalSortingAction_tooltip);
45         setDescription(JavaBrowsingMessages.LexicalSortingAction_description);
46         boolean checked= JavaPlugin.getDefault().getPreferenceStore().getBoolean(fPreferenceKey);
47         valueChanged(checked, false);
48         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LEXICAL_SORTING_BROWSING_ACTION);
49     }
50
51     public void run() {
52         valueChanged(isChecked(), true);
53     }
54
55     private void valueChanged(final boolean on, boolean store) {
56         setChecked(on);
57         BusyIndicator.showWhile(fViewer.getControl().getDisplay(), new Runnable JavaDoc() {
58             public void run() {
59                 if (on)
60                     fViewer.setComparator(fComparator);
61                 else
62                     fViewer.setComparator(fSourcePositonComparator);
63             }
64         });
65         
66         if (store)
67             JavaPlugin.getDefault().getPreferenceStore().setValue(fPreferenceKey, on);
68     }
69 }
70
Popular Tags