]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.dnd.JdtViewerDropSupport; | |
27 | import org.eclipse.jdt.internal.ui.viewsupport.SourcePositionComparator; | |
28 | ||
29 | /* | |
30 | * XXX: This class should become part of the MemberFilterActionGroup | |
31 | * which should be renamed to MemberActionsGroup | |
32 | */ | |
33 | public class LexicalSortingAction extends Action { | |
34 | private JavaElementComparator fComparator= new JavaElementComparator(); | |
35 | private SourcePositionComparator fSourcePositonComparator= new SourcePositionComparator(); | |
36 | private StructuredViewer fViewer; | |
37 | private String fPreferenceKey; | |
38 | private final JdtViewerDropSupport fDropSupport; | |
39 | ||
40 | public LexicalSortingAction(StructuredViewer viewer, String id, 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, "alphab_sort_co.gif"); //$NON-NLS-1$ | |
47 | setToolTipText(JavaBrowsingMessages.LexicalSortingAction_tooltip); | |
48 | setDescription(JavaBrowsingMessages.LexicalSortingAction_description); | |
49 | boolean checked= JavaPlugin.getDefault().getPreferenceStore().getBoolean(fPreferenceKey); | |
50 | valueChanged(checked, false); | |
51 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LEXICAL_SORTING_BROWSING_ACTION); | |
52 | } | |
53 | ||
54 | @Override | |
55 | public void run() { | |
56 | valueChanged(isChecked(), true); | |
57 | } | |
58 | ||
59 | private void valueChanged(final boolean on, boolean store) { | |
60 | setChecked(on); | |
61 | BusyIndicator.showWhile(fViewer.getControl().getDisplay(), new Runnable() { | |
62 | public void run() { | |
63 | if (on) { | |
64 | fViewer.setComparator(fComparator); | |
65 | fDropSupport.setFeedbackEnabled(false); | |
66 | } else { | |
67 | fViewer.setComparator(fSourcePositonComparator); | |
68 | fDropSupport.setFeedbackEnabled(true); | |
69 | } | |
70 | } | |
71 | }); | |
72 | ||
73 | if (store) | |
74 | JavaPlugin.getDefault().getPreferenceStore().setValue(fPreferenceKey, on); | |
75 | } | |
76 | } |