KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > models > ClassesActionsProvider


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 package org.netbeans.modules.debugger.jpda.ui.models;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import javax.swing.AbstractAction JavaDoc;
27 import javax.swing.Action JavaDoc;
28 import javax.swing.JMenu JavaDoc;
29 import javax.swing.JMenuItem JavaDoc;
30 import javax.swing.JRadioButtonMenuItem JavaDoc;
31 import org.netbeans.api.debugger.Properties;
32 import org.netbeans.spi.debugger.ContextProvider;
33
34 import org.netbeans.spi.viewmodel.NodeActionsProvider;
35 import org.netbeans.spi.viewmodel.ModelListener;
36 import org.netbeans.spi.viewmodel.UnknownTypeException;
37 import org.netbeans.spi.viewmodel.Models;
38 import org.netbeans.spi.viewmodel.TreeModel;
39 import org.openide.awt.Mnemonics;
40
41 import org.openide.util.NbBundle;
42 import org.openide.util.RequestProcessor;
43 import org.openide.util.actions.Presenter;
44
45
46 /**
47  * @author Jan Jancura
48  */

49 public class ClassesActionsProvider implements NodeActionsProvider {
50     
51     private static Properties classesProperties = Properties.getDefault().
52             getProperties("debugger").getProperties("classesView"); // NOI18N
53

54     //private JPDADebugger debugger;
55
private TreeModel tree;
56     
57
58     public ClassesActionsProvider (ContextProvider lookupProvider) {
59         //debugger = (JPDADebugger) lookupProvider.lookupFirst(null, JPDADebugger.class);
60
tree = (TreeModel) lookupProvider.lookupFirst ("ClassesView", TreeModel.class);
61     }
62     
63     public Action JavaDoc[] getActions (Object JavaDoc node) throws UnknownTypeException {
64         return new Action JavaDoc[] { new PackageViewTypeAction(tree) };
65     }
66     
67     public void performDefaultAction (Object JavaDoc node) throws UnknownTypeException {
68         return;
69     }
70
71     private static class PackageViewTypeAction extends AbstractAction JavaDoc implements Presenter.Popup {
72
73         private TreeModel tree;
74  
75         PackageViewTypeAction(TreeModel tree) {
76             super ("");
77             this.tree = tree;
78         }
79         
80         public boolean isEnabled () {
81             return true;
82         }
83
84         public void actionPerformed (ActionEvent JavaDoc e) {
85             // Ignored
86
}
87         
88         public JMenuItem JavaDoc getPopupPresenter() {
89             JMenu JavaDoc menu = new JMenu JavaDoc();
90             Mnemonics.setLocalizedText(menu, NbBundle.getMessage(ClassesActionsProvider.class, "LBL_change_package_type"));
91             menu.add(createChoice(true, NbBundle.getMessage(ClassesActionsProvider.class, "ChangePackageViewTypeAction_list")));
92             menu.add(createChoice(false, NbBundle.getMessage(ClassesActionsProvider.class, "ChangePackageViewTypeAction_tree")));
93             return menu;
94         }
95
96         private JMenuItem JavaDoc createChoice(final boolean flat, String JavaDoc label) {
97             JRadioButtonMenuItem JavaDoc item = new JRadioButtonMenuItem JavaDoc();
98             Mnemonics.setLocalizedText(item, label);
99             boolean isFlat = classesProperties.getBoolean("flat", true);
100             item.setSelected(flat == isFlat);
101             item.addActionListener(new ActionListener JavaDoc() {
102                 public void actionPerformed(ActionEvent JavaDoc e) {
103                     classesProperties.setBoolean("flat", flat);
104                     // Refresh the classes view
105
// It's in a different module => we have to use reflection :-(
106
try {
107                         Method JavaDoc fireTreeChangedMethod =
108                                 tree.getClass().getMethod("fireTreeChanged", new Class JavaDoc[] {});
109                         try {
110                             fireTreeChangedMethod.invoke(tree, new Object JavaDoc[] {});
111                         } catch (IllegalArgumentException JavaDoc ex) {
112                         } catch (InvocationTargetException JavaDoc ex) {
113                         } catch (IllegalAccessException JavaDoc ex) {
114                         }
115                     } catch (SecurityException JavaDoc ex) {
116                     } catch (NoSuchMethodException JavaDoc ex) {
117                     }
118                 }
119             });
120             return item;
121         }
122     }
123 }
124
Popular Tags