KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > client > SortAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * SortAction.java
22  *
23  * Created on June 23, 2004, 4:07 PM
24  *
25  * @author Stepan Herold
26  * @version
27  */

28
29 package org.netbeans.modules.web.monitor.client;
30
31 import java.awt.event.ActionEvent JavaDoc;
32 import java.awt.event.ActionListener JavaDoc;
33 import javax.swing.JMenu JavaDoc;
34 import javax.swing.JMenuItem JavaDoc;
35 import javax.swing.JRadioButtonMenuItem JavaDoc;
36
37 import org.netbeans.modules.web.monitor.client.Controller.CompAlpha;
38 import org.netbeans.modules.web.monitor.client.Controller.CompTime;
39
40 import org.openide.nodes.Node;
41 import org.openide.util.HelpCtx;
42 import org.openide.util.NbBundle;
43 import org.openide.util.actions.NodeAction;
44
45
46
47 public class SortAction extends NodeAction {
48     // radio button menu items
49
private transient JMenuItem JavaDoc descSortMenuItem, ascSortMenuItem, alphSortMenuItem;
50     
51     protected boolean enable(Node[] activatedNodes) {
52         return true;
53     }
54     
55     public HelpCtx getHelpCtx() {
56         return HelpCtx.DEFAULT_HELP;
57     }
58     
59     public JMenuItem JavaDoc getPopupPresenter() {
60         JMenu JavaDoc menu = new JMenu JavaDoc(NbBundle.getMessage(MonitorAction.class, "MON_Sort_by"));
61
62         TransactionView transView = TransactionView.getInstance();
63         descSortMenuItem = createItem(
64             NbBundle.getMessage(MonitorAction.class, "MON_Sort_desc"),
65             transView.isDescButtonSelected());
66         ascSortMenuItem = createItem(
67             NbBundle.getMessage(MonitorAction.class, "MON_Sort_asc"),
68             transView.isAscButtonSelected());
69         alphSortMenuItem = createItem(
70             NbBundle.getMessage(MonitorAction.class, "MON_Sort_alph"),
71             transView.isAlphButtonSelected());
72         
73         ActionListener JavaDoc listener = new RadioMenuItemActioListener();
74         descSortMenuItem.addActionListener(listener);
75         ascSortMenuItem.addActionListener(listener);
76         alphSortMenuItem.addActionListener(listener);
77         
78         menu.add(descSortMenuItem);
79         menu.add(ascSortMenuItem);
80         menu.add(alphSortMenuItem);
81         
82         return menu;
83     }
84
85     private JMenuItem JavaDoc createItem(String JavaDoc dispName, boolean selected) {
86         JMenuItem JavaDoc item = new JRadioButtonMenuItem JavaDoc();
87         item.setText(dispName);
88         item.setSelected(selected);
89         return item;
90     }
91     
92     public String JavaDoc getName() {
93         return NbBundle.getMessage(MonitorAction.class, "MON_Sort_by");
94     }
95     
96     protected void performAction(Node[] activatedNodes) {
97     }
98     
99     class RadioMenuItemActioListener implements ActionListener JavaDoc {
100         public void actionPerformed(ActionEvent JavaDoc e) {
101             Controller controller = MonitorAction.getController();
102             TransactionView transView = TransactionView.getInstance();
103             Object JavaDoc source = e.getSource();
104             if (source == descSortMenuItem) {
105                 if (!transView.isDescButtonSelected()) {
106                     transView.toggleTaskbarButtons(false, true, false);
107                     controller.setComparator(controller.new CompTime(true));
108                 }
109              } else if (source == ascSortMenuItem) {
110                  if (!transView.isAscButtonSelected()) {
111                     transView.toggleTaskbarButtons(true, false, false);
112                     controller.setComparator(controller.new CompTime(false));
113                  }
114              } else if (source == alphSortMenuItem) {
115                  if (!transView.isAlphButtonSelected()) {
116                     transView.toggleTaskbarButtons(false, false, true);
117                     controller.setComparator(controller.new CompAlpha());
118                  }
119              }
120         }
121     }
122 }
123
Popular Tags