1 19 20 package org.netbeans.modules.debugger.jpda.ui.models; 21 22 import com.sun.jdi.AbsentInformationException; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.lang.ref.WeakReference ; 26 import java.util.List ; 27 import java.util.Vector ; 28 29 import org.netbeans.api.debugger.DebuggerEngine; 30 import org.netbeans.spi.debugger.ContextProvider; 31 import org.netbeans.api.debugger.Session; 32 import org.netbeans.api.debugger.jpda.CallStackFrame; 33 import org.netbeans.api.debugger.jpda.JPDADebugger; 34 import org.netbeans.spi.viewmodel.ModelEvent; 35 import org.netbeans.spi.viewmodel.NodeModel; 36 import org.netbeans.spi.viewmodel.TreeModel; 37 import org.netbeans.spi.viewmodel.ModelListener; 38 import org.netbeans.spi.viewmodel.UnknownTypeException; 39 import org.openide.util.NbBundle; 40 41 42 45 public class CallStackNodeModel implements NodeModel { 46 47 public static final String CALL_STACK = 48 "org/netbeans/modules/debugger/resources/callStackView/NonCurrentFrame"; 49 public static final String CURRENT_CALL_STACK = 50 "org/netbeans/modules/debugger/resources/callStackView/CurrentFrame"; 51 52 private JPDADebugger debugger; 53 private Session session; 54 private Vector listeners = new Vector (); 55 56 57 public CallStackNodeModel (ContextProvider lookupProvider) { 58 debugger = (JPDADebugger) lookupProvider. 59 lookupFirst (null, JPDADebugger.class); 60 session = (Session) lookupProvider. 61 lookupFirst (null, Session.class); 62 new Listener (this, debugger); 63 } 64 65 public String getDisplayName (Object o) throws UnknownTypeException { 66 if (o == TreeModel.ROOT) { 67 return NbBundle.getBundle (CallStackNodeModel.class).getString 68 ("CTL_CallstackModel_Column_Name_Name"); 69 } else 70 if (o instanceof CallStackFrame) { 71 CallStackFrame sf = (CallStackFrame) o; 72 CallStackFrame ccsf = debugger.getCurrentCallStackFrame (); 73 if ( (ccsf != null) && 74 (ccsf.equals (sf)) 75 ) 76 return BoldVariablesTableModelFilterFirst.toHTML ( 77 getCSFName (session, sf, false), 78 true, 79 false, 80 null 81 ); 82 return getCSFName (session, sf, false); 83 } else if ("No current thread" == o) { 84 return NbBundle.getMessage(CallStackNodeModel.class, "NoCurrentThread"); 85 } else if ("Thread is running" == o) { 86 return NbBundle.getMessage(CallStackNodeModel.class, "ThreadIsRunning"); 87 } else 88 throw new UnknownTypeException (o); 89 } 90 91 public String getShortDescription (Object o) throws UnknownTypeException { 92 if (o == TreeModel.ROOT) { 93 return NbBundle.getBundle (CallStackNodeModel.class).getString 94 ("CTL_CallstackModel_Column_Name_Desc"); 95 } else 96 if (o instanceof CallStackFrame) { 97 CallStackFrame sf = (CallStackFrame) o; 98 return getCSFName (session, sf, true); 99 } else if ("No current thread" == o) { 100 return NbBundle.getMessage(CallStackNodeModel.class, "NoCurrentThread"); 101 } else if ("Thread is running" == o) { 102 return NbBundle.getMessage(CallStackNodeModel.class, "ThreadIsRunning"); 103 } else 104 throw new UnknownTypeException (o); 105 } 106 107 public String getIconBase (Object node) throws UnknownTypeException { 108 if (node instanceof String ) return null; 109 if (node instanceof CallStackFrame) { 110 CallStackFrame ccsf = debugger.getCurrentCallStackFrame (); 111 if ( (ccsf != null) && 112 (ccsf.equals (node)) 113 ) return CURRENT_CALL_STACK; 114 return CALL_STACK; 115 } 116 throw new UnknownTypeException (node); 117 } 118 119 123 public void addModelListener (ModelListener l) { 124 listeners.add (l); 125 } 126 127 131 public void removeModelListener (ModelListener l) { 132 listeners.remove (l); 133 } 134 135 private void fireNodeChanged(Object node) { 136 Vector v = (Vector ) listeners.clone (); 137 int k = v.size (); 138 if (k == 0) return ; 139 ModelEvent.NodeChanged nodeChangedEvent = new ModelEvent.NodeChanged(this, node); 140 for (int i = 0; i < k; i++) { 141 ((ModelListener) v.get (i)).modelChanged (nodeChangedEvent); 142 } 143 } 144 145 public static String getCSFName ( 146 Session s, 147 CallStackFrame sf, 148 boolean l 149 ) { 150 String language = sf.getDefaultStratum (); 151 int ln = sf.getLineNumber (language); 152 String fileName = l ? 153 sf.getClassName () : 154 BreakpointsNodeModel.getShort (sf.getClassName ()); 155 if ("Java".equals (language)) 156 fileName += "." + sf.getMethodName (); 157 else 158 try { 159 fileName = sf.getSourcePath (language); 160 } catch (AbsentInformationException e) { 161 fileName += "." + sf.getMethodName (); 162 } 163 if (ln < 0) 164 return fileName; 165 return fileName + ":" + ln; 166 } 167 168 169 171 175 private static class Listener implements PropertyChangeListener { 176 177 private WeakReference ref; 178 private JPDADebugger debugger; 179 180 private Listener ( 181 CallStackNodeModel rm, 182 JPDADebugger debugger 183 ) { 184 ref = new WeakReference (rm); 185 this.debugger = debugger; 186 debugger.addPropertyChangeListener ( 187 debugger.PROP_CURRENT_CALL_STACK_FRAME, 188 this 189 ); 190 } 191 192 private CallStackNodeModel getModel () { 193 CallStackNodeModel rm = (CallStackNodeModel) ref.get (); 194 if (rm == null) { 195 debugger.removePropertyChangeListener ( 196 debugger.PROP_CURRENT_CALL_STACK_FRAME, 197 this 198 ); 199 } 200 return rm; 201 } 202 203 public void propertyChange (PropertyChangeEvent e) { 204 CallStackNodeModel rm = getModel (); 205 if (rm == null) return; 206 rm.fireNodeChanged(e.getOldValue()); 207 rm.fireNodeChanged(e.getNewValue()); 208 } 209 } 210 } 211 | Popular Tags |