1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import javax.swing.AbstractAction ; 27 import javax.swing.Action ; 28 import javax.swing.JMenu ; 29 import javax.swing.JMenuItem ; 30 import javax.swing.JRadioButtonMenuItem ; 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 49 public class ClassesActionsProvider implements NodeActionsProvider { 50 51 private static Properties classesProperties = Properties.getDefault(). 52 getProperties("debugger").getProperties("classesView"); 54 private TreeModel tree; 56 57 58 public ClassesActionsProvider (ContextProvider lookupProvider) { 59 tree = (TreeModel) lookupProvider.lookupFirst ("ClassesView", TreeModel.class); 61 } 62 63 public Action [] getActions (Object node) throws UnknownTypeException { 64 return new Action [] { new PackageViewTypeAction(tree) }; 65 } 66 67 public void performDefaultAction (Object node) throws UnknownTypeException { 68 return; 69 } 70 71 private static class PackageViewTypeAction extends AbstractAction 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 e) { 85 } 87 88 public JMenuItem getPopupPresenter() { 89 JMenu menu = new JMenu (); 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 createChoice(final boolean flat, String label) { 97 JRadioButtonMenuItem item = new JRadioButtonMenuItem (); 98 Mnemonics.setLocalizedText(item, label); 99 boolean isFlat = classesProperties.getBoolean("flat", true); 100 item.setSelected(flat == isFlat); 101 item.addActionListener(new ActionListener () { 102 public void actionPerformed(ActionEvent e) { 103 classesProperties.setBoolean("flat", flat); 104 try { 107 Method fireTreeChangedMethod = 108 tree.getClass().getMethod("fireTreeChanged", new Class [] {}); 109 try { 110 fireTreeChangedMethod.invoke(tree, new Object [] {}); 111 } catch (IllegalArgumentException ex) { 112 } catch (InvocationTargetException ex) { 113 } catch (IllegalAccessException ex) { 114 } 115 } catch (SecurityException ex) { 116 } catch (NoSuchMethodException ex) { 117 } 118 } 119 }); 120 return item; 121 } 122 } 123 } 124 | Popular Tags |