Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/eclipse/jdt/annotation/SortAction.java


1   package com.port80.eclipse.jdt.annotation;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.eclipse.jface.action.Action;
7   import org.eclipse.jface.action.ActionContributionItem;
8   import org.eclipse.jface.action.IMenuCreator;
9   import org.eclipse.swt.widgets.Control;
10  import org.eclipse.swt.widgets.Menu;
11  
12  import com.port80.eclipse.jdt.JdtPlugin;
13  import com.port80.eclipse.util.UtilPluginImages;
14  
15  /**
16   * @see org.eclipse.jdt.internal.ui.typehierarchy.HistoryDropDownAction
17   * @author chrisl
18   */
19  
20  public class SortAction extends Action implements IMenuCreator {
21  
22    private AnnotationView fView;
23    private List fActions = new ArrayList();
24  
25    public SortAction(AnnotationView view) {
26      fView = view;
27      setToolTipText(JdtPlugin.getString("AnnotationView.SortAction.tooltip")); //$NON-NLS-1$
28      UtilPluginImages.setLocalImageDescriptors(this, UtilPluginImages.IMG_HISTORY_LIST); //$NON-NLS-1$
29      //WorkbenchHelp.setHelp(this, IJavaHelpContextIds.TYPEHIERARCHY_HISTORY_ACTION);
30      setMenuCreator(this);
31    }
32  
33    public void dispose() {
34      fView = null;
35    }
36  
37    public Menu getMenu(Menu parent) {
38      return null;
39    }
40  
41    public Menu getMenu(Control parent) {
42      Menu menu = new Menu(parent);
43      String[] sortkeys = fView.getSortKeys();
44      String key=fView.getSortKey();
45      for (int i = 0; i < sortkeys.length; ++i) {
46        String name = sortkeys[i];
47        Action action = new Action() {
48          public void run() {
49            getView().setSortKey(getText());
50          }
51        };
52        action.setText(name);
53        action.setChecked(name.equals(key));
54        addActionToMenu(menu, action);
55        fActions.add(action);
56      }
57      return menu;
58    }
59  
60    public void run() {
61      fView.setSortKey(fView.getSortKey());
62    }
63  
64    ////////////////////////////////////////////////////////////////////////
65  
66    AnnotationView getView() {
67      return fView;
68    }
69    
70    private void addActionToMenu(Menu parent, Action action) {
71      ActionContributionItem item = new ActionContributionItem(action);
72      item.fill(parent, -1);
73    }
74  
75    ////////////////////////////////////////////////////////////////////////
76  }