jdk/src/share/classes/com/sun/tools/example/debug/gui/ClassTreeTool.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 51 6fe31bc95bbc
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 51
diff changeset
     2
 * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.example.debug.gui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.tree.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.example.debug.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.example.debug.bdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class ClassTreeTool extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private Environment env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private ExecutionManager runtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private SourceManager sourceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private ClassManager classManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private JTree tree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private DefaultTreeModel treeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private ClassTreeNode root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private SearchPath sourcePath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private CommandInterpreter interpreter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static String HEADING = "CLASSES";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public ClassTreeTool(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        super(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.runtime = env.getExecutionManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.sourceManager = env.getSourceManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.interpreter = new CommandInterpreter(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        root = createClassTree(HEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        treeModel = new DefaultTreeModel(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        // Create a tree that allows one selection at a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        tree = new JTree(treeModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        tree.setSelectionModel(new SingleLeafTreeSelectionModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        /******
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // Listen for when the selection changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        tree.addTreeSelectionListener(new TreeSelectionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            public void valueChanged(TreeSelectionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                ClassTreeNode node = (ClassTreeNode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    (e.getPath().getLastPathComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                if (node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    interpreter.executeCommand("view " + node.getReferenceTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        ******/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        MouseListener ml = new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                int selRow = tree.getRowForLocation(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if(selRow != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    if(e.getClickCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        ClassTreeNode node =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                            (ClassTreeNode)selPath.getLastPathComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        // If user clicks on leaf, select it, and issue 'view' command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        if (node.isLeaf()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                            tree.setSelectionPath(selPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                            interpreter.executeCommand("view " + node.getReferenceTypeName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        tree.addMouseListener(ml);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        JScrollPane treeView = new JScrollPane(tree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        add(treeView);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // Create listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        ClassTreeToolListener listener = new ClassTreeToolListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        runtime.addJDIListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        runtime.addSessionListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        //### remove listeners on exit!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private class ClassTreeToolListener extends JDIAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                       implements JDIListener, SessionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // SessionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        public void sessionStart(EventObject e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            // Get system classes and any others loaded before attaching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            try {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   127
                for (ReferenceType type : runtime.allClasses()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    root.addClass(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            } catch (VMDisconnectedException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                // VM terminated unexpectedly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            } catch (NoSessionException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                // Ignore.  Should not happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        public void sessionInterrupt(EventObject e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        public void sessionContinue(EventObject e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // JDIListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        public void classPrepare(ClassPrepareEventSet e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            root.addClass(e.getReferenceType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        public void classUnload(ClassUnloadEventSet e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            root.removeClass(e.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        public void vmDisconnect(VMDisconnectEventSet e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            // Clear contents of this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            root = createClassTree(HEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            treeModel = new DefaultTreeModel(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            tree.setModel(treeModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    ClassTreeNode createClassTree(String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return new ClassTreeNode(label, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    class ClassTreeNode extends DefaultMutableTreeNode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        private ReferenceType refTy;  // null for package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        ClassTreeNode(String name, ReferenceType refTy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            this.refTy = refTy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        public ReferenceType getReferenceType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return refTy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        public String getReferenceTypeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return refTy.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        private boolean isPackage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return (refTy == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        public boolean isLeaf() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            return !isPackage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        public void addClass(ReferenceType refTy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            addClass(refTy.name(), refTy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        private void addClass(String className, ReferenceType refTy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            if (className.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            int pos = className.indexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (pos < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                insertNode(className, refTy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                String head = className.substring(0, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                String tail = className.substring(pos + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                ClassTreeNode child = insertNode(head, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                child.addClass(tail, refTy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        private ClassTreeNode insertNode(String name, ReferenceType refTy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            for (int i = 0; i < getChildCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                ClassTreeNode child = (ClassTreeNode)getChildAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                int cmp = name.compareTo(child.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (cmp == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    // like-named node already exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    return child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                } else if (cmp < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    // insert new node before the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    ClassTreeNode newChild = new ClassTreeNode(name, refTy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    treeModel.insertNodeInto(newChild, this, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    return newChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // insert new node after last child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            ClassTreeNode newChild = new ClassTreeNode(name, refTy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            treeModel.insertNodeInto(newChild, this, getChildCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return newChild;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        public void removeClass(String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if (className.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            int pos = className.indexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (pos < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                ClassTreeNode child = findNode(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (!isPackage()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    treeModel.removeNodeFromParent(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                String head = className.substring(0, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                String tail = className.substring(pos + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                ClassTreeNode child = findNode(head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                child.removeClass(tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                if (isPackage() && child.getChildCount() < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    // Prune non-leaf nodes with no children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    treeModel.removeNodeFromParent(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        private ClassTreeNode findNode(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            for (int i = 0; i < getChildCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                ClassTreeNode child = (ClassTreeNode)getChildAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                int cmp = name.compareTo(child.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                if (cmp == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    return child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                } else if (cmp > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    // not found, since children are sorted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}