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.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008:
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.php.dbgp.models.nodes;
020:
021: import java.util.Collection;
022: import java.util.List;
023:
024: import org.netbeans.modules.php.dbgp.api.ModelNode;
025: import org.netbeans.modules.php.dbgp.api.UnsufficientValueException;
026: import org.netbeans.modules.php.dbgp.models.VariablesModel;
027: import org.netbeans.modules.php.dbgp.packets.Property;
028: import org.netbeans.modules.php.dbgp.packets.PropertyCommand;
029: import org.netbeans.modules.php.dbgp.packets.PropertyGetCommand;
030: import org.netbeans.modules.php.dbgp.packets.PropertySetCommand;
031: import org.netbeans.modules.php.dbgp.packets.PropertyValueCommand;
032: import org.netbeans.spi.viewmodel.ModelEvent;
033: import org.openide.text.Line;
034:
035: /**
036: * @author ads
037: *
038: */
039: public abstract class AbstractVariableNode extends AbstractModelNode
040: implements VariableNode {
041:
042: protected static final String FIELD_ICON = "org/netbeans/modules/debugger/resources/watchesView/Field"; // NOI18N
043:
044: /**
045: * <code>property</code> is not authority for this class.
046: * It is used as information.
047: * This class is initialized based on <code>property</code>.
048: * And it could be updated later based on other property .
049: * F.e. one can set new property via {@link #setProperty(Property)}
050: * but this doesn't mean that all AbstractVariableNode should be
051: * reinitialized due property change.
052: * AbstractVariableNode provides its own information that updates by
053: * ( basically children ) adding/removing children.
054: * So children in current <code>property</code> and AbstractVariableNode
055: * class could be different.
056: */
057: protected AbstractVariableNode(Property property,
058: AbstractModelNode parent) {
059: super (parent, property.getChildren());
060: myProperty = property;
061: }
062:
063: /* (non-Javadoc)
064: * @see org.netbeans.modules.php.dbgp.models.VariableNode#getFullName()
065: */
066: public String getFullName() {
067: return getProperty().getFullName();
068: }
069:
070: /* (non-Javadoc)
071: * @see org.netbeans.modules.php.dbgp.models.VariableNode#getName()
072: */
073: public String getName() {
074: AbstractModelNode node = getParent();
075: if (node instanceof ArrayVariableNode) {
076: StringBuilder builder = new StringBuilder("[");
077: builder.append(getProperty().getName());
078: builder.append("]");
079: return builder.toString();
080: }
081: return getProperty().getName();
082: }
083:
084: /* (non-Javadoc)
085: * @see org.netbeans.modules.php.dbgp.api.ModelNode#getChildren(int, int)
086: */
087: public ModelNode[] getChildren(int from, int to) {
088: List<AbstractVariableNode> subList = getVariables().subList(
089: from, to);
090: return subList.toArray(new ModelNode[subList.size()]);
091: }
092:
093: /* (non-Javadoc)
094: * @see org.netbeans.modules.php.dbgp.api.ModelNode#getChildrenSize()
095: */
096: public int getChildrenSize() {
097: return getVariables().size();
098: }
099:
100: /* (non-Javadoc)
101: * @see org.netbeans.modules.php.dbgp.api.ModelNode#getIconBase()
102: */
103: public String getIconBase() {
104: AbstractModelNode node = getParent();
105: if (node instanceof ObjectVariableNode) {
106: return FIELD_ICON;
107: }
108: return LOCAL_VARIABLE_ICON;
109: }
110:
111: /* (non-Javadoc)
112: * @see org.netbeans.modules.php.dbgp.api.ModelNode#getShortDescription()
113: */
114: public String getShortDescription() {
115: // TODO Auto-generated method stub
116: return null;
117: }
118:
119: /* (non-Javadoc)
120: * @see org.netbeans.modules.php.dbgp.api.ModelNode#getType()
121: */
122: public String getType() {
123: return getProperty().getType();
124: }
125:
126: /* (non-Javadoc)
127: * @see org.netbeans.modules.php.dbgp.api.ModelNode#getValue()
128: */
129: public String getValue() throws UnsufficientValueException {
130: return getProperty().getStringValue();
131: }
132:
133: /* (non-Javadoc)
134: * @see org.netbeans.modules.php.dbgp.api.ModelNode#isReadOnly()
135: */
136: public boolean isReadOnly() {
137: return false;
138: }
139:
140: /* (non-Javadoc)
141: * @see org.netbeans.modules.php.dbgp.models.VariableNode#findDeclarationLine()
142: */
143: public Line findDeclarationLine() {
144: // TODO Auto-generated method stub
145: return null;
146: }
147:
148: /* (non-Javadoc)
149: * @see org.netbeans.modules.php.dbgp.api.ModelNode#isLeaf()
150: */
151: public boolean isLeaf() {
152: return !getProperty().hasChildren();
153: }
154:
155: public void setupCommand(PropertyValueCommand valueCommand) {
156: setupCommand((PropertyGetCommand) valueCommand);
157: valueCommand.setMaxDataSize(getProperty().getSize());
158: // ? valueCommand.setAddress( getProperty().getAddress());
159: }
160:
161: public void setupCommand(PropertyGetCommand getCommand) {
162: setupCommand((PropertyCommand) getCommand);
163: String key = getProperty().getKey();
164: if (key != null) {
165: getCommand.setKey(key);
166: }
167: }
168:
169: public void setupCommand(PropertySetCommand command) {
170: setupCommand((PropertyCommand) command);
171: // ? command.setAddress( getProperty().getAddress());
172: }
173:
174: public void setupFillChildrenCommand(PropertyGetCommand getCommand) {
175: setupCommand(getCommand);
176: int page = getProperty().getPage() + 1;
177: getCommand.setDataPage(page);
178: }
179:
180: public boolean isChildrenFilled() {
181: int pages = getProperty().getPageSize();
182: if (pages == 0) {
183: return true;
184: }
185: return getProperty().getChildren().size() == 0;
186: }
187:
188: public int getContext() {
189: return getRootContext().getIndex();
190: }
191:
192: protected void setProperty(Property property) {
193: Property old = getProperty();
194: property.setName(old.getName());
195: myProperty = property;
196: }
197:
198: protected abstract void collectUpdates(
199: VariablesModel variablesModel, VariableNode node,
200: Collection<ModelEvent> events);
201:
202: protected Property getProperty() {
203: return myProperty;
204: }
205:
206: public ContextNode getRootContext() {
207: AbstractModelNode parent = getParent();
208: while (!(parent instanceof ContextNode)) {
209: parent = parent.getParent();
210: }
211: assert parent instanceof ContextNode;
212: return (ContextNode) parent;
213: }
214:
215: private void setupCommand(PropertyCommand command) {
216: command.setName(getFullName());
217: command.setContext(getContext());
218: }
219:
220: private Property myProperty;
221:
222: }
|