This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 145543
Collapse All | Expand All

(-)f080832b3afd (+189 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.junit.output;
41
42
import java.util.BitSet;
43
import org.openide.explorer.view.TreeView;
44
import org.openide.nodes.Children;
45
import org.openide.nodes.Node;
46
import static java.lang.Boolean.FALSE;
47
import static java.lang.Boolean.TRUE;
48
49
/**
50
 * Utility class containing methods for storage and recovery of nodes'
51
 * expansion states (collapsed/expanded).
52
 *
53
 * @author  Marian Petras
54
 */
55
final class NodeStateUtilities {
56
57
    private NodeStateUtilities() { }
58
59
    /**
60
     */
61
    static Object getExpansionState(final Node node,
62
                                    final TreeView treeView) {
63
        if (!treeView.isExpanded(node)) {
64
            return FALSE;
65
        }
66
67
        return getExpansionStates(node.getChildren(), treeView);
68
    }
69
70
    /**
71
     */
72
    static void restoreExpansionState(final Node node,
73
                                      final Object stateInfo,
74
                                      final TreeView treeView) {
75
        if (stateInfo == FALSE) {
76
            //we will not be collapsing nodes expanded by the user
77
        } else if (stateInfo != null) {
78
            treeView.expandNode(node);
79
            if (stateInfo != TRUE) {
80
                restoreExpansionStates(node.getChildren(), stateInfo, treeView);
81
            }
82
        }
83
    }
84
85
    /**
86
     */
87
    static Object getExpansionStates(final Children children,
88
                                     final TreeView treeView) {
89
        if (children == Children.LEAF) {
90
            return FALSE;
91
        }
92
93
        return getExpansionStates(children.getNodes(), treeView);
94
    }
95
96
    /**
97
     */
98
    static void restoreExpansionStates(final Children children,
99
                                       final Object statesInfo,
100
                                       final TreeView treeView) {
101
        if (children == Children.LEAF) {
102
            return;
103
        }
104
105
        restoreExpansionStates(children.getNodes(true), statesInfo, treeView);
106
    }
107
108
    /**
109
     */
110
    static Object getExpansionStates(final Node[] nodes,
111
                                     final TreeView treeView) {
112
        if (nodes.length == 0) {
113
            return TRUE;
114
        }
115
116
        BitSet stateSet = null;
117
        Object[] stateArray = null;
118
        for (int i = 0; i < nodes.length; i++) {
119
            Object expansionState = getExpansionState(nodes[i], treeView);
120
            if (stateArray == null) {
121
                if (expansionState == TRUE) {
122
                    if (stateSet == null) {
123
                        stateSet = new BitSet(nodes.length);
124
                    }
125
                    stateSet.set(i);
126
                    continue;
127
                }
128
129
                if (expansionState == FALSE) {
130
                    //stateSet.clear(i);            //it is the default value
131
                    continue;
132
                }
133
134
                /*
135
                 * Oops! Something else then TRUE or FALSE!
136
                 * We cannot store such a value in a bitset.
137
                 * So convert the data collected so far to another format
138
                 * - to an array of objects:
139
                 */
140
                stateArray = new Object[nodes.length];
141
                for (int j = 0; j < i; j++) {
142
                    stateArray[j] = stateSet.get(j) ? TRUE : FALSE;
143
                }
144
                stateSet = null;
145
            }
146
            stateArray[i] = expansionState;
147
        }
148
        assert (stateSet == null) || (stateArray == null); //at most one is used
149
150
        if ((stateSet == null) && (stateArray == null)) {
151
            /* no node expanded */
152
            return TRUE;
153
        }
154
155
        return (stateSet != null) ? stateSet : stateArray;
156
    }
157
158
    /**
159
     */
160
    static void restoreExpansionStates(final Node[] nodes,
161
                                       final Object statesInfo,
162
                                       final TreeView treeView) {
163
        if (statesInfo == null) {
164
            return;
165
        }
166
167
        final Class infoClass = statesInfo.getClass();
168
        if (infoClass == Boolean.class) {
169
            assert ((Boolean) statesInfo).booleanValue();   //always TRUE
170
            //nothing to do (nothing to expand)
171
        } else if (infoClass == BitSet.class) {
172
            BitSet stateSet = (BitSet) statesInfo;
173
            int length = Math.min(stateSet.size(), nodes.length);
174
            for (int i = stateSet.nextSetBit(0);
175
                                (i < length) && (i != -1);
176
                                i = stateSet.nextSetBit(i + 1)) {
177
                treeView.expandNode(nodes[i]);
178
            }
179
        } else {
180
            assert infoClass.isArray();
181
            Object[] states = (Object[]) statesInfo;
182
            int length = Math.min(nodes.length, states.length);
183
            for (int i = 0; i < length; i++) {
184
                restoreExpansionState(nodes[i], states[i], treeView);
185
            }
186
        }
187
    }
188
189
}
(-)a/junit/src/org/netbeans/modules/junit/output/ResultPanelTree.java (-3 / +3 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 24-30 Link Here
24
 * Contributor(s):
24
 * Contributor(s):
25
 *
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
30
 * If you wish your version of this file to be governed by only the CDDL
Lines 222-228 Link Here
222
        
222
        
223
        this.filtered = filtered;
223
        this.filtered = filtered;
224
        
224
        
225
        rootNode.setFiltered(filtered);
225
        rootNode.setFiltered(filtered, treeView);
226
    }
226
    }
227
227
228
    /**
228
    /**
(-)a/junit/src/org/netbeans/modules/junit/output/RootNode.java (-2 / +3 lines)
Lines 43-48 Link Here
43
43
44
import java.awt.EventQueue;
44
import java.awt.EventQueue;
45
import java.util.Collection;
45
import java.util.Collection;
46
import org.openide.explorer.view.TreeView;
46
import org.openide.nodes.AbstractNode;
47
import org.openide.nodes.AbstractNode;
47
import org.openide.nodes.Children;
48
import org.openide.nodes.Children;
48
import org.openide.util.NbBundle;
49
import org.openide.util.NbBundle;
Lines 172-178 Link Here
172
    
173
    
173
    /**
174
    /**
174
     */
175
     */
175
    void setFiltered(final boolean filtered) {
176
    void setFiltered(final boolean filtered, final TreeView treeView) {
176
        assert EventQueue.isDispatchThread();
177
        assert EventQueue.isDispatchThread();
177
        
178
        
178
        if (filtered == this.filtered) {
179
        if (filtered == this.filtered) {
Lines 182-188 Link Here
182
        
183
        
183
        Children children = getChildren();
184
        Children children = getChildren();
184
        if (children != Children.LEAF) {
185
        if (children != Children.LEAF) {
185
            ((RootNodeChildren) children).setFiltered(filtered);
186
            ((RootNodeChildren) children).setFiltered(filtered, treeView);
186
        }
187
        }
187
    }
188
    }
188
    
189
    
(-)a/junit/src/org/netbeans/modules/junit/output/RootNodeChildren.java (-3 / +21 lines)
Lines 46-51 Link Here
46
import java.util.Collection;
46
import java.util.Collection;
47
import java.util.Iterator;
47
import java.util.Iterator;
48
import java.util.List;
48
import java.util.List;
49
import org.openide.explorer.view.TreeView;
49
import org.openide.nodes.Children;
50
import org.openide.nodes.Children;
50
import org.openide.nodes.Node;
51
import org.openide.nodes.Node;
51
52
Lines 69-74 Link Here
69
    private String runningSuiteName;
70
    private String runningSuiteName;
70
    /** */
71
    /** */
71
    private TestsuiteNode runningSuiteNode;
72
    private TestsuiteNode runningSuiteNode;
73
    /** */
74
    private Object nodeStateInfo;
72
    
75
    
73
    /**
76
    /**
74
     * Creates a new instance of ReportRootNode
77
     * Creates a new instance of ReportRootNode
Lines 233-239 Link Here
233
        super.removeNotify();
236
        super.removeNotify();
234
        live = false;
237
        live = false;
235
    }
238
    }
236
    
239
237
    /**
240
    /**
238
     * Adds all nodes matching the current filter (if the filter is enabled)
241
     * Adds all nodes matching the current filter (if the filter is enabled)
239
     * or all nodes generally (if the filter is off).
242
     * or all nodes generally (if the filter is off).
Lines 267-273 Link Here
267
    private void removeAllNodes() {
270
    private void removeAllNodes() {
268
        remove(getNodes());
271
        remove(getNodes());
269
    }
272
    }
270
    
273
271
    /**
274
    /**
272
     */
275
     */
273
    private TestsuiteNode createNode(final Report report) {
276
    private TestsuiteNode createNode(final Report report) {
Lines 276-282 Link Here
276
    
279
    
277
    /**
280
    /**
278
     */
281
     */
279
    void setFiltered(final boolean filtered) {
282
    void setFiltered(final boolean filtered,
283
                     final TreeView treeView) {
280
        assert EventQueue.isDispatchThread();
284
        assert EventQueue.isDispatchThread();
281
        
285
        
282
        if (filtered == this.filtered) {
286
        if (filtered == this.filtered) {
Lines 289-298 Link Here
289
        }
293
        }
290
294
291
        if (filtered) {
295
        if (filtered) {
296
            storeNodeExpansionState(treeView);
292
            removePassedSuites();
297
            removePassedSuites();
293
        } else {
298
        } else {
294
            addPassedSuites();
299
            addPassedSuites();
300
            recallNodeExpansionState(treeView);
295
        }
301
        }
302
    }
303
304
    private void storeNodeExpansionState(final TreeView treeView) {
305
        assert nodeStateInfo == null;
306
        nodeStateInfo = NodeStateUtilities.getExpansionStates(this, treeView);
307
    }
308
309
    private void recallNodeExpansionState(final TreeView treeView) {
310
        if ((nodeStateInfo != null) && (nodeStateInfo.getClass() != Boolean.class)) {
311
            NodeStateUtilities.restoreExpansionStates(this, nodeStateInfo, treeView);
312
        }
313
        nodeStateInfo = null;
296
    }
314
    }
297
    
315
    
298
    /**
316
    /**

Return to bug 145543