01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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 org.eclipse.jdt.internal.ui.actions;
11:
12: import org.eclipse.swt.custom.BusyIndicator;
13:
14: import org.eclipse.jface.action.Action;
15: import org.eclipse.jface.viewers.StructuredViewer;
16:
17: import org.eclipse.ui.PlatformUI;
18:
19: import org.eclipse.jdt.ui.JavaElementComparator;
20:
21: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
22: import org.eclipse.jdt.internal.ui.JavaPlugin;
23: import org.eclipse.jdt.internal.ui.JavaPluginImages;
24: import org.eclipse.jdt.internal.ui.browsing.JavaBrowsingMessages;
25: import org.eclipse.jdt.internal.ui.dnd.JdtViewerDropSupport;
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 fPreferenceKey;
37: private final JdtViewerDropSupport fDropSupport;
38:
39: public LexicalSortingAction(StructuredViewer viewer, String id,
40: JdtViewerDropSupport dropSupport) {
41: super ();
42: fViewer = viewer;
43: fDropSupport = dropSupport;
44: fPreferenceKey = "LexicalSortingAction." + id + ".isChecked"; //$NON-NLS-1$ //$NON-NLS-2$
45: setText(JavaBrowsingMessages.LexicalSortingAction_label);
46: JavaPluginImages.setLocalImageDescriptors(this ,
47: "alphab_sort_co.gif"); //$NON-NLS-1$
48: setToolTipText(JavaBrowsingMessages.LexicalSortingAction_tooltip);
49: setDescription(JavaBrowsingMessages.LexicalSortingAction_description);
50: boolean checked = JavaPlugin.getDefault().getPreferenceStore()
51: .getBoolean(fPreferenceKey);
52: valueChanged(checked, false);
53: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
54: IJavaHelpContextIds.LEXICAL_SORTING_BROWSING_ACTION);
55: }
56:
57: public void run() {
58: valueChanged(isChecked(), true);
59: }
60:
61: private void valueChanged(final boolean on, boolean store) {
62: setChecked(on);
63: BusyIndicator.showWhile(fViewer.getControl().getDisplay(),
64: new Runnable() {
65: public void run() {
66: if (on) {
67: fViewer.setComparator(fComparator);
68: fDropSupport.setFeedbackEnabled(false);
69: } else {
70: fViewer
71: .setComparator(fSourcePositonComparator);
72: fDropSupport.setFeedbackEnabled(true);
73: }
74: }
75: });
76:
77: if (store)
78: JavaPlugin.getDefault().getPreferenceStore().setValue(
79: fPreferenceKey, on);
80: }
81: }
|