1 11 package org.eclipse.pde.internal.ui.editor.actions; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.action.IAction; 15 import org.eclipse.jface.util.IPropertyChangeListener; 16 import org.eclipse.jface.viewers.StructuredViewer; 17 import org.eclipse.jface.viewers.ViewerComparator; 18 import org.eclipse.pde.internal.ui.PDEPluginImages; 19 20 public class SortAction extends Action { 21 22 private boolean fSorted; 23 24 private StructuredViewer fViewer; 25 26 private ViewerComparator fComparator; 27 28 private ViewerComparator fDefaultComparator; 29 30 38 public SortAction(StructuredViewer viewer, String tooltipText, 39 ViewerComparator sorter, ViewerComparator defaultSorter, 40 IPropertyChangeListener listener) { 41 42 super(tooltipText, IAction.AS_CHECK_BOX); 43 setToolTipText(tooltipText); 45 setImageDescriptor(PDEPluginImages.DESC_ALPHAB_SORT_CO); 47 fDefaultComparator = defaultSorter; 49 fViewer = viewer; 51 if (sorter == null) { 54 fComparator = new ViewerComparator(); 55 } else { 56 fComparator = sorter; 57 } 58 if (viewer.getComparator() == fDefaultComparator) { 61 fSorted = false; 62 } else { 63 fSorted = true; 64 } 65 setChecked(fSorted); 68 if (listener != null) { 70 addListenerObject(listener); 71 } 72 } 73 74 77 public void run() { 78 if (fSorted) { 80 fViewer.setComparator(fDefaultComparator); 83 fSorted = false; 84 } else { 85 fViewer.setComparator(fComparator); 88 fSorted = true; 89 } 90 notifyResult(true); 91 } 92 93 } 94 | Popular Tags |