1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import java.util.WeakHashMap ; 23 import javax.security.auth.Refreshable ; 24 import org.netbeans.api.debugger.jpda.Field; 25 import org.netbeans.api.debugger.jpda.InvalidExpressionException; 26 import org.netbeans.api.debugger.jpda.JPDAClassType; 27 import org.netbeans.api.debugger.jpda.JPDADebugger; 28 import org.netbeans.api.debugger.jpda.JPDAWatch; 29 import org.netbeans.api.debugger.jpda.LocalVariable; 30 import org.netbeans.api.debugger.jpda.ObjectVariable; 31 import org.netbeans.api.debugger.jpda.Super; 32 import org.netbeans.api.debugger.jpda.This; 33 import org.netbeans.api.debugger.jpda.Variable; 34 import org.netbeans.spi.debugger.ContextProvider; 35 import org.netbeans.spi.debugger.ui.Constants; 36 import org.netbeans.spi.viewmodel.TableModel; 37 import org.netbeans.spi.viewmodel.ModelListener; 38 import org.netbeans.spi.viewmodel.UnknownTypeException; 39 import org.openide.DialogDisplayer; 40 import org.openide.NotifyDescriptor; 41 import org.openide.util.NbBundle; 42 43 44 48 public class VariablesTableModel implements TableModel, Constants { 49 50 private JPDADebugger debugger; 51 52 public VariablesTableModel(ContextProvider contextProvider) { 53 debugger = (JPDADebugger) contextProvider.lookupFirst(null, JPDADebugger.class); 54 } 55 56 public Object getValueAt (Object row, String columnID) throws 57 UnknownTypeException { 58 59 if ( LOCALS_TO_STRING_COLUMN_ID.equals (columnID) || 60 WATCH_TO_STRING_COLUMN_ID.equals (columnID) 61 ) { 62 if (row instanceof Super) 63 return ""; 64 else 65 66 if (row instanceof ObjectVariable) 67 try { 68 return ((ObjectVariable) row).getToStringValue (); 69 } catch (InvalidExpressionException ex) { 70 return getMessage (ex); 71 } 72 else 73 if (row instanceof Variable) 74 return ((Variable) row).getValue (); 75 if (row == "lastOperations") { return ""; } 78 } else 79 if ( LOCALS_TYPE_COLUMN_ID.equals (columnID) || 80 WATCH_TYPE_COLUMN_ID.equals (columnID) 81 ) { 82 if (row instanceof Variable) 83 return getShort (((Variable) row).getType ()); 84 if (row instanceof javax.swing.JToolTip ) { 85 row = ((javax.swing.JToolTip ) row).getClientProperty("getShortDescription"); 86 if (row instanceof Variable) { 87 if (row instanceof Refreshable && !((Refreshable ) row).isCurrent()) { 88 return ""; 89 } 90 return ((Variable) row).getType(); 91 } 92 } 93 } else 94 if ( LOCALS_VALUE_COLUMN_ID.equals (columnID) || 95 WATCH_VALUE_COLUMN_ID.equals (columnID) 96 ) { 97 if (row instanceof JPDAWatch) { 98 JPDAWatch w = (JPDAWatch) row; 99 String e = w.getExceptionDescription (); 100 if (e != null) 101 return ">" + e + "<"; 102 return w.getValue (); 103 } else 104 if (row instanceof Variable) 105 return ((Variable) row).getValue (); 106 } 107 if (row instanceof JPDAClassType) { 108 return ""; } 110 if (row.toString().startsWith("SubArray")) { return ""; } 113 if (row == "lastOperations") { return ""; } 116 throw new UnknownTypeException (row); 117 } 118 119 public boolean isReadOnly (Object row, String columnID) throws 120 UnknownTypeException { 121 if (row instanceof Variable) { 122 if ( LOCALS_TO_STRING_COLUMN_ID.equals (columnID) || 123 WATCH_TO_STRING_COLUMN_ID.equals (columnID) || 124 LOCALS_TYPE_COLUMN_ID.equals (columnID) || 125 WATCH_TYPE_COLUMN_ID.equals (columnID) 126 ) return true; 127 if ( LOCALS_VALUE_COLUMN_ID.equals (columnID) || 128 WATCH_VALUE_COLUMN_ID.equals (columnID) 129 ) { 130 if (row instanceof This) 131 return true; 132 else 133 if ( row instanceof LocalVariable || 134 row instanceof Field || 135 row instanceof JPDAWatch 136 ) 137 return !debugger.canBeModified(); 138 else 139 return true; 140 } 141 } 142 if (row instanceof JPDAClassType) { 143 return true; 144 } 145 if (row.toString().startsWith("SubArray")) { 146 return true; 147 } 148 throw new UnknownTypeException (row); 149 } 150 151 public void setValueAt (Object row, String columnID, Object value) 152 throws UnknownTypeException { 153 if (row instanceof LocalVariable) { 154 if (LOCALS_VALUE_COLUMN_ID.equals (columnID)) { 155 try { 156 ((LocalVariable) row).setValue ((String ) value); 157 } catch (InvalidExpressionException e) { 158 NotifyDescriptor.Message descriptor = 159 new NotifyDescriptor.Message ( 160 e.getLocalizedMessage (), 161 NotifyDescriptor.WARNING_MESSAGE 162 ); 163 DialogDisplayer.getDefault ().notify (descriptor); 164 } 165 return; 166 } 167 } 168 if (row instanceof Field) { 169 if ( LOCALS_VALUE_COLUMN_ID.equals (columnID) || 170 WATCH_VALUE_COLUMN_ID.equals (columnID) 171 ) { 172 try { 173 ((Field) row).setValue ((String ) value); 174 } catch (InvalidExpressionException e) { 175 NotifyDescriptor.Message descriptor = 176 new NotifyDescriptor.Message ( 177 e.getLocalizedMessage (), 178 NotifyDescriptor.WARNING_MESSAGE 179 ); 180 DialogDisplayer.getDefault ().notify (descriptor); 181 } 182 return; 183 } 184 } 185 if (row instanceof JPDAWatch) { 186 if ( LOCALS_VALUE_COLUMN_ID.equals (columnID) || 187 WATCH_VALUE_COLUMN_ID.equals (columnID) 188 ) { 189 try { 190 ((JPDAWatch) row).setValue ((String ) value); 191 } catch (InvalidExpressionException e) { 192 NotifyDescriptor.Message descriptor = 193 new NotifyDescriptor.Message ( 194 e.getLocalizedMessage (), 195 NotifyDescriptor.WARNING_MESSAGE 196 ); 197 DialogDisplayer.getDefault ().notify (descriptor); 198 } 199 return; 200 } 201 } 202 throw new UnknownTypeException (row); 203 } 204 205 210 public void addModelListener (ModelListener l) { 211 } 212 213 218 public void removeModelListener (ModelListener l) { 219 } 220 221 static String getShort (String c) { 222 int i = c.lastIndexOf ('.'); 223 if (i < 0) return c; 224 return c.substring (i + 1); 225 } 226 227 private static String getMessage (InvalidExpressionException e) { 228 String m = e.getLocalizedMessage (); 229 if (m == null) { 230 m = e.getMessage (); 231 } 232 if (m == null) { 233 m = NbBundle.getMessage(VariablesTableModel.class, "MSG_NA"); 234 } 235 return ">" + m + "<"; 236 } 237 } 238 | Popular Tags |