1 19 20 package org.netbeans.modules.scripting.php.dbginterface.models; 21 22 import java.util.List ; 23 import javax.swing.Action ; 24 import org.netbeans.modules.scripting.php.dbginterface.DbgDebuggerImpl; 25 import org.netbeans.modules.scripting.php.dbginterface.ModelSupport; 26 import org.netbeans.spi.debugger.ContextProvider; 27 import org.netbeans.spi.viewmodel.NodeActionsProvider; 28 import org.netbeans.spi.viewmodel.NodeModel; 29 import org.netbeans.spi.viewmodel.TableModel; 30 import org.netbeans.spi.viewmodel.TreeModel; 31 import org.netbeans.spi.viewmodel.UnknownTypeException; 32 import org.netbeans.spi.debugger.ui.Constants; 33 import org.openide.text.Line; 34 import org.openide.util.Mutex; 35 36 40 public class CallStackModel extends ModelSupport 41 implements TreeModel, NodeModel, NodeActionsProvider, TableModel { 42 43 private static final boolean DEBUG = false; 44 45 public static final String CALL_STACK = 46 "org/netbeans/modules/debugger/resources/callStackView/NonCurrentFrame"; 47 public static final String CURRENT_CALL_STACK = 48 "org/netbeans/modules/debugger/resources/callStackView/CurrentFrame"; 49 50 public CallStackModel(final ContextProvider contextProvider) { 51 this.contextProvider = contextProvider; 52 } 53 54 private final ContextProvider contextProvider; 55 56 private ContextProvider getContextProvider() { 57 return contextProvider; 58 } 59 60 private DbgDebuggerImpl getDebugger() { 61 return (DbgDebuggerImpl)contextProvider.lookupFirst( 62 null, DbgDebuggerImpl.class); 63 } 64 65 public Object getRoot() { 69 return ROOT; 70 } 71 72 public Object [] getChildren(Object parent, int from, int to) throws UnknownTypeException { 73 if (parent == ROOT) { 74 DbgDebuggerImpl.Context context = getDebugger().getCurrentScriptContext(); 75 76 if (context != null) { 77 List <DebugFrame> callstack = context.getCallStack(); 78 79 if (callstack != null) { 80 return callstack.toArray(new DebugFrame[callstack.size()]); 81 } 82 } 83 84 return new DebugFrame[0]; 85 } 86 87 throw new UnknownTypeException(parent); 88 } 89 90 public boolean isLeaf(Object node) throws UnknownTypeException { 91 if (node == ROOT) { 92 return false; 93 } 94 else if (node instanceof DebugFrame) { 95 return true; 96 } 97 98 throw new UnknownTypeException(node); 99 } 100 101 public int getChildrenCount(Object node) throws UnknownTypeException { 102 if (node == ROOT) { 103 DbgDebuggerImpl.Context context = getDebugger().getCurrentScriptContext(); 104 105 if (context != null && context.getCallStack() != null) { 106 return context.getCallStack().size(); 107 } 108 else { 109 return 0; 110 } 111 } 112 113 throw new UnknownTypeException(node); 114 } 115 116 public String getDisplayName(Object node) throws UnknownTypeException { 120 if (node instanceof DebugFrame) { 121 DebugFrame frame = (DebugFrame)node; 122 123 System.err.println("mw CallStackModel.getDisplayName(" + frame + ")"); 124 125 return frame.getDisplayName(); 126 } 127 else if (node == ROOT) { 128 return ROOT.toString(); 129 } 130 131 throw new UnknownTypeException(node); 132 } 133 134 public String getIconBase(Object node) throws UnknownTypeException { 135 if (node instanceof DebugFrame) { 136 DbgDebuggerImpl.Context context = getDebugger().getCurrentScriptContext(); 137 138 if(context != null && context.getCallStack().get(0) == node) { 139 return CURRENT_CALL_STACK; 140 } 141 else { 142 return CALL_STACK; 143 } 144 } 145 else if (node == ROOT) { 146 return null; 147 } 148 149 throw new UnknownTypeException (node); 150 } 151 152 public String getShortDescription(Object node) throws UnknownTypeException { 153 if(node == ROOT) { 154 return null; 155 } 156 else if (node instanceof DebugFrame) { 157 return null; 158 } 159 160 throw new UnknownTypeException (node); 161 } 162 163 public void performDefaultAction(Object node) throws UnknownTypeException { 167 if (node instanceof DebugFrame) { 168 DebugFrame frame = (DebugFrame)node; 169 170 DbgDebuggerImpl debugger = getDebugger(); 172 debugger.getWatchesModel().setStackFrame(frame); 173 debugger.getVariablesModel().setStackFrame(frame); 174 175 final Line line = frame.getLine(); 177 178 if (line != null) { 179 Mutex.EVENT.readAccess(new Runnable () { 180 public void run () { 181 line.show(Line.SHOW_GOTO); 182 } 183 }); 184 } 185 } 186 throw new UnknownTypeException (node); 187 } 188 189 public Action [] getActions (Object node) throws UnknownTypeException { 190 return new Action [] {}; 191 } 192 193 public Object getValueAt(Object node, String columnID) throws UnknownTypeException { 197 if(node == ROOT) { 198 return null; 199 } 200 else if (node instanceof DebugFrame) { 201 if (columnID == Constants.CALL_STACK_FRAME_LOCATION_COLUMN_ID) { 202 DebugFrame frame = (DebugFrame)node; 203 204 return frame.getSourceFile() + ":" + frame.getLineNumber(); 205 } 206 else { 207 return "?! unknown column"; 208 } 209 } 210 211 throw new UnknownTypeException (node); 212 } 213 214 public boolean isReadOnly(Object node, String columnID) throws UnknownTypeException { 215 if(node == ROOT) { 216 return true; 217 } 218 else if (node instanceof DebugFrame) { 219 return true; 220 } 221 222 throw new UnknownTypeException (node); 223 } 224 225 public void setValueAt(Object node, String columnID, Object value) throws UnknownTypeException { 226 throw new UnknownTypeException(node); 227 } 228 } 229 | Popular Tags |