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

(-)a/core.output2/nbproject/project.xml (-1 / +1 lines)
Lines 94-100 Link Here
94
                    <build-prerequisite/>
94
                    <build-prerequisite/>
95
                    <compile-dependency/>
95
                    <compile-dependency/>
96
                    <run-dependency>
96
                    <run-dependency>
97
                        <specification-version>1.23</specification-version>
97
                        <specification-version>1.33</specification-version>
98
                    </run-dependency>
98
                    </run-dependency>
99
                </dependency>
99
                </dependency>
100
                <dependency>
100
                <dependency>
(-)a/core.output2/src/org/netbeans/core/output2/NbIOProvider.java (-17 / +36 lines)
Lines 45-55 Link Here
45
package org.netbeans.core.output2;
45
package org.netbeans.core.output2;
46
46
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.util.WeakHashMap;
48
import javax.swing.Action;
49
import javax.swing.Action;
49
import org.openide.util.Exceptions;
50
import org.openide.util.Exceptions;
50
import org.openide.util.NbBundle;
51
import org.openide.util.NbBundle;
52
import org.openide.windows.IOContainer;
51
import org.openide.windows.IOProvider;
53
import org.openide.windows.IOProvider;
52
import org.openide.windows.IOContainer;
53
import org.openide.windows.InputOutput;
54
import org.openide.windows.InputOutput;
54
import org.openide.windows.OutputWriter;
55
import org.openide.windows.OutputWriter;
55
56
Lines 59-65 Link Here
59
 */
60
 */
60
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100)
61
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100)
61
public final class NbIOProvider extends IOProvider {
62
public final class NbIOProvider extends IOProvider {
62
    private static final PairMap namesToIos = new PairMap();
63
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
64
            new WeakHashMap<IOContainer, PairMap>();
63
65
64
    private static final String STDOUT = NbBundle.getMessage(NbIOProvider.class,
66
    private static final String STDOUT = NbBundle.getMessage(NbIOProvider.class,
65
        "LBL_STDOUT"); //NOI18N
67
        "LBL_STDOUT"); //NOI18N
Lines 110-124 Link Here
110
        return NAME;
112
        return NAME;
111
    }
113
    }
112
114
113
    private InputOutput getIO(String name, boolean newIO, Action[] toolbarActions, IOContainer ioContainer) {
115
    @Override
116
    public InputOutput getIO(String name, boolean newIO,
117
            Action[] toolbarActions, IOContainer ioContainer) {
114
        if (Controller.LOG) {
118
        if (Controller.LOG) {
115
            Controller.log("GETIO: " + name + " new:" + newIO);
119
            Controller.log("GETIO: " + name + " new:" + newIO);
116
        }
120
        }
117
        NbIO result = namesToIos.get(name);
121
        IOContainer realIoContainer = ioContainer == null
118
122
                ? IOContainer.getDefault() : ioContainer;
123
        NbIO result;
124
        synchronized (containerPairMaps) {
125
            PairMap namesToIos = containerPairMaps.get(realIoContainer);
126
            result = namesToIos != null ? namesToIos.get(name) : null;
127
        }
119
        if (result == null || newIO) {
128
        if (result == null || newIO) {
120
            result = new NbIO(name, toolbarActions, ioContainer);
129
            result = new NbIO(name, toolbarActions, realIoContainer);
121
            namesToIos.add (name, result);
130
            synchronized (containerPairMaps) {
131
                PairMap namesToIos = containerPairMaps.get(realIoContainer);
132
                if (namesToIos == null) {
133
                    namesToIos = new PairMap();
134
                    containerPairMaps.put(realIoContainer, namesToIos);
135
                }
136
                namesToIos.add(name, result);
137
            }
122
            NbIO.post(new IOEvent(result, IOEvent.CMD_CREATE, newIO));
138
            NbIO.post(new IOEvent(result, IOEvent.CMD_CREATE, newIO));
123
        }
139
        }
124
        return result;
140
        return result;
Lines 126-141 Link Here
126
    
142
    
127
    
143
    
128
    static void dispose (NbIO io) {
144
    static void dispose (NbIO io) {
129
        namesToIos.remove (io);
145
        IOContainer ioContainer = io.getIOContainer();
130
    }
146
        if (ioContainer == null) {
131
    
147
            ioContainer = IOContainer.getDefault();
132
    /**
148
        }
133
     * Called when the output window is hidden.  Switches the caching of IOs
149
        synchronized (containerPairMaps) {
134
     * to weak references, so that only those still alive will be shown the 
150
            PairMap namesToIos = containerPairMaps.get(ioContainer);
135
     * next time the output window is opened.
151
            if (namesToIos != null) {
136
     */
152
                namesToIos.remove(io);
137
    static void setWeak(boolean value) {
153
                if (namesToIos.isEmpty()) {
138
        namesToIos.setWeak(value);
154
                    containerPairMaps.remove(ioContainer);
155
                }
156
            }
157
        }
139
    }
158
    }
140
}
159
}
141
160
(-)a/core.output2/test/unit/src/org/netbeans/core/output2/NbIOProviderTest.java (+148 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.core.output2;
43
44
import javax.swing.Action;
45
import javax.swing.Icon;
46
import javax.swing.JComponent;
47
import static org.junit.Assert.*;
48
import org.junit.Test;
49
import org.openide.windows.IOContainer;
50
import org.openide.windows.IOContainer.CallBacks;
51
import org.openide.windows.IOProvider;
52
import org.openide.windows.InputOutput;
53
54
/**
55
 *
56
 * @author jhavlin
57
 */
58
public class NbIOProviderTest {
59
60
    public NbIOProviderTest() {
61
    }
62
63
    @Test
64
    public void testGetIO_4args() {
65
66
        IOContainer def = IOContainer.getDefault();
67
        IOContainer cus = IOContainer.create(new MyContainerProvider());
68
69
        InputOutput ioDef1 = IOProvider.getDefault().getIO("test1", true, null, def);
70
        InputOutput ioCus1 = IOProvider.getDefault().getIO("test1", true, null, cus);
71
        InputOutput ioDef2 = IOProvider.getDefault().getIO("test2", true, null, def);
72
        InputOutput ioCus2 = IOProvider.getDefault().getIO("test2", true, null, cus);
73
74
        assertNotSame(ioDef1, ioCus1);
75
        assertNotSame(ioDef2, ioCus2);
76
        assertNotSame(ioDef1, ioDef2);
77
        assertNotSame(ioCus1, ioCus2);
78
79
        InputOutput ioDef1b = IOProvider.getDefault().getIO("test1", false, null, def);
80
        InputOutput ioCus1b = IOProvider.getDefault().getIO("test1", false, null, cus);
81
82
        assertSame(ioDef1, ioDef1b);
83
        assertSame(ioCus1, ioCus1b);
84
85
        ioDef1.closeInputOutput();
86
        ioDef2.closeInputOutput();
87
        ioCus1.closeInputOutput();
88
        ioCus2.closeInputOutput();
89
    }
90
91
    public static class MyContainerProvider implements IOContainer.Provider {
92
93
        @Override
94
        public void open() {
95
        }
96
97
        @Override
98
        public void requestActive() {
99
        }
100
101
        @Override
102
        public void requestVisible() {
103
        }
104
105
        @Override
106
        public boolean isActivated() {
107
            return true;
108
        }
109
110
        @Override
111
        public void add(JComponent comp, CallBacks cb) {
112
        }
113
114
        @Override
115
        public void remove(JComponent comp) {
116
        }
117
118
        @Override
119
        public void select(JComponent comp) {
120
        }
121
122
        @Override
123
        public JComponent getSelected() {
124
            return null;
125
        }
126
127
        @Override
128
        public void setTitle(JComponent comp, String name) {
129
        }
130
131
        @Override
132
        public void setToolTipText(JComponent comp, String text) {
133
        }
134
135
        @Override
136
        public void setIcon(JComponent comp, Icon icon) {
137
        }
138
139
        @Override
140
        public void setToolbarActions(JComponent comp, Action[] toolbarActions) {
141
        }
142
143
        @Override
144
        public boolean isCloseable(JComponent comp) {
145
            return true;
146
        }
147
    }
148
}
(-)a/openide.io/apichanges.xml (+24 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
<changes>
109
<changes>
110
    <change id="getIO-4-params">
111
      <api name="io"/>
112
      <summary>Added IOProvider.getIO variant that takes all 4 possible parameters.</summary>
113
      <version major="1" minor="33"/>
114
      <date day="22" month="6" year="2012"/>
115
      <author login="jhavlin"/>
116
      <compatibility addition="yes" binary="compatible" semantic="compatible" />
117
      <description>
118
          <p>
119
              Added method <code>IOProvider.getIO</code> that takes all
120
              4 supported parameters and that complements other
121
              <code>getIO</code> methods. See
122
              <code><a href="@TOP@/org/openide/windows/IOProvider.html">
123
              IOProvider</a></code>
124
          </p>
125
          <p>
126
              The original mapping from IO name to IO object has been replaced
127
              with mapping from pair [IO container, IO name] to IO object.
128
              This mapping is used for reusing of IO objects.
129
          </p>
130
      </description>
131
      <class package="org.openide.windows" name="IOProvider"/>
132
      <issue number="182538" />
133
    </change>
110
    <change id="Fine-grain-select">
134
    <change id="Fine-grain-select">
111
      <api name="io"/>
135
      <api name="io"/>
112
      <summary>Added API for fine grain control over IO select operation</summary>
136
      <summary>Added API for fine grain control over IO select operation</summary>
(-)a/openide.io/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.io
2
OpenIDE-Module: org.openide.io
3
OpenIDE-Module-Specification-Version: 1.32
3
OpenIDE-Module-Specification-Version: 1.33
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/openide.io/nbproject/project.xml (+9 lines)
Lines 50-55 Link Here
50
            <code-name-base>org.openide.io</code-name-base>
50
            <code-name-base>org.openide.io</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.15</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
53
                    <code-name-base>org.openide.util</code-name-base>
62
                    <code-name-base>org.openide.util</code-name-base>
54
                    <build-prerequisite/>
63
                    <build-prerequisite/>
55
                    <compile-dependency/>
64
                    <compile-dependency/>
(-)a/openide.io/src/org/openide/windows/IOProvider.java (+26 lines)
Lines 52-57 Link Here
52
import java.io.StringWriter;
52
import java.io.StringWriter;
53
import java.util.Collection;
53
import java.util.Collection;
54
import javax.swing.Action;
54
import javax.swing.Action;
55
import org.netbeans.api.annotations.common.NonNull;
56
import org.netbeans.api.annotations.common.NullAllowed;
55
import org.openide.util.Lookup;
57
import org.openide.util.Lookup;
56
58
57
/** A factory for IO tabs shown in the output window.  To create a new tab to
59
/** A factory for IO tabs shown in the output window.  To create a new tab to
Lines 156-161 Link Here
156
    }
158
    }
157
159
158
    /**
160
    /**
161
     * Gets a named instance of {@link InputOutput}. Corresponding IO tab will be placed
162
     * in parent container corresponding to provided {@link IOContainer}.
163
     * @param name A localized display name for the tab
164
     * @param newIO if <tt>true</tt>, a new <code>InputOutput</code> is returned, else an existing <code>InputOutput</code> of the same name may be returned
165
     * @param actions array of actions that are added to the toolbar, Can be empty array, but not null.
166
     *   The number of actions should not exceed 5 and each should have the <code>Action.SMALL_ICON</code> property defined.
167
     * @param ioContainer parent container accessor
168
     * @return an <code>InputOutput</code> instance for accessing the new tab
169
     * <br>Note: Please remember that {@link InputOutput} objects need to be
170
     * properly closed. Ensure that {@link InputOutput#closeInputOutput()} is
171
     * called when returned object is no longer needed, otherwise allocated
172
     * memory and other resources will not be freed.
173
     * @see InputOutput
174
     * @since 1.33
175
     * <br>Note: The method is non-abstract for backward compatibility reasons only. If you are
176
     * extending <code>IOProvider</code> and implementing its abstract classes, you are encouraged to override
177
     * this method as well. The default implementation falls back to the <code>getIO(name, actions)</code> method, ignoring the ioContainer and newIO passed.
178
     */
179
    public @NonNull InputOutput getIO(@NonNull String name, boolean newIO,
180
            @NonNull Action[] actions, @NullAllowed IOContainer ioContainer) {
181
        return getIO(name, actions);
182
    }
183
184
    /**
159
     * Gets name (ID) of provider
185
     * Gets name (ID) of provider
160
     * @return name of provider
186
     * @return name of provider
161
     * @since 1.15
187
     * @since 1.15
(-)a/terminal/src/org/netbeans/modules/terminal/ioprovider/TerminalIOProvider.java (-1 / +2 lines)
Lines 60-66 Link Here
60
	return getIO(name, true, actions, ioContainer);
60
	return getIO(name, true, actions, ioContainer);
61
    }
61
    }
62
62
63
    private InputOutput getIO(String name,
63
    @Override
64
    public InputOutput getIO(String name,
64
	                      boolean newIO,
65
	                      boolean newIO,
65
			      Action[] actions,
66
			      Action[] actions,
66
			      IOContainer ioContainer) {
67
			      IOContainer ioContainer) {

Return to bug 182538