1 19 20 package org.netbeans.modules.scripting.php.dbginterface.models; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import org.netbeans.modules.scripting.php.dbginterface.ModelSupport; 25 import org.netbeans.modules.scripting.php.dbginterface.api.VariableNode; 26 import org.netbeans.spi.debugger.ContextProvider; 27 import org.netbeans.spi.debugger.ui.Constants; 28 import org.netbeans.spi.viewmodel.ModelEvent; 29 import org.netbeans.spi.viewmodel.NodeModel; 30 import org.netbeans.spi.viewmodel.TableModel; 31 import org.netbeans.spi.viewmodel.TreeModel; 32 import org.netbeans.spi.viewmodel.UnknownTypeException; 33 34 public class VariablesModel extends ModelSupport 35 implements TreeModel, TableModel, NodeModel { 36 37 private final ContextProvider contextProvider; 38 39 private DebugFrame currentFrame; private VariableNode theModel; 41 42 public VariablesModel(final ContextProvider contextProvider) { 43 this.contextProvider = contextProvider; 44 this.theModel = null; 45 } 46 47 public DebugFrame getCurrentFrame() { 48 return currentFrame; 49 } 50 51 public void setStackFrame(DebugFrame newFrame) { 55 if (currentFrame != newFrame) { 56 currentFrame = newFrame; 57 } 58 59 if (theModel == null) { 61 theModel = currentFrame.getScopeVariables(); 62 fireTreeChanged(); 63 } 64 else { 65 Collection <ModelEvent> events = new ArrayList <ModelEvent>(); 66 67 theModel.collectUpdates(this, events, currentFrame.getScopeVariables()); 68 fireTableUpdate(events); 69 } 70 } 71 72 public void clearModel() { 73 theModel = null; 74 fireTreeChanged(); 75 } 76 77 78 public Object getRoot() { 82 return ROOT; } 84 85 public Object [] getChildren(Object parent, int from, int to) throws UnknownTypeException { 86 if (parent == ROOT) { 88 if (theModel == null) { 89 return new Object [0]; 90 } 91 92 return theModel.getChildren(0, theModel.getChildrenCount()); 93 } 94 else if (parent instanceof VariableNode) { 95 return ((VariableNode) parent).getChildren(from, to); 96 } 97 98 throw new UnknownTypeException(parent + " " + parent.getClass().getName()); 99 } 100 101 public boolean isLeaf(Object node) throws UnknownTypeException { 102 if (node == null) { 103 return true; 104 } 105 else if (node == ROOT) { 106 return theModel == null; 107 } 108 else if (node instanceof VariableNode) { 109 return ((VariableNode)node).isLeaf(); 110 } 111 112 throw new UnknownTypeException(node); 113 } 114 115 public int getChildrenCount(Object node) throws UnknownTypeException { 116 if (node == ROOT) { 117 if (theModel == null) { 118 return 0; 119 } 120 121 return theModel.getChildrenCount(); 122 } 123 else if (node instanceof VariableNode) { 124 return ((VariableNode)node).getChildrenCount(); 125 } 126 127 throw new UnknownTypeException(node); 128 } 129 130 public Object getValueAt(Object node, String columnID) throws UnknownTypeException { 134 String result = ""; 136 if (Constants.LOCALS_TYPE_COLUMN_ID.equals(columnID)) { 137 if (node instanceof VariableNode) { 138 String className = ((VariableNode) node).getTypeName(); 139 result = (className == null) ? "" : className; 140 } 141 else { 142 result = (node != null) ? node.getClass().getName() : ""; 143 } 144 } 145 else if (Constants.LOCALS_VALUE_COLUMN_ID.equals(columnID)) { 146 if (node instanceof VariableNode) { 147 VariableNode vn = (VariableNode) node; 148 149 if (vn.isLeaf()) { 150 return vn.getTooltipValue(); 151 } 152 else { 153 return ""; 154 } 155 } 156 else if (node == null) { 157 result = ""; 158 } 159 } 160 161 return result; 162 } 163 164 public boolean isReadOnly(Object node, String string) throws UnknownTypeException { 165 if (node instanceof VariableNode && Constants.LOCALS_VALUE_COLUMN_ID.equals(string)) { 166 return ((VariableNode)node).isReadOnly(); 167 } 168 169 return true; 170 } 171 172 public void setValueAt(Object node, String string, Object value) throws UnknownTypeException { 173 if (!Constants.LOCALS_VALUE_COLUMN_ID.equals(string)) { 174 throw new UnknownTypeException(node); 175 } 176 177 if (!(node instanceof VariableNode)) { 178 throw new UnknownTypeException(node); 179 } 180 181 VariableNode v = (VariableNode)node; 182 183 if (v.isReadOnly()) { 184 throw new UnknownTypeException(node); 185 } 186 187 currentFrame.setVariableValue(v, value); 188 } 189 190 public String getDisplayName(Object node) throws UnknownTypeException { 194 if(node == null) { 195 return "null"; 196 } else if(node == ROOT) { 197 return ROOT; 198 } else if(node instanceof VariableNode) { 199 return ((VariableNode) node).getDisplayName(); 200 } 201 throw new UnknownTypeException(node); 202 } 203 204 public String getIconBase(Object node) throws UnknownTypeException { 205 if(node == null || node == ROOT) { 206 return VariableNode.LOCAL_VARIABLE_ICON; 207 } else if(node instanceof VariableNode) { 208 return ((VariableNode) node).getIconBase(); 209 } 210 throw new UnknownTypeException(node); 211 } 212 213 public String getShortDescription(Object node) throws UnknownTypeException { 214 if(node == null || node == ROOT) { 215 return null; 216 } else if(node instanceof VariableNode) { 217 return ((VariableNode) node).getShortDescription(); 218 } 219 throw new UnknownTypeException(node); 220 } 221 222 223 227 public void fireTreeChanged() { 228 refresh(true); 229 } 230 231 private void fireTableUpdate(Collection <ModelEvent> events) { 232 fireChangeEvents(events); 233 } 234 } 235 | Popular Tags |