001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License. You can obtain a copy of the License at
005: * http://www.netbeans.org/cddl.html or http://www.netbeans.org/cddl.txt. When
006: * distributing Covered Code, include this CDDL Header Notice in each file and
007: * include the License file at http://www.netbeans.org/cddl.txt. If applicable,
008: * add the following below the CDDL Header, with the fields enclosed by brackets []
009: * replaced by your own identifying information: "Portions Copyrighted [year]
010: * [name of copyright owner]" The Original Software is NetBeans. The Initial
011: * Developer of the Original Software is Sun Microsystems, Inc. Portions
012: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
013: */
014: package org.netbeans.modules.php.dbgp.models.nodes;
015:
016: import java.util.ArrayList;
017: import java.util.List;
018: import java.util.Set;
019:
020: import org.netbeans.api.debugger.Watch;
021: import org.netbeans.modules.php.dbgp.DebugSession;
022: import org.netbeans.modules.php.dbgp.StartActionProviderImpl;
023: import org.netbeans.modules.php.dbgp.api.ModelNode;
024: import org.netbeans.modules.php.dbgp.api.SessionId;
025: import org.netbeans.modules.php.dbgp.api.UnsufficientValueException;
026: import org.netbeans.modules.php.dbgp.models.VariablesModelFilter.FilterType;
027: import org.netbeans.modules.php.dbgp.packets.EvalCommand;
028: import org.netbeans.modules.php.dbgp.packets.Property;
029: import org.netbeans.spi.debugger.ContextProvider;
030:
031: public class ScriptWatchEvaluating extends AbstractModelNode implements
032: ModelNode {
033:
034: private static final String WATCH_ICON = "org/netbeans/modules/debugger/resources/watchesView/Watch"; // NOI18N
035:
036: protected ScriptWatchEvaluating(ContextProvider provider,
037: Watch watch) {
038: super (null, null);
039: myWatch = watch;
040: myProvider = provider;
041: requestValue();
042: }
043:
044: public synchronized String getExpression() {
045: return myWatch.getExpression();
046: }
047:
048: public synchronized void remove() {
049: myWatch.remove();
050: }
051:
052: public synchronized void setExpression(String expression) {
053: myWatch.setExpression(expression);
054: requestValue();
055: }
056:
057: public String getName() {
058: return myWatch.getExpression();
059: }
060:
061: public String getDisplayName() {
062: return myWatch.getExpression();
063: }
064:
065: public String getShortDescription() {
066: return myWatch.getExpression();
067: }
068:
069: public String getIconBase() {
070: return WATCH_ICON;
071: }
072:
073: public synchronized String getType() {
074: if (myValue == null) {
075: return null;
076: }
077: return myValue.getType();
078: }
079:
080: public synchronized String getValue()
081: throws UnsufficientValueException {
082: if (myValue == null) {
083: return null;
084: }
085: return myValue.getStringValue();
086: }
087:
088: public VariableNode[] getChildren(int from, int to) {
089: List<AbstractModelNode> list;
090: synchronized (this ) {
091: if (getVariables() == null) {
092: list = new ArrayList<AbstractModelNode>();
093: } else {
094: list = new ArrayList<AbstractModelNode>(getVariables());
095: }
096: }
097: if (from >= list.size()) {
098: return new VariableNode[0];
099: }
100: int end = Math.min(to, list.size());
101: list = list.subList(from, end);
102: return list.toArray(new VariableNode[list.size()]);
103: }
104:
105: /* (non-Javadoc)
106: * @see org.netbeans.modules.php.dbgp.api.ModelNode#isLeaf()
107: */
108: public boolean isLeaf() {
109: return getChildrenSize() == 0;
110: }
111:
112: public boolean isReadOnly() {
113: /*
114: * Theoretically one could perfrom in Eval command response send
115: * PropertyGet command with expression as name.
116: * In case of appropraite answer one can allow edit such node
117: * ( via PropertySet command ) by its full name.
118: * But there are complexity in
119: * 1) each time one need to each watch request property via PropertyGet
120: * 2) for each child node one needs to build full name manually.
121: *
122: * For this time I disallow to edit values in watches view.
123: */
124: return true;
125: }
126:
127: /*
128: * (non-Javadoc)
129: *
130: * @see org.netbeans.modules.php.dbgp.api.ModelNode#getChildrenSize()
131: */
132: public synchronized int getChildrenSize() {
133: return getVariables() == null ? 0 : getVariables().size();
134: }
135:
136: /**
137: * Method intended for call only by WatchesModel.
138: * WatchesModel is responsible for update this node value when debugger
139: * response with value.
140: * This is done in async way.
141: */
142: protected synchronized void setEvaluated(Property value) {
143: myValue = value;
144: if (value != null) {
145: initVariables(value.getChildren());
146: }
147: }
148:
149: protected void requestValue() {
150: setEvaluated(null);
151: DebugSession session = getSession();
152: if (session == null) {
153: return;
154: }
155: EvalCommand command = new EvalCommand(session
156: .getTransactionId());
157: command.setData(getExpression());
158: /* TODO : uncomment later.
159: * I found a bug in XDEbug with eval command:
160: * after response to eval request it performs two actions:
161: * 1) Stops script execution ( and debugging ) unexpectedly
162: * 2) Response with unexpected "response" packet that don't contain
163: * "command" attribute with "status" attribute equals to "stopped"
164: * and "reason" equals "ok".
165: * Need to investigate this more deeply and file a bug on XDebug.
166: *
167: * XDebug bug submitted:
168: * http://bugs.xdebug.org/bug_view_page.php?bug_id=0000313
169: *
170: * session.sendCommandLater(command);
171: */
172: }
173:
174: protected boolean isTypeApplied(Set<FilterType> set) {
175: return true;
176: }
177:
178: private SessionId getSessionId() {
179: if (myProvider == null) {
180: return null;
181: }
182: SessionId id = (SessionId) myProvider.lookupFirst(null,
183: SessionId.class);
184: if (id == null) {
185: return null;
186: }
187: return id;
188: }
189:
190: private DebugSession getSession() {
191: return StartActionProviderImpl.getInstance().getCurrentSession(
192: getSessionId());
193: }
194:
195: private Watch myWatch;
196:
197: private ContextProvider myProvider;
198:
199: private Property myValue;
200: }
|