1 package jde.debugger.gui;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Comparator;
6 import java.util.Iterator;
8 import java.util.TreeSet;
9 import javax.swing.tree.DefaultTreeModel;
10 import javax.swing.tree.MutableTreeNode;
11 import javax.swing.tree.TreeModel;
12 import javax.swing.tree.TreeNode;
14 import com.sun.jdi.ArrayReference;
15 import com.sun.jdi.ArrayType;
16 import com.sun.jdi.Field;
17 import com.sun.jdi.ReferenceType;
18 import com.sun.jdi.StringReference;
19 import com.sun.jdi.Value;
20 import jde.debugger.JDEException;
24 /** A TreeNode for array references.
25 * @author <a href="mailto:udalrich@carolingia.org">Troy Daniels</a>
27 * @version $Revision: 1.1 $
29 class ArrayModel extends ReferenceModel {
32 ArrayModel(ArrayReference value, DefaultTreeModel treeModel) {
35 throw new IllegalArgumentException("Null value in constructor.");
36 if (null == treeModel)
37 throw new IllegalArgumentException("Null tree model in constructor.");
39 m_treeModel = treeModel;
43 /** Get the number of children.
44 * @return The number of fields that we should be displaying.
47 return m_value.length();
49 /** Returns if the node allows children */
50 boolean getAllowsChildren() { return true; }
52 /** Create a child at the given index.
53 * @return A tree node for the child at the given index */
54 MutableTreeNode createChildAt(int index) throws JDEException {
55 String name = getIndexName(index);
56 ArrayType arrayType = (ArrayType) m_value.type();
57 MutableTreeNode node =
58 LVTreeNode.makeTreeNode(name,
59 arrayType.componentTypeName(),
60 m_value.getValue(index),
65 /** Get a string to represent the value of the variable */
67 return m_value.type().name() + "[" + m_value.length() + "]";
70 private static String getIndexName(int index) {
71 return "[" + index + "]";
74 /** Update the values in the children
75 * @param children The array of old child values
77 void updateChildren(TreeNode[] children) {
78 // For the children that already exist, set the new value.
79 TreeNode reloadParent = null;
81 (index < children.length) &&
82 (index < m_value.length());
84 LVTreeNode child = asLVTreeNode(children[index]);
85 if ((null != child) &&
86 (child.getName().equals(getIndexName(index))))
87 child.setValue(m_value.getValue(index));
89 // Different node. Reset it
90 if ((null != children[index]) &&
91 (null != children[index].getParent()))
92 reloadParent = children[index].getParent();
93 children[index] = null;
97 // Reload the model if we had significant changes
98 if (null != reloadParent)
99 m_treeModel.reload(reloadParent);
102 private final ArrayReference m_value;
103 private final DefaultTreeModel m_treeModel;