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 172012
Collapse All | Expand All

(-)a/core.windows/nbproject/project.xml (+5 lines)
Lines 215-220 Link Here
215
                        <recursive/>
215
                        <recursive/>
216
                        <compile-dependency/>
216
                        <compile-dependency/>
217
                    </test-dependency>
217
                    </test-dependency>
218
                    <test-dependency>
219
                        <code-name-base>org.openide.windows</code-name-base>
220
                        <compile-dependency/>
221
                        <test/>
222
                    </test-dependency>
218
                </test-type>
223
                </test-type>
219
            </test-dependencies>
224
            </test-dependencies>
220
            <friend-packages>
225
            <friend-packages>
(-)a/core.windows/src/org/netbeans/core/windows/RegistryImpl.java (-2 / +71 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.core.windows;
42
package org.netbeans.core.windows;
43
43
44
import java.util.Collection;
45
import java.util.Iterator;
44
import org.openide.nodes.Node;
46
import org.openide.nodes.Node;
45
import org.openide.util.WeakSet;
47
import org.openide.util.WeakSet;
46
import org.openide.windows.TopComponent;
48
import org.openide.windows.TopComponent;
Lines 90-96 Link Here
90
     * @return immutable set of {@link TopComponent}s
92
     * @return immutable set of {@link TopComponent}s
91
     */
93
     */
92
    public synchronized Set<TopComponent> getOpened() {
94
    public synchronized Set<TopComponent> getOpened() {
93
        return java.util.Collections.unmodifiableSet(openSet);
95
        return new SyncSet();
94
    }
96
    }
95
    
97
    
96
    /** Get the currently selected element.
98
    /** Get the currently selected element.
Lines 333-337 Link Here
333
    private static void debugLog(String message) {
335
    private static void debugLog(String message) {
334
        Debug.log(RegistryImpl.class, message);
336
        Debug.log(RegistryImpl.class, message);
335
    }
337
    }
336
    
338
339
    private final class SyncSet implements Set<TopComponent> {
340
        public int size() {
341
            synchronized (RegistryImpl.this) {
342
                return openSet.size();
343
            }
344
        }
345
346
        public boolean isEmpty() {
347
            synchronized (RegistryImpl.this) {
348
                return openSet.isEmpty();
349
            }
350
        }
351
352
        public boolean contains(Object o) {
353
            synchronized (RegistryImpl.this) {
354
                return openSet.contains(o);
355
            }
356
        }
357
358
        public Iterator<TopComponent> iterator() {
359
            synchronized (RegistryImpl.this) {
360
                return new HashSet<TopComponent>(openSet).iterator();
361
            }
362
        }
363
364
        public Object[] toArray() {
365
            synchronized (RegistryImpl.this) {
366
                return openSet.toArray();
367
            }
368
        }
369
370
        public <T> T[] toArray(T[] a) {
371
            synchronized (RegistryImpl.this) {
372
                return openSet.toArray(a);
373
            }
374
        }
375
376
        public boolean containsAll(Collection<?> c) {
377
            synchronized (RegistryImpl.this) {
378
                return openSet.containsAll(c);
379
            }
380
        }
381
382
        public boolean add(TopComponent e) {
383
            throw new UnsupportedOperationException();
384
        }
385
386
        public boolean remove(Object o) {
387
            throw new UnsupportedOperationException();
388
        }
389
390
        public boolean addAll(Collection<? extends TopComponent> c) {
391
            throw new UnsupportedOperationException();
392
        }
393
394
        public boolean retainAll(Collection<?> c) {
395
            throw new UnsupportedOperationException();
396
        }
397
398
        public boolean removeAll(Collection<?> c) {
399
            throw new UnsupportedOperationException();
400
        }
401
402
        public void clear() {
403
            throw new UnsupportedOperationException();
404
        }
405
    }
337
}
406
}
(-)2728bff12ca2 (+55 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.core.windows;
41
42
import org.openide.windows.TopComponentRegistryTest;
43
44
/** Checks that the same behaviour of the registry is kept in the
45
 * default implementation as well as in the real one.
46
 *
47
 * @author Jaroslav Tulach <jtulach@netbeans.org>
48
 */
49
public class TopComponentRegistryImplTest extends TopComponentRegistryTest {
50
51
    public TopComponentRegistryImplTest(String name) {
52
        super(name);
53
    }
54
55
}
(-)a/openide.windows/src/org/openide/windows/DummyWindowManager.java (-2 / +14 lines)
Lines 53-58 Link Here
53
import java.net.URL;
53
import java.net.URL;
54
import java.util.ArrayList;
54
import java.util.ArrayList;
55
import java.util.Arrays;
55
import java.util.Arrays;
56
import java.util.Collections;
56
import java.util.HashMap;
57
import java.util.HashMap;
57
import java.util.HashSet;
58
import java.util.HashSet;
58
import java.util.Iterator;
59
import java.util.Iterator;
Lines 635-641 Link Here
635
        private PropertyChangeSupport pcs;
636
        private PropertyChangeSupport pcs;
636
637
637
        public R() {
638
        public R() {
638
            opened = new HashSet<TopComponent>();
639
            opened = new HashSet<TopComponent>() {
640
                @Override
641
                public Iterator<TopComponent> iterator() {
642
                    HashSet<TopComponent> copy = new HashSet<TopComponent>();
643
                    Iterator<TopComponent> it = super.iterator();
644
                    while (it.hasNext()) {
645
                        TopComponent topComponent = it.next();
646
                        copy.add(topComponent);
647
                    }
648
                    return copy.iterator();
649
                }
650
            };
639
            nodes = new Node[0];
651
            nodes = new Node[0];
640
        }
652
        }
641
653
Lines 676-682 Link Here
676
        }
688
        }
677
689
678
        public synchronized Set<TopComponent> getOpened() {
690
        public synchronized Set<TopComponent> getOpened() {
679
            return new HashSet<TopComponent>(opened);
691
            return Collections.unmodifiableSet(opened);
680
        }
692
        }
681
693
682
        synchronized void setActive(TopComponent tc) {
694
        synchronized void setActive(TopComponent tc) {
(-)2728bff12ca2 (+80 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.openide.windows;
41
42
import java.util.Set;
43
import org.netbeans.junit.NbTestCase;
44
45
public class TopComponentRegistryTest extends NbTestCase {
46
    public TopComponentRegistryTest(String name) {
47
        super(name);
48
    }
49
50
    @Override
51
    protected boolean runInEQ() {
52
        return true;
53
    }
54
55
    public void testGetOpenedIsSafeToIterate() {
56
        TopComponent tc1 = new TopComponent();
57
        TopComponent tc2 = new TopComponent();
58
        TopComponent tc3 = new TopComponent();
59
60
        Set<TopComponent> all = TopComponent.getRegistry().getOpened();
61
62
        tc1.open();
63
        tc2.open();
64
        tc3.open();
65
66
        assertEquals("Contains 3 elements: " + all, 3, all.size());
67
68
        assertTrue("tc1 in set: ", all.contains(tc1));
69
        assertTrue("tc2 in set: ", all.contains(tc2));
70
        assertTrue("tc3 in set: ", all.contains(tc3));
71
72
        int cnt = 3;
73
        for (TopComponent c : all) {
74
            assertTrue("Can be closed", c.close());
75
            assertEquals("Now there are ", --cnt, all.size());
76
        }
77
78
        assertTrue("All components are closed", all.isEmpty());
79
    }
80
}

Return to bug 172012