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

(-)a/spi.debugger.ui/apichanges.xml (+19 lines)
Lines 172-177 Link Here
172
        <class package="org.netbeans.spi.debugger.ui" name="ViewLifecycle"/>
172
        <class package="org.netbeans.spi.debugger.ui" name="ViewLifecycle"/>
173
        <issue number="198385"/>
173
        <issue number="198385"/>
174
    </change>
174
    </change>
175
    
176
    <change id="EngineComponentsProvider">
177
        <api name="DebuggerCoreSPI"/>
178
        <summary><code>EngineComponentsProvider</code> interface added.</summary>
179
        <version major="2" minor="35"/>
180
        <date day="19" month="9" year="2012"/>
181
        <author login="mentlicher"/>
182
        <compatibility binary="compatible" source="compatible" addition="yes" semantic="compatible"/>
183
        <description>
184
            <p>
185
                <code>EngineComponentsProvider</code> interface introduced
186
                to provide GUI components that are associated with a debugger
187
                engine. <code>EngineComponentsProvider.ComponentInfo</code>
188
                provides information about the associated component.
189
            </p>
190
        </description>
191
        <class package="org.netbeans.spi.debugger.ui" name="EngineComponentsProvider"/>
192
        <issue number="217953"/>
193
    </change>
175
194
176
</changes>
195
</changes>
177
196
(-)a/spi.debugger.ui/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.netbeans.spi.debugger.ui/1
2
OpenIDE-Module: org.netbeans.spi.debugger.ui/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties
4
OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml
5
OpenIDE-Module-Specification-Version: 2.34
5
OpenIDE-Module-Specification-Version: 2.35
6
OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui
6
OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui
7
OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class
7
OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/ComponentInfoFromBeanContext.java (+133 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.modules.debugger.ui;
43
44
import java.awt.Component;
45
import java.beans.DesignMode;
46
import java.beans.beancontext.BeanContextChildComponentProxy;
47
import java.lang.reflect.Method;
48
import java.util.ArrayList;
49
import java.util.List;
50
import javax.swing.SwingUtilities;
51
import org.netbeans.api.debugger.Properties;
52
import org.netbeans.spi.debugger.ui.EngineComponentsProvider.ComponentInfo;
53
import org.openide.util.Exceptions;
54
import org.openide.windows.TopComponent;
55
56
/**
57
 * A helper class, which transforms the old providing of associated GUI components
58
 * via BeanContextChildComponentProxy to the new API {@link ComponentInfo}.
59
 * 
60
 * @author Martin Entlicher
61
 */
62
public class ComponentInfoFromBeanContext {
63
    
64
    private static final String PROPERTY_CLOSED_TC = "closedTopComponents"; // NOI18N
65
66
    public static Transform TRANSFORM; // Initialized from EngineComponentsProvider
67
    
68
    static List<ComponentInfo> transform(List<? extends BeanContextChildComponentProxy> componentProxies) {
69
        ComponentInfo.class.getName(); // Initializes TRANSFORM
70
        List<ComponentInfo> cinfos = new ArrayList<ComponentInfo>(componentProxies.size());
71
        for (final BeanContextChildComponentProxy cp : componentProxies) {
72
            final Component[] c = new Component[] { null };
73
            final boolean[] doOpen = new boolean[] { false };
74
            try {
75
                SwingUtilities.invokeAndWait(new Runnable() {
76
                    @Override
77
                    public void run() {
78
                        c[0] = cp.getComponent();
79
                        doOpen[0] = (cp instanceof DesignMode) ? ((DesignMode) cp).isDesignTime() : true;
80
                    }
81
                });
82
                if (c[0] == null) {
83
                    //throw new NullPointerException("No component from "+cp);
84
                    continue;
85
                }
86
            } catch (Exception ex) {
87
                Exceptions.printStackTrace(ex);
88
                continue;
89
            }
90
            //cs.add(c[0]);
91
            boolean open = doOpen[0];
92
            if (c[0] instanceof TopComponent) {
93
                final TopComponent tc = (TopComponent) c[0];
94
                boolean wasClosed = Properties.getDefault().getProperties(DebuggerManagerListener.class.getName()).
95
                        getProperties(PROPERTY_CLOSED_TC).getBoolean(tc.getName(), false);
96
                boolean wasOpened = !Properties.getDefault().getProperties(DebuggerManagerListener.class.getName()).
97
                        getProperties(PROPERTY_CLOSED_TC).getBoolean(tc.getName(), true);
98
                open = (doOpen[0] && !wasClosed || !doOpen[0] && wasOpened);
99
            }
100
            ComponentInfo ci = TRANSFORM.transform(c[0], open);
101
            cinfos.add(ci);
102
        }
103
        
104
        return cinfos;
105
    }
106
107
    static void closing(List<ComponentInfo> components) {
108
        for (ComponentInfo ci : components) {
109
            Component c = ci.getComponent();
110
            if (c instanceof TopComponent) {
111
                TopComponent tc = (TopComponent) c;
112
                /* To check which components we're closing:
113
                try {
114
                    Method pid = TopComponent.class.getDeclaredMethod("preferredID");
115
                    pid.setAccessible(true);
116
                    System.err.println("ComponentInfoFromBeanContext.closing("+pid.invoke(tc)+")");
117
                } catch (Exception ex) {
118
                    ex.printStackTrace();
119
                }*/
120
                boolean isOpened = tc.isOpened();
121
                Properties.getDefault().getProperties(DebuggerManagerListener.class.getName()).
122
                        getProperties(PROPERTY_CLOSED_TC).setBoolean(tc.getName(), !isOpened);
123
            }
124
        }
125
        
126
    }
127
    
128
    public static interface Transform {
129
        
130
        ComponentInfo transform(Component c, boolean opened);//BeanContextChildComponentProxy componentProxy);
131
        
132
    }
133
}
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/DebuggerManagerListener.java (-62 / +165 lines)
Lines 52-60 Link Here
52
import java.beans.beancontext.BeanContextChildComponentProxy;
52
import java.beans.beancontext.BeanContextChildComponentProxy;
53
import java.lang.ref.Reference;
53
import java.lang.ref.Reference;
54
import java.lang.ref.WeakReference;
54
import java.lang.ref.WeakReference;
55
import java.lang.reflect.Method;
55
import java.util.ArrayList;
56
import java.util.ArrayList;
57
import java.util.Collections;
56
import java.util.HashMap;
58
import java.util.HashMap;
57
import java.util.HashSet;
59
import java.util.HashSet;
60
import java.util.LinkedHashMap;
58
import java.util.LinkedList;
61
import java.util.LinkedList;
59
import java.util.List;
62
import java.util.List;
60
import java.util.Map;
63
import java.util.Map;
Lines 71-76 Link Here
71
import org.netbeans.api.debugger.Properties;
74
import org.netbeans.api.debugger.Properties;
72
import org.netbeans.modules.debugger.ui.actions.DebuggerAction;
75
import org.netbeans.modules.debugger.ui.actions.DebuggerAction;
73
import org.netbeans.spi.debugger.ActionsProvider;
76
import org.netbeans.spi.debugger.ActionsProvider;
77
import org.netbeans.spi.debugger.ui.EngineComponentsProvider;
78
import org.netbeans.spi.debugger.ui.EngineComponentsProvider.ComponentInfo;
74
import org.openide.awt.Toolbar;
79
import org.openide.awt.Toolbar;
75
import org.openide.awt.ToolbarPool;
80
import org.openide.awt.ToolbarPool;
76
import org.openide.util.Exceptions;
81
import org.openide.util.Exceptions;
Lines 92-99 Link Here
92
    private static final String PROPERTY_CLOSED_TC = "closedTopComponents"; // NOI18N
97
    private static final String PROPERTY_CLOSED_TC = "closedTopComponents"; // NOI18N
93
98
94
    private List<DebuggerEngine> openedGroups = new LinkedList<DebuggerEngine>();
99
    private List<DebuggerEngine> openedGroups = new LinkedList<DebuggerEngine>();
95
    private final Map<DebuggerEngine, List<? extends Component>> openedComponents = new HashMap<DebuggerEngine, List<? extends Component>>();
100
    //private final Map<DebuggerEngine, List<? extends Component>> openedComponents = new HashMap<DebuggerEngine, List<? extends Component>>();
96
    private Set<Reference<Component>> componentsInitiallyOpened = new HashSet<Reference<Component>>();
101
    private final Map<DebuggerEngine, Map<EngineComponentsProvider, List<? extends ComponentInfo>>> openedComponents =
102
            new HashMap<DebuggerEngine, Map<EngineComponentsProvider, List<? extends ComponentInfo>>>();
103
    private static final Set<Reference<Component>> componentsInitiallyOpened = new HashSet<Reference<Component>>();
97
    private final Map<DebuggerEngine, List<? extends Component>> closedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>();
104
    private final Map<DebuggerEngine, List<? extends Component>> closedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>();
98
    private final Map<DebuggerEngine, List<? extends Component>> usedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>();
105
    private final Map<DebuggerEngine, List<? extends Component>> usedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>();
99
    private final Map<Component, Dimension> toolbarButtonsPrefferedSize = new HashMap<Component, Dimension>();
106
    private final Map<Component, Dimension> toolbarButtonsPrefferedSize = new HashMap<Component, Dimension>();
Lines 101-107 Link Here
101
    private ToolbarContainerListener toolbarContainerListener;
108
    private ToolbarContainerListener toolbarContainerListener;
102
    private static final RequestProcessor RP = new RequestProcessor("Debugger Engine Setup", 1);        // NOI18N
109
    private static final RequestProcessor RP = new RequestProcessor("Debugger Engine Setup", 1);        // NOI18N
103
110
104
    private static final List<Component> OPENED_COMPONENTS = new LinkedList<Component>();
111
    private static final List<ComponentInfo> OPENED_COMPONENTS = new LinkedList<ComponentInfo>();
105
112
106
    @Override
113
    @Override
107
    public void engineAdded (DebuggerEngine engine) {
114
    public void engineAdded (DebuggerEngine engine) {
Lines 116-125 Link Here
116
            }
123
            }
117
            final List<? extends BeanContextChildComponentProxy> componentProxies =
124
            final List<? extends BeanContextChildComponentProxy> componentProxies =
118
                    engine.lookup(null, BeanContextChildComponentProxy.class);
125
                    engine.lookup(null, BeanContextChildComponentProxy.class);
126
            final List<? extends EngineComponentsProvider> componentsProvidersL = engine.lookup(null, EngineComponentsProvider.class);
119
            //final List<? extends TopComponent> windowsToOpen = engine.lookup(null, TopComponent.class);
127
            //final List<? extends TopComponent> windowsToOpen = engine.lookup(null, TopComponent.class);
120
            if (componentProxies != null && !componentProxies.isEmpty()) {
128
            if (!componentProxies.isEmpty() || !componentsProvidersL.isEmpty()) {
121
                final List<Component> componentsToOpen = new ArrayList<Component>(componentProxies.size());
129
                final Map<EngineComponentsProvider, List<? extends ComponentInfo>> componentsToOpen =
122
                componentsToOpen.add(new java.awt.Label("EMPTY"));
130
                        new LinkedHashMap<EngineComponentsProvider, List<? extends ComponentInfo>>();
131
                componentsToOpen.put(null, null); // Going to initialize...
123
                if (openedComponents.isEmpty() && openedGroups.isEmpty()) {
132
                if (openedComponents.isEmpty() && openedGroups.isEmpty()) {
124
                    fillOpenedDebuggerComponents(componentsInitiallyOpened);
133
                    fillOpenedDebuggerComponents(componentsInitiallyOpened);
125
                }
134
                }
Lines 130-177 Link Here
130
                rp.post (new Runnable () {
139
                rp.post (new Runnable () {
131
                    @Override
140
                    @Override
132
                    public void run () {
141
                    public void run () {
133
                        List<Component> cs = new ArrayList<Component>(componentProxies.size());
142
                        final Map<EngineComponentsProvider, List<? extends ComponentInfo>> ecs =
143
                                new LinkedHashMap<EngineComponentsProvider, List<? extends ComponentInfo>>();
144
                        final List<ComponentInfo> cs = new ArrayList<ComponentInfo>();
134
                        try {
145
                        try {
135
                            final List<TopComponent> topComponentsToOpen = new ArrayList<TopComponent>(componentProxies.size());
146
                            final List<? extends EngineComponentsProvider> componentsProviders;
136
                            for (final BeanContextChildComponentProxy cp : componentProxies) {
147
                            if (!componentProxies.isEmpty()) {
137
                                final Component[] c = new Component[] { null };
148
                                BeanContextComponentProvider bccp = new BeanContextComponentProvider(componentProxies);
138
                                final boolean[] doOpen = new boolean[] { false };
149
                                if (componentsProvidersL.isEmpty()) {
139
                                try {
150
                                    componentsProviders = Collections.singletonList(bccp);
140
                                    SwingUtilities.invokeAndWait(new Runnable() {
151
                                } else {
141
                                        @Override
152
                                    List<EngineComponentsProvider> cps = new ArrayList<EngineComponentsProvider>(componentsProvidersL.size() + 1);
142
                                        public void run() {
153
                                    cps.addAll(componentsProvidersL);
143
                                            c[0] = cp.getComponent();
154
                                    cps.add(bccp);
144
                                            doOpen[0] = (cp instanceof DesignMode) ? ((DesignMode) cp).isDesignTime() : true;
155
                                    componentsProviders = Collections.unmodifiableList(cps);
156
                                }
157
                            } else {
158
                                componentsProviders = componentsProvidersL;
159
                            }
160
                            final Map<TopComponent, ComponentInfo> topComponentsToOpen = new LinkedHashMap<TopComponent, ComponentInfo>();
161
                            for (EngineComponentsProvider ecp : componentsProviders) {
162
                                List<ComponentInfo> cis = ecp.getComponents();
163
                                for (final ComponentInfo ci : cis) {
164
                                    if (ci.isOpened()) {
165
                                        try {
166
                                            SwingUtilities.invokeAndWait(new Runnable() {
167
                                                @Override
168
                                                public void run() {
169
                                                    Component c = ci.getComponent();
170
                                                    if (c instanceof TopComponent) {
171
                                                        topComponentsToOpen.put((TopComponent) c, ci);
172
                                                    } else {
173
                                                        c.setVisible(true);
174
                                                    }
175
                                                }
176
                                            });
177
                                        } catch (Exception ex) {
178
                                            Exceptions.printStackTrace(ex);
179
                                            continue;
145
                                        }
180
                                        }
146
                                    });
147
                                    if (c[0] == null) {
148
                                        //throw new NullPointerException("No component from "+cp);
149
                                        continue;
150
                                    }
181
                                    }
151
                                } catch (Exception ex) {
182
                                    cs.add(ci);
152
                                    Exceptions.printStackTrace(ex);
153
                                    continue;
154
                                }
183
                                }
155
                                cs.add(c[0]);
184
                                ecs.put(ecp, cis);
156
                                if (c[0] instanceof TopComponent) {
157
                                    final TopComponent tc = (TopComponent) c[0];
158
                                    boolean wasClosed = Properties.getDefault().getProperties(DebuggerManagerListener.class.getName()).
159
                                            getProperties(PROPERTY_CLOSED_TC).getBoolean(tc.getName(), false);
160
                                    boolean wasOpened = !Properties.getDefault().getProperties(DebuggerManagerListener.class.getName()).
161
                                            getProperties(PROPERTY_CLOSED_TC).getBoolean(tc.getName(), true);
162
                                    if (doOpen[0] && !wasClosed || !doOpen[0] && wasOpened) {
163
                                        topComponentsToOpen.add(tc);
164
                                    }
165
                                } else {
166
                                    if (doOpen[0]) {
167
                                        SwingUtilities.invokeLater(new Runnable() {
168
                                            @Override
169
                                            public void run() {
170
                                                c[0].setVisible(true);
171
                                            }
172
                                        });
173
                                    }
174
                                }
175
                            }
185
                            }
176
                            if (topComponentsToOpen.size() > 0) {
186
                            if (topComponentsToOpen.size() > 0) {
177
                                SwingUtilities.invokeLater(new Runnable() {
187
                                SwingUtilities.invokeLater(new Runnable() {
Lines 184-202 Link Here
184
                        } finally {
194
                        } finally {
185
                            synchronized (openedComponents) {
195
                            synchronized (openedComponents) {
186
                                componentsToOpen.clear();
196
                                componentsToOpen.clear();
187
                                componentsToOpen.addAll(cs);
197
                                componentsToOpen.putAll(ecs);
188
                                openedComponents.notifyAll();
198
                                openedComponents.notifyAll();
189
                            }
199
                            }
190
                            synchronized (OPENED_COMPONENTS) {
200
                            synchronized (OPENED_COMPONENTS) {
201
                                OPENED_COMPONENTS.addAll(cs);
202
                                /* consider componentsInitiallyOpened when closing components from OPENED_COMPONENTS
203
                                 * instead of this:
191
                                if (componentsInitiallyOpened.isEmpty()) {
204
                                if (componentsInitiallyOpened.isEmpty()) {
192
                                    OPENED_COMPONENTS.addAll(cs);
205
                                    OPENED_COMPONENTS.addAll(cs);
193
                                } else {
206
                                } else {
194
                                    List<Component> ocs = new ArrayList<Component>(cs);
207
                                    List<ComponentInfo> ocs = new ArrayList<ComponentInfo>(cs);
195
                                    for (Reference<Component> cref : componentsInitiallyOpened) {
208
                                    for (Reference<Component> cref : componentsInitiallyOpened) {
196
                                        ocs.remove(cref.get());
209
                                        ocs.remove(cref.get());
197
                                    }
210
                                    }
198
                                    OPENED_COMPONENTS.addAll(ocs);
211
                                    OPENED_COMPONENTS.addAll(ocs);
199
                                }
212
                                }
213
                                */
200
                            }
214
                            }
201
                        }
215
                        }
202
                    }
216
                    }
Lines 231-241 Link Here
231
        }
245
        }
232
    }
246
    }
233
247
234
    private void openTopComponents(List<TopComponent> components) {
248
    private void openTopComponents(Map<TopComponent, ComponentInfo> components) {
235
        assert SwingUtilities.isEventDispatchThread();
249
        assert SwingUtilities.isEventDispatchThread();
236
        Set<Mode> modesWithVisibleTC = new HashSet<Mode>();
250
        Set<Mode> modesWithVisibleTC = new HashSet<Mode>();
237
        for (TopComponent tc : components) {
251
        for (Map.Entry<TopComponent, ComponentInfo> tci : components.entrySet()) {
252
            TopComponent tc = tci.getKey();
253
            ComponentInfo ci = tci.getValue();
238
            tc.open();
254
            tc.open();
255
            if (ci.isMinimized()) {
256
                WindowManager.getDefault().setTopComponentMinimized(tc, true);
257
            }
239
            Mode mode = WindowManager.getDefault().findMode(tc);
258
            Mode mode = WindowManager.getDefault().findMode(tc);
240
            if (modesWithVisibleTC.add(mode)) {
259
            if (modesWithVisibleTC.add(mode)) {
241
                TopComponent tcSel = mode.getSelectedTopComponent();
260
                TopComponent tcSel = mode.getSelectedTopComponent();
Lines 375-404 Link Here
375
    public void engineRemoved (DebuggerEngine engine) {
394
    public void engineRemoved (DebuggerEngine engine) {
376
        //boolean doCloseToolbar = false;
395
        //boolean doCloseToolbar = false;
377
        synchronized (openedComponents) {
396
        synchronized (openedComponents) {
378
            List<? extends Component> openedWindows = openedComponents.remove(engine);
397
            final Map<EngineComponentsProvider, List<? extends ComponentInfo>> openedWindowsByProvider = openedComponents.remove(engine);
379
            if (openedWindows != null) {
398
            if (openedWindowsByProvider != null) {
380
                // If it's not filled yet by AWT, wait...
399
                // If it's not filled yet by AWT, wait...
381
                if (openedWindows.size() == 1 && openedWindows.get(0) instanceof java.awt.Label) {
400
                if (openedWindowsByProvider.size() == 1 && openedWindowsByProvider.get(0) == null) {
382
                    try {
401
                    try {
383
                       openedComponents.wait();
402
                       openedComponents.wait();
384
                    } catch (InterruptedException iex) {}
403
                    } catch (InterruptedException iex) {}
385
                }
404
                }
405
                List<ComponentInfo> openedWindows = new ArrayList<ComponentInfo>();
406
                for (List<? extends ComponentInfo> lci : openedWindowsByProvider.values()) {
407
                    openedWindows.addAll(lci);
408
                }
386
                // Check whether the component is opened by some other engine...
409
                // Check whether the component is opened by some other engine...
387
                final List<Component> retainOpened = new ArrayList<Component>();
410
                final List<ComponentInfo> retainOpened = new ArrayList<ComponentInfo>();
388
                for (List<? extends Component> ltc : openedComponents.values()) {
411
                for (Map<EngineComponentsProvider, List<? extends ComponentInfo>> meci : openedComponents.values()) {
389
                    retainOpened.addAll(ltc);
412
                    for (List<? extends ComponentInfo> lci : meci.values()){
413
                        retainOpened.addAll(lci);
414
                    }
390
                }
415
                }
391
                final List<Component> windowsToClose = new ArrayList<Component>(openedWindows);
416
                final List<Component> initiallyOpened = new ArrayList<Component>();
392
                windowsToClose.removeAll(retainOpened);
393
                for (Reference<Component> cref : componentsInitiallyOpened) {
417
                for (Reference<Component> cref : componentsInitiallyOpened) {
394
                    windowsToClose.remove(cref.get());
418
                    Component c = cref.get();
419
                    if (c != null) {
420
                        initiallyOpened.add(c);
421
                    }
395
                }
422
                }
396
                if (!windowsToClose.isEmpty()) {
423
                final List<ComponentInfo> windowsToClose = new ArrayList<ComponentInfo>(openedWindows);
397
                    SwingUtilities.invokeLater (new Runnable () {
424
                //windowsToClose.removeAll(retainOpened);
425
                try {
426
                    SwingUtilities.invokeAndWait(new Runnable() {
398
                        @Override
427
                        @Override
399
                        public void run () {
428
                        public void run() {
429
                            List<Component> retainOpenedComponents = new ArrayList<Component>(retainOpened.size());
430
                            for (ComponentInfo ci : retainOpened) {
431
                                retainOpenedComponents.add(ci.getComponent());
432
                            }
433
                            for (Component c : initiallyOpened) {
434
                                if (c != null) {
435
                                    retainOpenedComponents.add(c);
436
                                }
437
                            }
438
                            List<ComponentInfo> windowsToCloseCopy = (ArrayList<ComponentInfo>) ((ArrayList) windowsToClose).clone();
439
                            for (ComponentInfo ci : windowsToCloseCopy) {
440
                                Component c = ci.getComponent();
441
                                if (retainOpenedComponents.contains(c)) {
442
                                    windowsToClose.remove(ci);
443
                                }
444
                            }
445
                            for (EngineComponentsProvider ecp : openedWindowsByProvider.keySet()) {
446
                                List<? extends ComponentInfo> cis = openedWindowsByProvider.get(ecp);
447
                                List<ComponentInfo> closing = new ArrayList<ComponentInfo>(cis);
448
                                closing.retainAll(windowsToClose);
449
                                ecp.willCloseNotify(closing);
450
                            }
400
                            final List<TopComponent> topComponentsToClose = new ArrayList<TopComponent>(windowsToClose.size());
451
                            final List<TopComponent> topComponentsToClose = new ArrayList<TopComponent>(windowsToClose.size());
401
                            for (Component c : windowsToClose) {
452
                            for (ComponentInfo ci : windowsToClose) {
453
                                Component c = ci.getComponent();
402
                                if (c instanceof TopComponent) {
454
                                if (c instanceof TopComponent) {
403
                                    TopComponent tc = (TopComponent) c;
455
                                    TopComponent tc = (TopComponent) c;
404
                                    boolean isOpened = tc.isOpened();
456
                                    boolean isOpened = tc.isOpened();
Lines 414-419 Link Here
414
                            closeTopComponentsList(topComponentsToClose);
466
                            closeTopComponentsList(topComponentsToClose);
415
                        }
467
                        }
416
                    });
468
                    });
469
                } catch (Exception exc) {
470
                    Exceptions.printStackTrace(exc);
417
                }
471
                }
418
                synchronized (OPENED_COMPONENTS) {
472
                synchronized (OPENED_COMPONENTS) {
419
                    OPENED_COMPONENTS.removeAll(windowsToClose);
473
                    OPENED_COMPONENTS.removeAll(windowsToClose);
Lines 435-440 Link Here
435
            }
489
            }
436
            if (openedComponents.isEmpty() && openedGroups.isEmpty()) {
490
            if (openedComponents.isEmpty() && openedGroups.isEmpty()) {
437
                componentsInitiallyOpened.clear();
491
                componentsInitiallyOpened.clear();
492
                synchronized (OPENED_COMPONENTS) {
493
                    OPENED_COMPONENTS.clear();
494
                }
438
                /*doCloseToolbar = true;
495
                /*doCloseToolbar = true;
439
                SwingUtilities.invokeLater (new Runnable () {
496
                SwingUtilities.invokeLater (new Runnable () {
440
                    public void run () {
497
                    public void run () {
Lines 568-581 Link Here
568
            group.close ();
625
            group.close ();
569
        }
626
        }
570
        synchronized (OPENED_COMPONENTS) {
627
        synchronized (OPENED_COMPONENTS) {
571
            for (Component c : OPENED_COMPONENTS) {
628
            final List<Component> initiallyOpened;
629
            if (componentsInitiallyOpened.isEmpty()) {
630
                initiallyOpened = Collections.EMPTY_LIST;
631
            } else {
632
                initiallyOpened = new ArrayList<Component>();
633
                for (Reference<Component> cref : componentsInitiallyOpened) {
634
                    Component c = cref.get();
635
                    if (c != null) {
636
                        initiallyOpened.add(c);
637
                    }
638
                }
639
            }
640
            for (ComponentInfo ci : OPENED_COMPONENTS) {
641
                Component c = ci.getComponent();
642
                if (initiallyOpened.contains(c)) {
643
                    continue;
644
                }
572
                if (c instanceof TopComponent) {
645
                if (c instanceof TopComponent) {
646
                    /* To check which components we're closing:
647
                    try {
648
                        Method pid = TopComponent.class.getDeclaredMethod("preferredID");
649
                        pid.setAccessible(true);
650
                    System.err.println("doCloseDebuggerUI("+pid.invoke(c)+")");
651
                    } catch (Exception ex) {
652
                        ex.printStackTrace();
653
                    }
654
                    */
573
                    ((TopComponent) c).close();
655
                    ((TopComponent) c).close();
574
                } else {
656
                } else {
575
                    c.setVisible(false);
657
                    c.setVisible(false);
576
                }
658
                }
577
            }
659
            }
578
            OPENED_COMPONENTS.clear();
660
            OPENED_COMPONENTS.clear();
661
            componentsInitiallyOpened.clear();
579
        }
662
        }
580
        ToolbarPool.getDefault().waitFinished();
663
        ToolbarPool.getDefault().waitFinished();
581
        if (ToolbarPool.getDefault().getConfiguration().equals("Debugging")) { // NOI18N
664
        if (ToolbarPool.getDefault().getConfiguration().equals("Debugging")) { // NOI18N
Lines 672-676 Link Here
672
        }
755
        }
673
        
756
        
674
    }
757
    }
758
    
759
    private static class BeanContextComponentProvider implements EngineComponentsProvider {
760
        
761
        private final List<? extends BeanContextChildComponentProxy> componentProxies;
762
        
763
        public BeanContextComponentProvider(List<? extends BeanContextChildComponentProxy> componentProxies) {
764
            this.componentProxies = componentProxies;
765
        }
766
767
        @Override
768
        public List<ComponentInfo> getComponents() {
769
            return ComponentInfoFromBeanContext.transform(componentProxies);
770
        }
771
772
        @Override
773
        public void willCloseNotify(List<ComponentInfo> components) {
774
            ComponentInfoFromBeanContext.closing(components);
775
        }
776
        
777
    }
675
778
676
}
779
}
(-)a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/EngineComponentsProvider.java (+220 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.spi.debugger.ui;
43
44
import java.awt.Component;
45
import java.util.List;
46
import org.netbeans.modules.debugger.ui.ComponentInfoFromBeanContext;
47
import org.netbeans.spi.debugger.DebuggerServiceRegistration;
48
import org.openide.windows.TopComponent;
49
import org.openide.windows.WindowManager;
50
51
/**
52
 * Provider of components associated with a debugger engine.
53
 * An instance of this class needs to be registered under the appropriate session/engine
54
 * ID path by {@link DebuggerServiceRegistration}.
55
 * <p>
56
 * The provided components are checked when the appropriate debugger engine is started
57
 * and opened if necessary. After the debugger engine is finished,
58
 * {@link EngineComponentsProvider#willCloseNotify(java.util.List)} is called
59
 * with components that are not used by other running engines and which are subsequently
60
 * closed.
61
 * 
62
 * @author Martin Entlicher
63
 * @since 2.35
64
 */
65
public interface EngineComponentsProvider {
66
    
67
    /**
68
     * Provide a list of components associated with the debugger engine.
69
     * The components are opened when the debugger engine starts and closed
70
     * when the debugger engine finishes.
71
     * 
72
     * @return The list of components associated with the debugger engine.
73
     */
74
    List<ComponentInfo> getComponents();
75
    
76
    /**
77
     * This method is called when the debugger engine finishes with the list
78
     * of components that are about to be closed.
79
     * The implementation might test them for opened state to decide if they
80
     * should be opened the next time when {@link #getComponents()} is called.
81
     * @param components The components that are to be closed. It's guaranteed
82
     * that only components returned by {@link #getComponents()} are passed in
83
     * and only those, that are not needed by another running engine.
84
     */
85
    void willCloseNotify(List<ComponentInfo> components);
86
    
87
    /**
88
     * Information about a component associated with a debugger engine.
89
     */
90
    public static final class ComponentInfo {
91
        
92
        static {
93
            initHelperTransform();
94
        }
95
        
96
        private final ComponentProvider provider;
97
        private final boolean opened;
98
        private final boolean minimized;
99
        //private int order = Integer.MAX_VALUE;
100
        
101
        private ComponentInfo(ComponentProvider provider, boolean opened, boolean minimized) {
102
            this.provider = provider;
103
            this.opened = opened;
104
            this.minimized = minimized;
105
        }
106
        
107
        /**
108
         * Get the component.
109
         * @return The component
110
         */
111
        public Component getComponent() {
112
            return provider.getComponent();
113
        }
114
        
115
        /**
116
         * Test if the component is to be opened when the debugger engine starts.
117
         * @return <code>true</code> when this component is to be opened on engine start,
118
         *         <code>false</code> otherwise.
119
         */
120
        public boolean isOpened() {
121
            return opened;
122
        }
123
        
124
        /**
125
         * Test if the component is to be opened in a minimized state when the
126
         * debugger engine starts.
127
         * @return <code>true</code> when this component is to be opened in a minimized state,
128
         *         <code>false</code> otherwise.
129
         */
130
        public boolean isMinimized() {
131
            return minimized;
132
        }
133
        
134
        /* can be added when needed
135
        public void setOrder(int order) {
136
            this.order = order;
137
        }
138
        
139
        public int getOrder() {
140
            return order;
141
        }
142
        */
143
        
144
        /* When generic Component support is required
145
        public static ComponentInfo create(ComponentProvider componentProvider) {
146
            return new ComponentInfo(componentProvider);
147
        }
148
        */
149
        
150
        /**
151
         * Create a component information about a {@link TopComponent},
152
         * which is opened by default.
153
         * @param tcName The ID of the {@link TopComponent}
154
         * @return A component information.
155
         */
156
        public static ComponentInfo create(String tcId) {
157
            return create(tcId, true);
158
        }
159
        
160
        /**
161
         * Create a component information about a {@link TopComponent}.
162
         * @param tcName The ID of the {@link TopComponent}
163
         * @param opened <code>true</code> if the component should be opened,
164
         *               <code>false</code> otherwise.
165
         * @return A component information.
166
         */
167
        public static ComponentInfo create(String tcId, boolean opened) {
168
            return create(tcId, opened, false);
169
        }
170
        
171
        /**
172
         * Create a component information about a {@link TopComponent}.
173
         * @param tcName The ID of the {@link TopComponent}
174
         * @param opened <code>true</code> if the component should be opened,
175
         *               <code>false</code> otherwise.
176
         * @param minimized <code>true</code> if the component should be opened in a minimized state,
177
         *                  <code>false</code> otherwise.
178
         * @return A component information.
179
         */
180
        public static ComponentInfo create(String tcId, boolean opened, boolean minimized) {
181
            return new ComponentInfo(new TopComponentProvider(tcId), opened, minimized);
182
        }
183
        
184
        private static void initHelperTransform() {
185
            ComponentInfoFromBeanContext.TRANSFORM = new ComponentInfoFromBeanContext.Transform() {
186
                @Override
187
                public ComponentInfo transform(final Component c, boolean opened) {
188
                    return new ComponentInfo(new ComponentProvider() {
189
                        @Override
190
                        public Component getComponent() {
191
                            return c;
192
                        }
193
                    }, opened, false);
194
                }
195
            };
196
        }
197
        
198
    }
199
    
200
    /*public - when generic Component suport is required. */
201
    static interface ComponentProvider {
202
        
203
        Component getComponent();
204
    }
205
    
206
    static class TopComponentProvider implements ComponentProvider {
207
        
208
        private final String tcId;
209
        
210
        private TopComponentProvider(String tcId) {
211
            this.tcId = tcId;
212
        }
213
214
        @Override
215
        public java.awt.Component getComponent() {
216
            return WindowManager.getDefault().findTopComponent(tcId);
217
        }
218
    }
219
    
220
}
(-)a/spi.debugger.ui/test/unit/src/org/netbeans/spi/debugger/ui/EngineComponentsProviderTest.java (+116 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.spi.debugger.ui;
43
44
import java.awt.Component;
45
import java.lang.reflect.InvocationTargetException;
46
import java.lang.reflect.Method;
47
import javax.swing.SwingUtilities;
48
import junit.framework.Test;
49
import junit.framework.TestCase;
50
import org.netbeans.api.debugger.DebuggerApiTestBase;
51
import org.netbeans.junit.NbModuleSuite;
52
import org.netbeans.spi.debugger.ui.EngineComponentsProvider.ComponentInfo;
53
import org.openide.windows.TopComponent;
54
55
/**
56
 *
57
 * @author Martin
58
 */
59
public class EngineComponentsProviderTest extends DebuggerApiTestBase {
60
    
61
    public EngineComponentsProviderTest(String s) {
62
        super(s);
63
    }
64
    
65
    public static Test suite() {
66
        return EngineComponentsProviderTest.createTestSuite(EngineComponentsProviderTest.class);
67
    }
68
69
    public void testCreateTC() throws Throwable {
70
        ComponentInfo ciVar = EngineComponentsProvider.ComponentInfo.create("localsView");
71
        checkComponentInfo(ciVar, true, false, "org.netbeans.modules.debugger.ui.views.LocalsView");
72
        
73
        ComponentInfo ciWatch = EngineComponentsProvider.ComponentInfo.create("watchesView", false);
74
        checkComponentInfo(ciWatch, false, false, "org.netbeans.modules.debugger.ui.views.WatchesView");
75
        
76
        ComponentInfo ciCS = EngineComponentsProvider.ComponentInfo.create("callstackView", false, true);
77
        checkComponentInfo(ciCS, false, true, "org.netbeans.modules.debugger.ui.views.CallStackView");
78
    }
79
    
80
    private void checkComponentInfo(final ComponentInfo ci,
81
                                    boolean opened, boolean minimized,
82
                                    final String ID) throws Throwable {
83
        assertEquals("Opened", opened, ci.isOpened());
84
        assertEquals("Minimized", minimized, ci.isMinimized());
85
        try {
86
            SwingUtilities.invokeAndWait(new Runnable() {
87
                @Override
88
                public void run() {
89
                    Component c = ci.getComponent();
90
                    assertTrue("Is TopComponent:", c instanceof TopComponent);
91
                    TopComponent tc = (TopComponent) c;
92
                    try {
93
                        Method pid = TopComponent.class.getDeclaredMethod("preferredID");
94
                        pid.setAccessible(true);
95
                        String tcId = (String) pid.invoke(tc);
96
                        //System.err.println("tcId = "+tcId);
97
                        assertEquals("TopComponent preferredID:", ID, tcId);
98
                    } catch (Exception ex) {
99
                        throw new RuntimeException(ex);
100
                    }
101
                }
102
            });
103
        } catch (InvocationTargetException itex) {
104
            Thread.dumpStack();
105
            throw itex.getTargetException();
106
        }
107
    }
108
109
    public static Test createTestSuite(Class<? extends TestCase> clazz) {
110
        NbModuleSuite.Configuration suiteConfiguration = NbModuleSuite.createConfiguration(clazz);
111
        suiteConfiguration = suiteConfiguration.gui(false);
112
        //suiteConfiguration = suiteConfiguration.reuseUserDir(false);
113
        return NbModuleSuite.create(suiteConfiguration);
114
    }
115
116
}
(-)a/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/EngineComponentsProviderImpl.java (+123 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.modules.web.javascript.debugger;
43
44
import java.awt.Component;
45
import java.lang.reflect.Method;
46
import java.util.ArrayList;
47
import java.util.List;
48
import java.util.prefs.Preferences;
49
import org.netbeans.api.debugger.Properties;
50
import org.netbeans.spi.debugger.ContextProvider;
51
import org.netbeans.spi.debugger.DebuggerServiceRegistration;
52
import org.netbeans.spi.debugger.ui.EngineComponentsProvider;
53
import org.openide.util.NbPreferences;
54
import org.openide.windows.TopComponent;
55
56
/**
57
 * Provider of debugger GUI components needed for JavaScript Debugger,
58
 * minimized initially.
59
 * 
60
 * @author Martin Entlicher
61
 */
62
@DebuggerServiceRegistration(path="javascript-debuggerengine", types=EngineComponentsProvider.class)
63
public class EngineComponentsProviderImpl implements EngineComponentsProvider {
64
    
65
    private static final String PROPERTY_CLOSED_TC = "closedTopComponents"; // NOI18N
66
    private static final String PROPERTY_BASE_NAME = "javascript-debuggerengine.EngineComponentsProvider";   // NOI18N
67
68
    private static final String[] DBG_COMPONENTS_OPENED = {
69
        "localsView", "watchesView", "callstackView", "breakpointsView",
70
    };
71
    private static final String[] DBG_COMPONENTS_CLOSED = {
72
        "evaluator", "resultsView", "sessionsView",
73
    };
74
75
    @Override
76
    public List<ComponentInfo> getComponents() {
77
        List<ComponentInfo> components = new ArrayList<ComponentInfo>(DBG_COMPONENTS_OPENED.length + DBG_COMPONENTS_CLOSED.length);
78
        for (String cid : DBG_COMPONENTS_OPENED) {
79
            components.add(EngineComponentsProvider.ComponentInfo.create(
80
                    cid, isOpened(cid, true), true));
81
        }
82
        for (String cid : DBG_COMPONENTS_CLOSED) {
83
            components.add(EngineComponentsProvider.ComponentInfo.create(
84
                    cid, isOpened(cid, false), true));
85
        }
86
        return components;
87
    }
88
    
89
    private static boolean isOpened(String cid, boolean open) {
90
        if (cid.equals("watchesView")) {
91
            Preferences preferences = NbPreferences.forModule(ContextProvider.class).node("variables_view"); // NOI18N
92
            open = !preferences.getBoolean("show_watches", true); // NOI18N
93
        }
94
        boolean wasClosed = Properties.getDefault().getProperties(PROPERTY_BASE_NAME).
95
                getProperties(PROPERTY_CLOSED_TC).getBoolean(cid, false);
96
        boolean wasOpened = !Properties.getDefault().getProperties(PROPERTY_BASE_NAME).
97
                getProperties(PROPERTY_CLOSED_TC).getBoolean(cid, true);
98
        open = (open && !wasClosed || !open && wasOpened);
99
        return open;
100
    }
101
102
    @Override
103
    public void willCloseNotify(List<ComponentInfo> components) {
104
        for (ComponentInfo ci : components) {
105
            Component c = ci.getComponent();
106
            if (c instanceof TopComponent) {
107
                TopComponent tc = (TopComponent) c;
108
                /*
109
                try {
110
                    Method pid = TopComponent.class.getDeclaredMethod("preferredID");
111
                    pid.setAccessible(true);
112
                    System.err.println("JS EngineComponentsProviderImpl.closing("+pid.invoke(tc)+") name = "+tc.getName());
113
                } catch (Exception ex) {
114
                    ex.printStackTrace();
115
                }*/
116
                boolean isOpened = tc.isOpened();
117
                Properties.getDefault().getProperties(PROPERTY_BASE_NAME).
118
                        getProperties(PROPERTY_CLOSED_TC).setBoolean(tc.getName(), !isOpened);
119
            }
120
        }
121
    }
122
    
123
}

Return to bug 217953