1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import java.util.Vector ; 23 import org.netbeans.api.debugger.jpda.JPDAThread; 24 import org.netbeans.api.debugger.jpda.JPDAThreadGroup; 25 import org.netbeans.spi.debugger.ui.Constants; 26 import org.netbeans.spi.viewmodel.ModelEvent; 27 import org.netbeans.spi.viewmodel.TableModel; 28 import org.netbeans.spi.viewmodel.ModelListener; 29 import org.netbeans.spi.viewmodel.UnknownTypeException; 30 import org.openide.ErrorManager; 31 import org.openide.util.NbBundle; 32 33 34 35 39 public class ThreadsTableModel implements TableModel, Constants { 40 41 private Vector listeners = new Vector (); 42 43 44 public Object getValueAt (Object row, String columnID) throws 45 UnknownTypeException { 46 if (row instanceof MonitorModel.ThreadWithBordel) 50 row = ((MonitorModel.ThreadWithBordel) row).originalThread; 51 if (row instanceof JPDAThreadGroup) { 52 if (THREAD_STATE_COLUMN_ID.equals (columnID)) 53 return ""; 54 if (THREAD_SUSPENDED_COLUMN_ID.equals (columnID)) { 55 JPDAThreadGroup group = (JPDAThreadGroup) row; 56 JPDAThread[] threads = group.getThreads (); 57 if (threads.length < 1) return Boolean.FALSE; 58 return Boolean.valueOf (threads [0].isSuspended ()); 59 } 60 } 61 if (row instanceof JPDAThread) { 62 if (THREAD_STATE_COLUMN_ID.equals (columnID)) { 63 String description = getThreadStateDescription(((JPDAThread) row).getState ()); 64 if (description != null) { 65 return description; 66 } 67 } else 68 if (THREAD_SUSPENDED_COLUMN_ID.equals (columnID)) 69 return Boolean.valueOf (((JPDAThread) row).isSuspended ()); 70 } 71 throw new UnknownTypeException (row); 72 } 73 74 private static String getThreadStateDescription(int state) { 75 switch (state) { 76 case JPDAThread.STATE_MONITOR: 77 return NbBundle.getMessage ( 78 ThreadsTableModel.class, 79 "CTL_Thread_State_OnMonitor" 80 ); 81 case JPDAThread.STATE_NOT_STARTED: 82 return NbBundle.getMessage ( 83 ThreadsTableModel.class, 84 "CTL_Thread_State_NotStarted" 85 ); 86 case JPDAThread.STATE_RUNNING: 87 return NbBundle.getMessage ( 88 ThreadsTableModel.class, 89 "CTL_Thread_State_Running" 90 ); 91 case JPDAThread.STATE_SLEEPING: 92 return NbBundle.getMessage ( 93 ThreadsTableModel.class, 94 "CTL_Thread_State_Sleeping" 95 ); 96 case JPDAThread.STATE_UNKNOWN: 97 return NbBundle.getMessage ( 98 ThreadsTableModel.class, 99 "CTL_Thread_State_Unknown" 100 ); 101 case JPDAThread.STATE_WAIT: 102 return NbBundle.getMessage ( 103 ThreadsTableModel.class, 104 "CTL_Thread_State_Waiting" 105 ); 106 case JPDAThread.STATE_ZOMBIE: 107 return NbBundle.getMessage ( 108 ThreadsTableModel.class, 109 "CTL_Thread_State_Zombie" 110 ); 111 default: ErrorManager.getDefault().log(ErrorManager.WARNING, "Unknown thread state: "+state); 112 return null; 113 } 114 } 115 116 public boolean isReadOnly (Object row, String columnID) throws 117 UnknownTypeException { 118 if (row instanceof MonitorModel.ThreadWithBordel) 119 row = ((MonitorModel.ThreadWithBordel) row).originalThread; 120 if (row instanceof JPDAThreadGroup) { 121 if (THREAD_STATE_COLUMN_ID.equals (columnID)) 122 return true; 123 if (THREAD_SUSPENDED_COLUMN_ID.equals (columnID)) 124 return false; 125 } 126 if (row instanceof JPDAThread) { 127 if (THREAD_STATE_COLUMN_ID.equals (columnID)) 128 return true; 129 else 130 if (THREAD_SUSPENDED_COLUMN_ID.equals (columnID)) 131 return false; 132 } 133 throw new UnknownTypeException (row); 134 } 135 136 public void setValueAt (Object row, String columnID, Object value) 137 throws UnknownTypeException { 138 if (row instanceof MonitorModel.ThreadWithBordel) 139 row = ((MonitorModel.ThreadWithBordel) row).originalThread; 140 if (row instanceof JPDAThreadGroup) { 141 if (THREAD_SUSPENDED_COLUMN_ID.equals (columnID)) { 142 if (((Boolean ) value).booleanValue ()) 143 ((JPDAThreadGroup) row).suspend (); 144 else 145 ((JPDAThreadGroup) row).resume (); 146 fireTableValueChanged (row, Constants.THREAD_SUSPENDED_COLUMN_ID); 147 return; 148 } 149 } 150 if (row instanceof JPDAThread) { 151 if (THREAD_SUSPENDED_COLUMN_ID.equals (columnID)) { 152 if (value.equals (Boolean.TRUE)) 153 ((JPDAThread) row).suspend (); 154 else 155 ((JPDAThread) row).resume (); 156 fireTableValueChanged (row, Constants.THREAD_SUSPENDED_COLUMN_ID); 157 return; 158 } 159 } 160 throw new UnknownTypeException (row); 161 } 162 163 168 public void addModelListener (ModelListener l) { 169 listeners.add (l); 170 } 171 172 177 public void removeModelListener (ModelListener l) { 178 listeners.remove (l); 179 } 180 181 private void fireTableValueChanged (Object o, String propertyName) { 182 Vector v = (Vector ) listeners.clone (); 183 int i, k = v.size (); 184 for (i = 0; i < k; i++) 185 ((ModelListener) v.get (i)).modelChanged ( 186 new ModelEvent.TableValueChanged (this, o, propertyName) 187 ); 188 } 189 } 190 | Popular Tags |