001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /**
043: * SortAction.java
044: *
045: * Created on June 23, 2004, 4:07 PM
046: *
047: * @author Stepan Herold
048: * @version
049: */package org.netbeans.modules.web.monitor.client;
050:
051: import java.awt.event.ActionEvent;
052: import java.awt.event.ActionListener;
053: import javax.swing.JMenu;
054: import javax.swing.JMenuItem;
055: import javax.swing.JRadioButtonMenuItem;
056:
057: import org.netbeans.modules.web.monitor.client.Controller.CompAlpha;
058: import org.netbeans.modules.web.monitor.client.Controller.CompTime;
059:
060: import org.openide.nodes.Node;
061: import org.openide.util.HelpCtx;
062: import org.openide.util.NbBundle;
063: import org.openide.util.actions.NodeAction;
064:
065: public class SortAction extends NodeAction {
066: // radio button menu items
067: private transient JMenuItem descSortMenuItem, ascSortMenuItem,
068: alphSortMenuItem;
069:
070: protected boolean enable(Node[] activatedNodes) {
071: return true;
072: }
073:
074: public HelpCtx getHelpCtx() {
075: return HelpCtx.DEFAULT_HELP;
076: }
077:
078: public JMenuItem getPopupPresenter() {
079: JMenu menu = new JMenu(NbBundle.getMessage(MonitorAction.class,
080: "MON_Sort_by"));
081:
082: TransactionView transView = TransactionView.getInstance();
083: descSortMenuItem = createItem(NbBundle.getMessage(
084: MonitorAction.class, "MON_Sort_desc"), transView
085: .isDescButtonSelected());
086: ascSortMenuItem = createItem(NbBundle.getMessage(
087: MonitorAction.class, "MON_Sort_asc"), transView
088: .isAscButtonSelected());
089: alphSortMenuItem = createItem(NbBundle.getMessage(
090: MonitorAction.class, "MON_Sort_alph"), transView
091: .isAlphButtonSelected());
092:
093: ActionListener listener = new RadioMenuItemActioListener();
094: descSortMenuItem.addActionListener(listener);
095: ascSortMenuItem.addActionListener(listener);
096: alphSortMenuItem.addActionListener(listener);
097:
098: menu.add(descSortMenuItem);
099: menu.add(ascSortMenuItem);
100: menu.add(alphSortMenuItem);
101:
102: return menu;
103: }
104:
105: private JMenuItem createItem(String dispName, boolean selected) {
106: JMenuItem item = new JRadioButtonMenuItem();
107: item.setText(dispName);
108: item.setSelected(selected);
109: return item;
110: }
111:
112: public String getName() {
113: return NbBundle.getMessage(MonitorAction.class, "MON_Sort_by");
114: }
115:
116: protected void performAction(Node[] activatedNodes) {
117: }
118:
119: class RadioMenuItemActioListener implements ActionListener {
120: public void actionPerformed(ActionEvent e) {
121: Controller controller = MonitorAction.getController();
122: TransactionView transView = TransactionView.getInstance();
123: Object source = e.getSource();
124: if (source == descSortMenuItem) {
125: if (!transView.isDescButtonSelected()) {
126: transView.toggleTaskbarButtons(false, true, false);
127: controller.setComparator(controller.new CompTime(
128: true));
129: }
130: } else if (source == ascSortMenuItem) {
131: if (!transView.isAscButtonSelected()) {
132: transView.toggleTaskbarButtons(true, false, false);
133: controller.setComparator(controller.new CompTime(
134: false));
135: }
136: } else if (source == alphSortMenuItem) {
137: if (!transView.isAlphButtonSelected()) {
138: transView.toggleTaskbarButtons(false, false, true);
139: controller
140: .setComparator(controller.new CompAlpha());
141: }
142: }
143: }
144: }
145: }
|