1 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 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 38 public LexicalSortingAction(StructuredViewer viewer, String id) { 39 super(); 40 fViewer= viewer; 41 fPreferenceKey= "LexicalSortingAction." + id + ".isChecked"; setText(JavaBrowsingMessages.LexicalSortingAction_label); 43 JavaPluginImages.setLocalImageDescriptors(this, "alphab_sort_co.gif"); 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 () { 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 |