1 19 20 package org.netbeans.modules.scripting.php.dbginterface.models; 21 22 import javax.swing.Action ; 23 import org.netbeans.modules.scripting.php.dbginterface.DbgDebuggerImpl; 24 import org.netbeans.modules.scripting.php.dbginterface.ModelSupport; 25 import org.netbeans.spi.debugger.ContextProvider; 26 import org.netbeans.spi.viewmodel.ModelEvent; 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.util.NbBundle; 34 35 39 public class ThreadsModel extends ModelSupport 40 implements TreeModel, NodeModel, NodeActionsProvider, TableModel { 41 42 private static final boolean DEBUG = false; 43 44 public static final String CURRENT = 45 "org/netbeans/modules/debugger/resources/threadsView/CurrentThread"; public static final String RUNNING = 47 "org/netbeans/modules/debugger/resources/threadsView/RunningThread"; public static final String SUSPENDED = 49 "org/netbeans/modules/debugger/resources/threadsView/SuspendedThread"; 51 public ThreadsModel(ContextProvider contextProvider) { 52 this.contextProvider = contextProvider; 53 } 54 55 private ContextProvider contextProvider; 56 57 private ContextProvider getContextProvider() { 58 return contextProvider; 59 } 60 61 private DbgDebuggerImpl getDebugger() { 62 return (DbgDebuggerImpl)contextProvider.lookupFirst(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) { 75 return getDebugger().getScriptContexts(); 76 } 77 78 throw new UnknownTypeException(parent); 79 } 80 81 public boolean isLeaf(Object node) throws UnknownTypeException { 82 if (node == ROOT) { 84 return false; 85 } 86 else if (node instanceof DbgDebuggerImpl.Context) { 87 return true; 88 } 89 90 throw new UnknownTypeException(node); 91 } 92 93 public int getChildrenCount(Object node) throws UnknownTypeException { 94 if (node == ROOT) { 96 return getDebugger().getScriptContexts().length; 97 } 98 throw new UnknownTypeException(node); 99 } 100 101 public String getDisplayName(Object node) throws UnknownTypeException { 105 if (node instanceof DbgDebuggerImpl.Context) { 107 DbgDebuggerImpl.Context context = (DbgDebuggerImpl.Context) node; 108 String contextName = context.toString(); 109 String debuggerName = context.getServer().toString(); 110 111 return NbBundle.getMessage(ThreadsModel.class, "LBL_ThreadName", contextName, debuggerName); } 113 else if (node == ROOT) { 114 return ROOT.toString(); 115 } 116 117 throw new UnknownTypeException(node); 118 } 119 120 public String getIconBase(Object node) throws UnknownTypeException { 121 if (node instanceof DbgDebuggerImpl.Context) { 123 if (((DbgDebuggerImpl.Context)node).isSuspended()) { 124 return SUSPENDED; 125 } 126 else if (((DbgDebuggerImpl.Context)node).isCurrent()) { 127 return CURRENT; 128 } 129 else { 130 return RUNNING; 131 } 132 } 133 else if (node == ROOT) { 134 return null; 135 } 136 137 throw new UnknownTypeException(node); 138 } 139 140 public String getShortDescription(Object node) throws UnknownTypeException { 141 if (node == ROOT) { 143 return null; 144 } 145 else if (node instanceof DbgDebuggerImpl.Context) { 146 return null; 147 } 148 throw new UnknownTypeException(node); 149 } 150 151 public void performDefaultAction(Object node) throws UnknownTypeException { 155 if (node instanceof DbgDebuggerImpl.Context) { 157 DbgDebuggerImpl.Context context = (DbgDebuggerImpl.Context) node; 158 159 if (!context.isCurrent()) { 160 getDebugger().setCurrentScriptContext(context); 161 refresh(false); 162 } 163 } 164 165 throw new UnknownTypeException(node); 166 } 167 168 public Action [] getActions(Object node) throws UnknownTypeException { 169 return new Action [] {}; 170 } 171 172 public Object getValueAt(Object node, String columnID) throws UnknownTypeException { 176 if (node == ROOT) { 178 return null; 179 } 180 181 if (node instanceof DbgDebuggerImpl.Context) { 182 DbgDebuggerImpl.Context context = (DbgDebuggerImpl.Context)node; 183 184 if (columnID == Constants.THREAD_SUSPENDED_COLUMN_ID) { 185 return context.isSuspended(); 186 } 187 else if (columnID == Constants.THREAD_STATE_COLUMN_ID) { 188 String result = NbBundle.getMessage(ThreadsModel.class, 189 (context.isCurrent() ? "LBL_ActiveThreadState" : "LBL_InactiveThreadState"), NbBundle.getMessage(ThreadsModel.class, 191 (context.isSuspended() ? "LBL_Suspended" : "LBL_Running"))); return result; 193 } 194 } 195 196 throw new UnknownTypeException(node); 197 } 198 199 public boolean isReadOnly(Object node, String columnID) throws UnknownTypeException { 200 if (node == ROOT) { 202 return true; 203 } 204 else if (node instanceof DbgDebuggerImpl.Context) { 205 return true; 206 } 207 208 throw new UnknownTypeException(node); 210 } 211 212 public void setValueAt(Object node, String columnID, Object value) throws UnknownTypeException { 213 throw new UnknownTypeException(node); 215 } 216 217 218 222 public void updateThreadState(DbgDebuggerImpl.Context context) { 223 225 fireChangeEvent(new ModelEvent.NodeChanged(this, context)); 226 } 227 228 public void updateThreadState(DbgDebuggerImpl.Context[] context) { 229 231 ModelEvent[] events = new ModelEvent[context.length]; 232 233 for(int i = 0; i < context.length; i++) { 234 events[i] = new ModelEvent.NodeChanged(this, context[i]); 235 } 236 fireChangeEvents(events); 237 } 238 } 239 | Popular Tags |