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

(-)a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/JPDABreakpointsActivation.java (+116 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 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 2015 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.debugger.jpda.breakpoints;
44
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
47
import java.util.Collections;
48
import java.util.HashMap;
49
import java.util.Map;
50
import org.netbeans.api.debugger.ActiveBreakpoints;
51
import org.netbeans.api.debugger.jpda.JPDADebugger;
52
import org.netbeans.spi.debugger.BreakpointsActivationProvider;
53
import org.netbeans.spi.debugger.ContextProvider;
54
import org.netbeans.spi.debugger.DebuggerServiceRegistration;
55
56
/**
57
 * JPDA activation/deactivation of breakpoints.
58
 * 
59
 * @author Martin Entlicher
60
 */
61
@DebuggerServiceRegistration(path="netbeans-JPDASession", types = BreakpointsActivationProvider.class)
62
public class JPDABreakpointsActivation implements BreakpointsActivationProvider {
63
    
64
    private final JPDADebugger debugger;
65
    private final Map<PropertyChangeListener, DelegateListener> listenersMap = Collections.synchronizedMap(new HashMap<PropertyChangeListener, DelegateListener>());
66
    
67
    public JPDABreakpointsActivation(ContextProvider contextProvider) {
68
        this.debugger = contextProvider.lookupFirst(null, JPDADebugger.class);
69
    }
70
71
    @Override
72
    public boolean areBreakpointsActive() {
73
        return debugger.getBreakpointsActive();
74
    }
75
76
    @Override
77
    public void setBreakpointsActive(boolean active) {
78
        debugger.setBreakpointsActive(active);
79
    }
80
81
    @Override
82
    public void addPropertyChangeListener(final PropertyChangeListener l) {
83
        DelegateListener dl = new DelegateListener(this, l);
84
        listenersMap.put(l, dl);
85
        debugger.addPropertyChangeListener(JPDADebugger.PROP_BREAKPOINTS_ACTIVE, dl);
86
    }
87
88
    @Override
89
    public void removePropertyChangeListener(PropertyChangeListener l) {
90
        DelegateListener dl = listenersMap.remove(l);
91
        if (dl != null) {
92
            debugger.removePropertyChangeListener(JPDADebugger.PROP_BREAKPOINTS_ACTIVE, dl);
93
        }
94
    }
95
    
96
    private static class DelegateListener implements PropertyChangeListener {
97
        
98
        private final Object source;
99
        private final PropertyChangeListener l;
100
        
101
        public DelegateListener(Object source, PropertyChangeListener l) {
102
            this.source = source;
103
            this.l = l;
104
        }
105
        
106
        @Override
107
        public void propertyChange(PropertyChangeEvent evt) {
108
            l.propertyChange(new PropertyChangeEvent(
109
                    source,
110
                    ActiveBreakpoints.PROP_BREAKPOINTS_ACTIVE,
111
                    evt.getOldValue(),
112
                    evt.getNewValue()));
113
        }
114
    }
115
    
116
}
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/resources/mf-layer.xml (+7 lines)
Lines 575-580 Link Here
575
                        methodvalue="org.netbeans.modules.debugger.ui.models.BreakpointsViewButtons.createNewBreakpointActionButton" name="instanceCreate"/>
575
                        methodvalue="org.netbeans.modules.debugger.ui.models.BreakpointsViewButtons.createNewBreakpointActionButton" name="instanceCreate"/>
576
                    <attr intvalue="100" name="position"/>
576
                    <attr intvalue="100" name="position"/>
577
                </file>
577
                </file>
578
                <file name="org-netbeans-modules-debugger-ui-models-BreakpointsViewButtons-createActivateBreakpointsActionButton.instance">
579
                    <attr name="serviceClass" stringvalue="java.awt.Component"/>
580
                    <attr name="instanceOf" stringvalue="java.awt.Component"/>
581
                    <attr
582
                        methodvalue="org.netbeans.modules.debugger.ui.models.BreakpointsViewButtons.createActivateBreakpointsActionButton" name="instanceCreate"/>
583
                    <attr intvalue="150" name="position"/>
584
                </file>
578
                <file name="org-netbeans-modules-debugger-ui-models-BreakpointsViewButtons-createGroupSelectionButton.instance">
585
                <file name="org-netbeans-modules-debugger-ui-models-BreakpointsViewButtons-createGroupSelectionButton.instance">
579
                    <attr name="serviceClass" stringvalue="java.awt.Component"/>
586
                    <attr name="serviceClass" stringvalue="java.awt.Component"/>
580
                    <attr name="instanceOf" stringvalue="java.awt.Component"/>
587
                    <attr name="instanceOf" stringvalue="java.awt.Component"/>
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/models/BreakpointsViewButtons.java (-1 / +108 lines)
Lines 50-68 Link Here
50
import java.awt.event.ActionListener;
50
import java.awt.event.ActionListener;
51
import java.awt.event.ItemEvent;
51
import java.awt.event.ItemEvent;
52
import java.awt.event.ItemListener;
52
import java.awt.event.ItemListener;
53
import java.beans.PropertyChangeEvent;
54
import java.lang.ref.Reference;
55
import java.lang.ref.WeakReference;
53
import java.util.List;
56
import java.util.List;
54
import javax.swing.AbstractAction;
57
import javax.swing.AbstractAction;
58
import javax.swing.AbstractButton;
55
import javax.swing.Action;
59
import javax.swing.Action;
56
import javax.swing.Icon;
60
import javax.swing.Icon;
61
import javax.swing.ImageIcon;
57
import javax.swing.JButton;
62
import javax.swing.JButton;
58
import javax.swing.JCheckBoxMenuItem;
63
import javax.swing.JCheckBoxMenuItem;
59
import javax.swing.JPopupMenu;
64
import javax.swing.JPopupMenu;
60
import javax.swing.JRadioButtonMenuItem;
65
import javax.swing.JRadioButtonMenuItem;
66
import javax.swing.JToggleButton;
61
import javax.swing.SwingUtilities;
67
import javax.swing.SwingUtilities;
68
import javax.swing.border.EmptyBorder;
69
import org.netbeans.api.debugger.ActiveBreakpoints;
62
import org.netbeans.api.debugger.Breakpoint;
70
import org.netbeans.api.debugger.Breakpoint;
71
import org.netbeans.api.debugger.DebuggerEngine;
63
import org.netbeans.api.debugger.DebuggerManager;
72
import org.netbeans.api.debugger.DebuggerManager;
64
import org.netbeans.api.debugger.DebuggerManagerAdapter;
73
import org.netbeans.api.debugger.DebuggerManagerAdapter;
65
66
import org.netbeans.api.debugger.Properties;
74
import org.netbeans.api.debugger.Properties;
67
import org.netbeans.api.debugger.Session;
75
import org.netbeans.api.debugger.Session;
68
import org.netbeans.api.project.Project;
76
import org.netbeans.api.project.Project;
Lines 84-89 Link Here
84
92
85
    public static final String PREFERENCES_NAME = "variables_view"; // NOI18N
93
    public static final String PREFERENCES_NAME = "variables_view"; // NOI18N
86
    public static final String SHOW_VALUE_AS_STRING = "show_value_as_string"; // NOI18N
94
    public static final String SHOW_VALUE_AS_STRING = "show_value_as_string"; // NOI18N
95
    private static final String DEACTIVATED_LINE_BREAKPOINT =
96
        "org/netbeans/modules/debugger/resources/editor/Breakpoint_stroke.png";                 // NOI18N
87
97
88
    public static JButton createNewBreakpointActionButton() {
98
    public static JButton createNewBreakpointActionButton() {
89
        JButton button = VariablesViewButtons.createButton(
99
        JButton button = VariablesViewButtons.createButton(
Lines 97-102 Link Here
97
        });
107
        });
98
        return button;
108
        return button;
99
    }
109
    }
110
    
111
    @NbBundle.Messages({"CTL_DeactivateAllBreakpoints=Deactivate all breakpoints in current session",
112
                        "CTL_ActivateAllBreakpoints=Activate all breakpoints in current session",
113
                        "CTL_NoDeactivation=The current session does not allow to deactivate breakpoints",
114
                        "CTL_NoSession=No debugger session"})
115
    public static AbstractButton createActivateBreakpointsActionButton() {
116
        ImageIcon icon = ImageUtilities.loadImageIcon(DEACTIVATED_LINE_BREAKPOINT, false);
117
        final JToggleButton button = new JToggleButton(icon);
118
        // ensure small size, just for the icon
119
        Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
120
        button.setPreferredSize(size);
121
        button.setMargin(new Insets(1, 1, 1, 1));
122
        button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
123
        button.setToolTipText(Bundle.CTL_DeactivateAllBreakpoints());
124
        button.setFocusable(false);
125
        final BreakpointsActivator ba = new BreakpointsActivator(button);
126
        button.addActionListener(ba);
127
        DebuggerManager.getDebuggerManager().addDebuggerListener(DebuggerManager.PROP_CURRENT_ENGINE, new DebuggerManagerAdapter() {
128
            @Override
129
            public void propertyChange(PropertyChangeEvent evt) {
130
                DebuggerEngine de = (DebuggerEngine) evt.getNewValue();
131
                ba.setCurrentEngine(de);
132
            }
133
        });
134
        ba.setCurrentEngine(DebuggerManager.getDebuggerManager().getCurrentEngine());
135
        return button;
136
    }
137
    
138
    private static class BreakpointsActivator implements ActionListener {
139
        
140
        private final Reference<JToggleButton> buttonRef;
141
        //private DebuggerEngine currentEngine;
142
        private volatile ActiveBreakpoints ab;
143
        //private String name;
144
        
145
        public BreakpointsActivator(JToggleButton button) {
146
            this.buttonRef = new WeakReference<JToggleButton>(button);
147
        }
148
        
149
        public void setCurrentEngine(DebuggerEngine currentEngine) {
150
            //this.currentEngine = currentEngine;
151
            //Session session = currentEngine.lookupFirst(null, Session.class);
152
            //this.name = session.getName();
153
            final JToggleButton button = buttonRef.get();
154
            if (button == null) {
155
                return ;
156
            }
157
            ActiveBreakpoints ab;
158
            final boolean active;
159
            final boolean canDeactivate;
160
            if (currentEngine == null) {
161
                ab = null;
162
                active = canDeactivate = false;
163
            } else {
164
                ab = ActiveBreakpoints.get(currentEngine);
165
                active = ab.areBreakpointsActive();
166
                canDeactivate = ab.canDeactivateBreakpoints();
167
            }
168
            SwingUtilities.invokeLater(new Runnable() {
169
                @Override
170
                public void run() {
171
                    button.setSelected(!active);
172
                    button.setEnabled(canDeactivate);
173
                    setTooltip(button, active, canDeactivate);
174
                }
175
            });
176
            this.ab = ab;
177
        }
178
        
179
        @Override
180
        public void actionPerformed(ActionEvent e) {
181
            ActiveBreakpoints ab = this.ab;
182
            if (ab == null || !ab.canDeactivateBreakpoints()) {
183
                return ;
184
            }
185
            JToggleButton button = (JToggleButton) e.getSource();
186
            final boolean active = !button.isSelected();
187
            ab.setBreakpointsActive(active);
188
            setTooltip(button, active, true);
189
        }
190
        
191
        private static void setTooltip(JToggleButton button, boolean active, boolean canDeactivate) {
192
            if (!canDeactivate) {
193
                if (active) {
194
                    button.setToolTipText(Bundle.CTL_NoDeactivation());
195
                } else {
196
                    button.setToolTipText(Bundle.CTL_NoSession());
197
                }
198
            } else {
199
                if (active) {
200
                    button.setToolTipText(Bundle.CTL_DeactivateAllBreakpoints());
201
                } else {
202
                    button.setToolTipText(Bundle.CTL_ActivateAllBreakpoints());
203
                }
204
            }
205
        }
206
    }
100
207
101
    public static synchronized JButton createGroupSelectionButton() {
208
    public static synchronized JButton createGroupSelectionButton() {
102
        final JButton button = VariablesViewButtons.createButton(
209
        final JButton button = VariablesViewButtons.createButton(
(-)a/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/breakpoints/WebBreakpointsActivation.java (+125 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 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 2015 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.web.javascript.debugger.breakpoints;
44
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
47
import java.util.Collections;
48
import java.util.HashMap;
49
import java.util.Map;
50
import org.netbeans.api.debugger.ActiveBreakpoints;
51
import org.netbeans.modules.web.webkit.debugging.api.Debugger;
52
import org.netbeans.spi.debugger.BreakpointsActivationProvider;
53
import org.netbeans.spi.debugger.ContextProvider;
54
import org.netbeans.spi.debugger.DebuggerServiceRegistration;
55
import org.openide.util.RequestProcessor;
56
57
/**
58
 * WEB JavaScript activation/deactivation of breakpoints.
59
 * 
60
 * @author Martin Entlicher
61
 */
62
@DebuggerServiceRegistration(path="javascript-debuggerengine", types = BreakpointsActivationProvider.class)
63
public class WebBreakpointsActivation implements BreakpointsActivationProvider {
64
65
    private static final RequestProcessor RP = new RequestProcessor(WebBreakpointsActivation.class.getName());
66
    private final Debugger debugger;
67
    private final Map<PropertyChangeListener, DelegateListener> listenersMap = Collections.synchronizedMap(new HashMap<PropertyChangeListener, DelegateListener>());
68
    
69
    public WebBreakpointsActivation(ContextProvider contextProvider) {
70
        this.debugger = contextProvider.lookupFirst(null, Debugger.class);
71
    }
72
73
    @Override
74
    public boolean areBreakpointsActive() {
75
        return debugger.areBreakpointsActive();
76
    }
77
78
    @Override
79
    public void setBreakpointsActive(final boolean active) {
80
        RP.post(new Runnable() {
81
            @Override
82
            public void run() {
83
                debugger.setBreakpointsActive(active);
84
            }
85
        });
86
    }
87
88
    @Override
89
    public void addPropertyChangeListener(final PropertyChangeListener l) {
90
        DelegateListener dl = new DelegateListener(this, l);
91
        listenersMap.put(l, dl);
92
        debugger.addPropertyChangeListener(dl);
93
    }
94
95
    @Override
96
    public void removePropertyChangeListener(PropertyChangeListener l) {
97
        DelegateListener dl = listenersMap.remove(l);
98
        if (dl != null) {
99
            debugger.removePropertyChangeListener(dl);
100
        }
101
    }
102
    
103
    private static class DelegateListener implements PropertyChangeListener {
104
        
105
        private final Object source;
106
        private final PropertyChangeListener l;
107
        
108
        public DelegateListener(Object source, PropertyChangeListener l) {
109
            this.source = source;
110
            this.l = l;
111
        }
112
        
113
        @Override
114
        public void propertyChange(PropertyChangeEvent evt) {
115
            if (Debugger.PROP_BREAKPOINTS_ACTIVE.equals(evt.getPropertyName())) {
116
                l.propertyChange(new PropertyChangeEvent(
117
                        source,
118
                        ActiveBreakpoints.PROP_BREAKPOINTS_ACTIVE,
119
                        evt.getOldValue(),
120
                        evt.getNewValue()));
121
            }
122
        }
123
    }
124
125
}

Return to bug 242800