2
* The contents of this file are subject to the terms of the Common Development
3
* and Distribution License (the License). You may not use this file except in
4
* compliance with the License.
6
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
* or http://www.netbeans.org/cddl.txt.
9
* When distributing Covered Code, include this CDDL Header Notice in each file
10
* and include the License file at http://www.netbeans.org/cddl.txt.
11
* If applicable, add the following below the CDDL Header, with the fields
12
* enclosed by brackets [] replaced by your own identifying information:
13
* "Portions Copyrighted [year] [name of copyright owner]"
15
* The Original Software is NetBeans. The Initial Developer of the Original
16
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
* Microsystems, Inc. All Rights Reserved.
19
package org.netbeans.modules.php.dbgp.models.nodes;
21
import java.util.ArrayList;
22
import java.util.Collection;
23
import java.util.Iterator;
24
import java.util.List;
27
import org.netbeans.modules.php.dbgp.models.VariablesModel;
28
import org.netbeans.modules.php.dbgp.models.VariablesModelFilter.FilterType;
29
import org.netbeans.modules.php.dbgp.packets.Property;
30
import org.netbeans.spi.viewmodel.ModelEvent;
37
public abstract class AbstractModelNode {
39
private static final String RESOURCE = "resource"; // NOI18N
41
private static final String OBJECT = "object"; // NOI18N
43
private static final String ARRAY = "array"; // NOI18N
45
private static final String STRING = "string"; // NOI18N
47
private static final String UNDEF = "uninitialized"; // NOI18N
49
private static final String NULL = "null"; // NOI18N
51
AbstractModelNode( AbstractModelNode parent , List<Property> properties ){
53
initVariables( properties );
56
public AbstractModelNode getParent() {
60
public boolean hasType( Set<FilterType> set ) {
61
return isTypeApplied( set );
64
public static org.netbeans.modules.php.dbgp.models.
65
VariablesModel.AbstractVariableNode createVariable( Property property ,
66
AbstractModelNode parent )
68
String type = property.getType();
69
if ( STRING.equals(type)) {
70
return new StringVariableNode( property , parent );
72
else if ( ARRAY.equals( type )) {
73
return new ArrayVariableNode( property , parent );
75
else if ( UNDEF.equals( type )){
76
return new UndefinedVariableNode( property, parent );
78
else if ( NULL.equals( type )){
79
return new NullVariableNode( property, parent );
81
else if ( OBJECT.equals(type )) {
82
return new ObjectVariableNode( property , parent );
84
else if ( RESOURCE.equals(type)) {
85
return new ResourceVariableNode( property , parent );
87
else if ( ScalarTypeVariableNode.BOOLEAN.equals(type) ||
88
ScalarTypeVariableNode.BOOL.equals(type) ||
89
ScalarTypeVariableNode.INTEGER.equals(type) ||
90
ScalarTypeVariableNode.INT.equals(type) ||
91
ScalarTypeVariableNode.FLOAT.equals(type)
94
return new ScalarTypeVariableNode( property , parent );
97
return new BaseVariableNode( property , parent );
101
protected abstract boolean isTypeApplied( Set<FilterType> set );
103
protected List<AbstractVariableNode> getVariables()
108
protected void initVariables( List<Property> properties ) {
109
if ( properties == null ) {
112
myVars = new ArrayList<AbstractVariableNode>( );
113
for (Property property : properties) {
114
org.netbeans.modules.php.dbgp.models.VariablesModel.
115
AbstractVariableNode var = createVariable( property , this );
120
protected void setVars( List<AbstractVariableNode> variables )
125
protected boolean addAbsentChildren( AbstractModelNode node) {
126
boolean hasChanged = false;
127
if (node.getVariables() != null && node.getVariables().size() > 0) {
128
Iterator<AbstractVariableNode> iterator = node.getVariables().iterator();
130
while (iterator.hasNext()) {
131
AbstractVariableNode newChild = iterator.next();
133
getVariables().add(newChild);
140
protected boolean updateExistedChildren( VariablesModel variablesModel,
141
AbstractModelNode node, Collection<ModelEvent> events )
143
boolean hasChanged = false;
144
List<AbstractVariableNode> list = new ArrayList<AbstractVariableNode>(
148
for( AbstractVariableNode child : list ) {
149
Property property = child.getProperty();
151
int newIndex = node.findChild(property);
153
if (newIndex == -1) {
154
getVariables().remove( currentIndx );
158
AbstractVariableNode newChild = node.getVariables().get(newIndex);
159
Property newProp = newChild.getProperty();
160
if (property.getType().equals(newProp.getType())) {
161
// properties are absolutely equal , need just update children and value
162
node.getVariables().remove( newIndex );
163
child.collectUpdates(variablesModel, newChild, events);
167
* Properties have the same name only. But we need to change
168
* class for variable ( because they have different types ).
170
getVariables().remove(currentIndx);
171
getVariables().add(currentIndx, newChild);
172
node.getVariables().remove( newIndex );
180
protected boolean updatePage( AbstractVariableNode node ) {
181
Property property = node.getProperty();
182
if ( property.getPageSize() >0 && property.getPage() >0 ){
183
addAbsentChildren(node);
191
protected int findChild( Property property ) {
193
for( AbstractVariableNode node : getVariables() ) {
194
Property prop = node.getProperty();
195
String propName = prop.getName();
196
//String propType = prop.getType();
197
if ( propName.equals( property.getName()) )
198
// && propType.equals( property.getType()))
207
private List<AbstractVariableNode> myVars;
209
private AbstractModelNode myParent;