1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import org.netbeans.api.debugger.DebuggerEngine; 23 import org.netbeans.spi.viewmodel.NodeActionsProviderFilter; 24 import org.netbeans.spi.viewmodel.NodeActionsProvider; 25 import org.netbeans.spi.viewmodel.UnknownTypeException; 26 import org.netbeans.spi.viewmodel.ModelListener; 27 import org.netbeans.api.debugger.Session; 28 import org.netbeans.api.debugger.jpda.JPDADebugger; 29 import org.netbeans.spi.debugger.ContextProvider; 30 31 import org.openide.util.actions.Presenter; 32 import org.openide.util.NbBundle; 33 34 import javax.swing.*; 35 import java.util.*; 36 import java.awt.event.ActionEvent ; 37 38 43 public class JPDASessionActionsProvider implements NodeActionsProviderFilter { 44 45 private HashSet listeners; 46 47 48 public JPDASessionActionsProvider () { 49 } 50 51 public void performDefaultAction(NodeActionsProvider original, Object node) throws UnknownTypeException { 52 original.performDefaultAction(node); 53 } 54 55 public Action [] getActions(NodeActionsProvider original, Object node) throws UnknownTypeException { 56 57 if (!(node instanceof Session) || !SessionsTableModelFilter.isJPDASession((Session) node)) { 58 return original.getActions(node); 59 } 60 Session session = (Session) node; 61 Action [] actions; 62 try { 63 actions = original.getActions(node); 64 } catch (UnknownTypeException e) { 65 actions = new Action[0]; 66 } 67 List myActions = new ArrayList(); 68 DebuggerEngine e = session.getCurrentEngine (); 69 if (e != null) { 70 JPDADebugger d = (JPDADebugger) e.lookupFirst(null, JPDADebugger.class); 71 myActions.add(new CustomizeSession(d)); 72 } 73 myActions.add(new LanguageSelection(session)); 74 myActions.addAll(Arrays.asList(actions)); 75 return (Action[]) myActions.toArray(new Action[myActions.size()]); 76 } 77 78 private String localize(String s) { 79 return NbBundle.getBundle(JPDASessionActionsProvider.class).getString(s); 80 } 81 82 private class LanguageSelection extends AbstractAction implements Presenter.Popup { 83 84 private Session session; 85 86 public LanguageSelection(Session session) { 87 this.session = session; 88 } 89 90 public void actionPerformed(ActionEvent e) { 91 } 92 93 public JMenuItem getPopupPresenter() { 94 JMenu displayAsPopup = new JMenu(localize("CTL_Session_Popup_Language")); 95 96 String [] languages = session.getSupportedLanguages(); 97 String currentLanguage = session.getCurrentLanguage(); 98 for (int i = 0; i < languages.length; i++) { 99 final String language = languages[i]; 100 JRadioButtonMenuItem langItem = new JRadioButtonMenuItem(new AbstractAction(language) { 101 public void actionPerformed(ActionEvent e) { 102 session.setCurrentLanguage(language); 103 } 104 }); 105 if (currentLanguage.equals(language)) langItem.setSelected(true); 106 displayAsPopup.add(langItem); 107 } 108 return displayAsPopup; 109 } 110 } 111 112 private class CustomizeSession extends AbstractAction implements Presenter.Popup { 113 114 private JPDADebugger dbg; 115 116 public CustomizeSession(JPDADebugger dbg) { 117 this.dbg = dbg; 118 } 119 120 public void actionPerformed(ActionEvent e) { 121 } 122 123 public JMenuItem getPopupPresenter() { 124 JMenu displayAsPopup = new JMenu 125 (localize ("CTL_Session_Resume_Threads")); 126 127 JRadioButtonMenuItem resumeAllItem = new JRadioButtonMenuItem ( 128 new AbstractAction (localize ("CTL_Session_Resume_All_Threads") 129 ) { 130 public void actionPerformed (ActionEvent e) { 131 dbg.setSuspend (JPDADebugger.SUSPEND_ALL); 132 } 133 }); 134 JRadioButtonMenuItem resumeCurrentItem = new JRadioButtonMenuItem ( 135 new AbstractAction (localize ("CTL_Session_Resume_Current_Thread") 136 ) { 137 public void actionPerformed(ActionEvent e) { 138 dbg.setSuspend (JPDADebugger.SUSPEND_EVENT_THREAD); 139 } 140 }); 141 142 if (dbg.getSuspend() == JPDADebugger.SUSPEND_ALL) 143 resumeAllItem.setSelected(true); 144 else resumeCurrentItem.setSelected(true); 145 146 displayAsPopup.add(resumeAllItem); 147 displayAsPopup.add(resumeCurrentItem); 148 return displayAsPopup; 149 } 150 } 151 152 public void addModelListener(ModelListener l) { 153 HashSet newListeners = (listeners == null) ? new HashSet() : (HashSet) listeners.clone(); 154 newListeners.add(l); 155 listeners = newListeners; 156 } 157 158 public void removeModelListener(ModelListener l) { 159 if (listeners == null) return; 160 HashSet newListeners = (HashSet) listeners.clone(); 161 newListeners.remove(l); 162 listeners = newListeners; 163 } 164 165 } 166 | Popular Tags |