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

(-)a/php.dbgp/nbproject/project.xml (+9 lines)
Lines 133-138 Link Here
133
                    </run-dependency>
133
                    </run-dependency>
134
                </dependency>
134
                </dependency>
135
                <dependency>
135
                <dependency>
136
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
137
                    <build-prerequisite/>
138
                    <compile-dependency/>
139
                    <run-dependency>
140
                        <release-version>1</release-version>
141
                        <specification-version>1.41</specification-version>
142
                    </run-dependency>
143
                </dependency>
144
                <dependency>
136
                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
145
                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
137
                    <build-prerequisite/>
146
                    <build-prerequisite/>
138
                    <compile-dependency/>
147
                    <compile-dependency/>
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointsReader.java (-30 / +7 lines)
Lines 47-57 Link Here
47
import java.net.URL;
47
import java.net.URL;
48
import org.netbeans.api.debugger.Properties;
48
import org.netbeans.api.debugger.Properties;
49
import org.netbeans.modules.php.dbgp.breakpoints.FunctionBreakpoint.Type;
49
import org.netbeans.modules.php.dbgp.breakpoints.FunctionBreakpoint.Type;
50
import org.openide.cookies.LineCookie;
51
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.URLMapper;
51
import org.openide.filesystems.URLMapper;
53
import org.openide.loaders.DataObject;
54
import org.openide.loaders.DataObjectNotFoundException;
55
import org.openide.text.Line;
52
import org.openide.text.Line;
56
53
57
/**
54
/**
Lines 59-66 Link Here
59
 * @author ads
56
 * @author ads
60
 */
57
 */
61
public class BreakpointsReader implements Properties.Reader {
58
public class BreakpointsReader implements Properties.Reader {
62
    private static final String LINE_NUMBER = "lineNumber"; // NOI18N
59
63
    private static final String URL = "url"; // NOI18N
64
    private static final String ENABED = "enabled"; // NOI18N
60
    private static final String ENABED = "enabled"; // NOI18N
65
    private static final String FUNC_NAME = "functionName"; // NOI18N
61
    private static final String FUNC_NAME = "functionName"; // NOI18N
66
    private static final String TYPE = "type"; // NOI18N
62
    private static final String TYPE = "type"; // NOI18N
Lines 77-83 Link Here
77
    @Override
73
    @Override
78
    public Object read(String typeID, Properties properties) {
74
    public Object read(String typeID, Properties properties) {
79
        if (typeID.equals(LineBreakpoint.class.getName())) {
75
        if (typeID.equals(LineBreakpoint.class.getName())) {
80
            Line line = getLine(properties.getString(URL, null), properties.getInt(LINE_NUMBER, 1));
76
            Line line = getLine(properties.getString(LineBreakpoint.PROP_URL, null), properties.getInt(LineBreakpoint.PROP_LINE_NUMBER, 1));
81
            if (line == null) {
77
            if (line == null) {
82
                return null;
78
                return null;
83
            }
79
            }
Lines 86-91 Link Here
86
                breakpoint.disable();
82
                breakpoint.disable();
87
            }
83
            }
88
            breakpoint.setGroupName(properties.getString(GROUP_NAME, ""));
84
            breakpoint.setGroupName(properties.getString(GROUP_NAME, ""));
85
            breakpoint.setCondition(properties.getString(LineBreakpoint.PROP_CONDITION, null));
89
            return breakpoint;
86
            return breakpoint;
90
        } else if (typeID.equals(FunctionBreakpoint.class.getName())) {
87
        } else if (typeID.equals(FunctionBreakpoint.class.getName())) {
91
            String func = properties.getString(FUNC_NAME, null);
88
            String func = properties.getString(FUNC_NAME, null);
Lines 109-118 Link Here
109
        if (object instanceof LineBreakpoint) {
106
        if (object instanceof LineBreakpoint) {
110
            LineBreakpoint breakpoint = (LineBreakpoint) object;
107
            LineBreakpoint breakpoint = (LineBreakpoint) object;
111
            FileObject fileObject = breakpoint.getLine().getLookup().lookup(FileObject.class);
108
            FileObject fileObject = breakpoint.getLine().getLookup().lookup(FileObject.class);
112
            properties.setString(URL, fileObject.toURL().toString());
109
            properties.setString(LineBreakpoint.PROP_URL, fileObject.toURL().toString());
113
            properties.setInt(LINE_NUMBER, breakpoint.getLine().getLineNumber());
110
            properties.setInt(LineBreakpoint.PROP_LINE_NUMBER, breakpoint.getLine().getLineNumber());
114
            properties.setBoolean(ENABED, breakpoint.isEnabled());
111
            properties.setBoolean(ENABED, breakpoint.isEnabled());
115
            properties.setString(GROUP_NAME, breakpoint.getGroupName());
112
            properties.setString(GROUP_NAME, breakpoint.getGroupName());
113
            properties.setString(LineBreakpoint.PROP_CONDITION, breakpoint.getCondition());
116
        } else if (object instanceof FunctionBreakpoint) {
114
        } else if (object instanceof FunctionBreakpoint) {
117
            FunctionBreakpoint breakpoint = (FunctionBreakpoint) object;
115
            FunctionBreakpoint breakpoint = (FunctionBreakpoint) object;
118
            String func = breakpoint.getFunction();
116
            String func = breakpoint.getFunction();
Lines 128-155 Link Here
128
        if (file == null) {
126
        if (file == null) {
129
            return null;
127
            return null;
130
        }
128
        }
131
        DataObject dataObject;
129
        return Utils.getLine(file, lineNumber);
132
        try {
133
            dataObject = DataObject.find(file);
134
        } catch (DataObjectNotFoundException ex) {
135
            return null;
136
        }
137
        if (dataObject == null) {
138
            return null;
139
        }
140
        LineCookie lineCookie = dataObject.getLookup().lookup(LineCookie.class);
141
        if (lineCookie == null) {
142
            return null;
143
        }
144
        Line.Set ls = lineCookie.getLineSet();
145
        if (ls == null) {
146
            return null;
147
        }
148
        try {
149
            return ls.getCurrent(lineNumber);
150
        } catch (IndexOutOfBoundsException e) {
151
            return null;
152
        }
153
    }
130
    }
154
131
155
    private FileObject getFileObject(String url) {
132
    private FileObject getFileObject(String url) {
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BrkptsViewActionProvider.java (-2 / +94 lines)
Lines 43-55 Link Here
43
 */
43
 */
44
package org.netbeans.modules.php.dbgp.breakpoints;
44
package org.netbeans.modules.php.dbgp.breakpoints;
45
45
46
import java.awt.Dialog;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.beans.PropertyChangeEvent;
50
import java.beans.PropertyChangeListener;
46
import javax.swing.Action;
51
import javax.swing.Action;
47
52
import org.netbeans.modules.php.dbgp.ui.DbgpLineBreakpointCustomizer;
53
import org.netbeans.modules.php.dbgp.ui.DbgpLineBreakpointCustomizerPanel;
54
import org.netbeans.spi.debugger.ui.Controller;
48
import org.netbeans.spi.viewmodel.Models;
55
import org.netbeans.spi.viewmodel.Models;
49
import org.netbeans.spi.viewmodel.NodeActionsProvider;
56
import org.netbeans.spi.viewmodel.NodeActionsProvider;
50
import org.netbeans.spi.viewmodel.NodeActionsProviderFilter;
57
import org.netbeans.spi.viewmodel.NodeActionsProviderFilter;
51
import org.netbeans.spi.viewmodel.UnknownTypeException;
58
import org.netbeans.spi.viewmodel.UnknownTypeException;
59
import org.openide.DialogDescriptor;
60
import org.openide.DialogDisplayer;
61
import org.openide.NotificationLineSupport;
62
import org.openide.NotifyDescriptor;
52
import org.openide.text.Line;
63
import org.openide.text.Line;
64
import org.openide.util.HelpCtx;
53
import org.openide.util.NbBundle;
65
import org.openide.util.NbBundle;
54
66
55
/**
67
/**
Lines 63-72 Link Here
63
    public Action[] getActions(NodeActionsProvider original, Object node) throws UnknownTypeException {
75
    public Action[] getActions(NodeActionsProvider original, Object node) throws UnknownTypeException {
64
        Action[] actions = original.getActions(node);
76
        Action[] actions = original.getActions(node);
65
        if (node instanceof LineBreakpoint) {
77
        if (node instanceof LineBreakpoint) {
66
            Action[] newActions = new Action[actions.length + 2];
78
            Action[] newActions = new Action[actions.length + 4];
67
            newActions[0] = GO_TO_SOURCE_ACTION;
79
            newActions[0] = GO_TO_SOURCE_ACTION;
68
            newActions[1] = null;
80
            newActions[1] = null;
69
            System.arraycopy(actions, 0, newActions, 2, actions.length);
81
            System.arraycopy(actions, 0, newActions, 2, actions.length);
82
            newActions[newActions.length - 2] = null;
83
            newActions[newActions.length - 1] = CUSTOMIZE_ACTION;
70
            actions = newActions;
84
            actions = newActions;
71
        }
85
        }
72
        return actions;
86
        return actions;
Lines 87-92 Link Here
87
            line.show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS);
101
            line.show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS);
88
        }
102
        }
89
    }
103
    }
104
105
    @NbBundle.Messages("CTL_Breakpoint_Customizer_Title=Breakpoint Properties")
106
    private static void customize(LineBreakpoint lb) {
107
        DbgpLineBreakpointCustomizerPanel panel = DbgpLineBreakpointCustomizer.getCustomizerComponent(lb);
108
        HelpCtx helpCtx = HelpCtx.findHelp(panel);
109
        if (helpCtx == null) {
110
            helpCtx = new HelpCtx("debug.add.breakpoint"); // NOI18N
111
        }
112
113
        Controller controller = panel.getController();
114
        if (controller == null) {
115
            return;
116
        }
117
118
        final Controller[] cPtr = new Controller[]{controller};
119
        final DialogDescriptor[] descriptorPtr = new DialogDescriptor[1];
120
        final Dialog[] dialogPtr = new Dialog[1];
121
        final PropertyChangeListener propertyChangeListener = (PropertyChangeEvent e) -> {
122
            if (e.getPropertyName().equals(NotifyDescriptor.PROP_ERROR_NOTIFICATION)) {
123
                Object v = e.getNewValue();
124
                String message = (v == null) ? null : v.toString();
125
                descriptorPtr[0].getNotificationLineSupport().setErrorMessage(message);
126
            } else if (e.getPropertyName().equals(Controller.PROP_VALID)) {
127
                descriptorPtr[0].setValid(controller.isValid());
128
            }
129
        };
130
        controller.addPropertyChangeListener(propertyChangeListener);
131
        ActionListener buttonsActionListener = (ActionEvent e) -> {
132
            if (descriptorPtr[0].getValue() == DialogDescriptor.OK_OPTION) {
133
                boolean ok = cPtr[0].ok();
134
                if (ok) {
135
                    dialogPtr[0].setVisible(false);
136
                    cPtr[0].removePropertyChangeListener(propertyChangeListener);
137
                }
138
            } else {
139
                dialogPtr[0].setVisible(false);
140
                cPtr[0].removePropertyChangeListener(propertyChangeListener);
141
            }
142
        };
143
        DialogDescriptor descriptor = new DialogDescriptor(
144
                panel,
145
                Bundle.CTL_Breakpoint_Customizer_Title(),
146
                true,
147
                DialogDescriptor.OK_CANCEL_OPTION,
148
                DialogDescriptor.OK_OPTION,
149
                DialogDescriptor.DEFAULT_ALIGN,
150
                helpCtx,
151
                buttonsActionListener
152
        );
153
        descriptor.setClosingOptions(new Object[]{});
154
        descriptor.createNotificationLineSupport();
155
        Dialog d = DialogDisplayer.getDefault().createDialog(descriptor);
156
        d.pack();
157
        descriptorPtr[0] = descriptor;
158
        dialogPtr[0] = d;
159
        d.setVisible(true);
160
    }
161
90
    private static final Action GO_TO_SOURCE_ACTION = Models.createAction(
162
    private static final Action GO_TO_SOURCE_ACTION = Models.createAction(
91
            NbBundle.getMessage(BrkptsViewActionProvider.class, GO_TO_SOURCE_LABEL),
163
            NbBundle.getMessage(BrkptsViewActionProvider.class, GO_TO_SOURCE_LABEL),
92
            new GoToSourcePerformer(),
164
            new GoToSourcePerformer(),
Lines 106-109 Link Here
106
178
107
    }
179
    }
108
180
181
    @NbBundle.Messages("CTL_Breakpoint_Customize_Label=Properties")
182
    private static final Action CUSTOMIZE_ACTION = Models.createAction(
183
            Bundle.CTL_Breakpoint_Customize_Label(),
184
            new CustomizePerformer(),
185
            Models.MULTISELECTION_TYPE_EXACTLY_ONE
186
    );
187
188
    private static class CustomizePerformer implements Models.ActionPerformer {
189
190
        @Override
191
        public boolean isEnabled(Object node) {
192
            return true;
193
        }
194
195
        @Override
196
        public void perform(Object[] nodes) {
197
            customize((LineBreakpoint) nodes[0]);
198
        }
199
    }
200
109
}
201
}
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/DbgpLineBreakpointType.java (+115 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 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
package org.netbeans.modules.php.dbgp.breakpoints;
41
42
import javax.swing.JComponent;
43
import javax.swing.text.BadLocationException;
44
import javax.swing.text.JTextComponent;
45
import org.netbeans.api.editor.EditorRegistry;
46
import org.netbeans.api.editor.document.LineDocumentUtils;
47
import org.netbeans.editor.BaseDocument;
48
import org.netbeans.modules.editor.NbEditorUtilities;
49
import org.netbeans.modules.php.api.util.FileUtils;
50
import org.netbeans.modules.php.dbgp.ui.DbgpLineBreakpointCustomizerPanel;
51
import org.netbeans.spi.debugger.ui.BreakpointType;
52
import org.netbeans.spi.debugger.ui.Controller;
53
import org.openide.filesystems.FileObject;
54
import org.openide.text.Line;
55
import org.openide.util.NbBundle;
56
57
@NbBundle.Messages({
58
    "DbgpLineBreakpointType.CategoryDisplayName=PHP",
59
    "DbgpLineBreakpointType.TypeDisplayName=Line"
60
})
61
@BreakpointType.Registration(displayName = "#DbgpLineBreakpointType.TypeDisplayName")
62
public class DbgpLineBreakpointType extends BreakpointType {
63
64
    private Controller controller;
65
66
    @Override
67
    public String getCategoryDisplayName() {
68
        return Bundle.DbgpLineBreakpointType_CategoryDisplayName();
69
    }
70
71
    @Override
72
    public String getTypeDisplayName() {
73
        return Bundle.DbgpLineBreakpointType_TypeDisplayName();
74
    }
75
76
    @Override
77
    public JComponent getCustomizer() {
78
        JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent();
79
        Line line;
80
        if (lastFocusedComponent != null) {
81
            FileObject fileObject = NbEditorUtilities.getFileObject(lastFocusedComponent.getDocument());
82
            int caretPosition = lastFocusedComponent.getCaretPosition();
83
            try {
84
                int lineNumber = LineDocumentUtils.getLineIndex((BaseDocument) lastFocusedComponent.getDocument(), caretPosition);
85
                line = Utils.getLine(fileObject, lineNumber);
86
            } catch (BadLocationException ex) {
87
                line = null;
88
            }
89
        } else {
90
            line = null;
91
        }
92
        DbgpLineBreakpointCustomizerPanel customizer = new DbgpLineBreakpointCustomizerPanel(line);
93
        controller = customizer.getController();
94
        return customizer;
95
    }
96
97
    @Override
98
    public Controller getController() {
99
        return controller;
100
    }
101
102
    @Override
103
    public boolean isDefault() {
104
        JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent();
105
        if (lastFocusedComponent == null) {
106
            return false;
107
        }
108
        FileObject fileObject = NbEditorUtilities.getFileObject(lastFocusedComponent.getDocument());
109
        if (fileObject == null) {
110
            return false;
111
        }
112
        return FileUtils.isPhpFile(fileObject);
113
    }
114
115
}
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/LineBreakpoint.java (+43 lines)
Lines 61-66 Link Here
61
import org.netbeans.editor.BaseDocument;
61
import org.netbeans.editor.BaseDocument;
62
import org.netbeans.editor.Utilities;
62
import org.netbeans.editor.Utilities;
63
import org.netbeans.modules.csl.api.OffsetRange;
63
import org.netbeans.modules.csl.api.OffsetRange;
64
import org.netbeans.modules.csl.spi.support.CancelSupport;
64
import org.netbeans.modules.parsing.api.ParserManager;
65
import org.netbeans.modules.parsing.api.ParserManager;
65
import org.netbeans.modules.parsing.api.ResultIterator;
66
import org.netbeans.modules.parsing.api.ResultIterator;
66
import org.netbeans.modules.parsing.api.Source;
67
import org.netbeans.modules.parsing.api.Source;
Lines 79-84 Link Here
79
import org.openide.filesystems.FileChangeListener;
80
import org.openide.filesystems.FileChangeListener;
80
import org.openide.filesystems.FileEvent;
81
import org.openide.filesystems.FileEvent;
81
import org.openide.filesystems.FileObject;
82
import org.openide.filesystems.FileObject;
83
import org.openide.filesystems.FileRenameEvent;
82
import org.openide.loaders.DataObject;
84
import org.openide.loaders.DataObject;
83
import org.openide.text.DataEditorSupport;
85
import org.openide.text.DataEditorSupport;
84
import org.openide.text.Line;
86
import org.openide.text.Line;
Lines 87-103 Link Here
87
import org.openide.util.WeakListeners;
89
import org.openide.util.WeakListeners;
88
90
89
/**
91
/**
92
 * If this class name is changed, {@link LineBreakpointBeanInfo} class name must
93
 * be changed.
90
 *
94
 *
91
 * @author ads
95
 * @author ads
92
 */
96
 */
93
public class LineBreakpoint extends AbstractBreakpoint {
97
public class LineBreakpoint extends AbstractBreakpoint {
98
94
    private static final Logger LOGGER = Logger.getLogger(LineBreakpoint.class.getName());
99
    private static final Logger LOGGER = Logger.getLogger(LineBreakpoint.class.getName());
95
    private static final RequestProcessor RP = new RequestProcessor(LineBreakpoint.class);
100
    private static final RequestProcessor RP = new RequestProcessor(LineBreakpoint.class);
101
    public static final String PROP_URL = "url"; // NOI18N
102
    public static final String PROP_LINE_NUMBER = "lineNumber"; // NOI18N
103
    public static final String PROP_CONDITION = "condition"; // NOI18N
104
96
    private final Line myLine;
105
    private final Line myLine;
97
    private final FileRemoveListener myListener;
106
    private final FileRemoveListener myListener;
98
    private FileChangeListener myWeakListener;
107
    private FileChangeListener myWeakListener;
99
    private final String myFileUrl;
108
    private final String myFileUrl;
100
    private final Future<Boolean> isValidFuture;
109
    private final Future<Boolean> isValidFuture;
110
    // @GuardedBy("this")
111
    private String condition;
101
112
102
    public LineBreakpoint(Line line) {
113
    public LineBreakpoint(Line line) {
103
        myLine = line;
114
        myLine = line;
Lines 188-193 Link Here
188
        return myFileUrl;
199
        return myFileUrl;
189
    }
200
    }
190
201
202
    public synchronized final String getCondition() {
203
        return condition;
204
    }
205
206
    public synchronized final void setCondition(String condition) {
207
        String oldCondition = this.condition;
208
        if ((condition != null && condition.equals(oldCondition))
209
                || (condition == null && oldCondition == null)) {
210
            return;
211
        }
212
        this.condition = condition;
213
        firePropertyChange(PROP_CONDITION, oldCondition, condition);
214
    }
215
216
    public synchronized final boolean isConditional() {
217
        return condition != null && !condition.isEmpty();
218
    }
219
191
    @Override
220
    @Override
192
    public int isTemp() {
221
    public int isTemp() {
193
        return 0;
222
        return 0;
Lines 215-220 Link Here
215
        return new PhpGroupProperties();
244
        return new PhpGroupProperties();
216
    }
245
    }
217
246
247
    void fireLineNumberChanged() {
248
        int lineNumber = getLine().getLineNumber();
249
        firePropertyChange(PROP_LINE_NUMBER, null, lineNumber);
250
    }
251
218
    //~ Inner classes
252
    //~ Inner classes
219
253
220
    private final class PhpGroupProperties extends GroupProperties {
254
    private final class PhpGroupProperties extends GroupProperties {
Lines 277-282 Link Here
277
                    LineBreakpoint.this);
311
                    LineBreakpoint.this);
278
        }
312
        }
279
313
314
        @Override
315
        public void fileRenamed(FileRenameEvent fe) {
316
            FileObject renamedFo = fe.getFile();
317
            firePropertyChange(PROP_URL, myFileUrl, renamedFo.toURL().toString());
318
        }
319
280
    }
320
    }
281
321
282
    private static final class StatementVisitor extends DefaultVisitor {
322
    private static final class StatementVisitor extends DefaultVisitor {
Lines 291-296 Link Here
291
331
292
        @Override
332
        @Override
293
        public void scan(ASTNode node) {
333
        public void scan(ASTNode node) {
334
            if (CancelSupport.getDefault().isCancelled()) {
335
                return;
336
            }
294
            if (node != null) {
337
            if (node != null) {
295
                OffsetRange nodeRange = new OffsetRange(node.getStartOffset(), node.getEndOffset());
338
                OffsetRange nodeRange = new OffsetRange(node.getStartOffset(), node.getEndOffset());
296
                if (node instanceof Statement && nodeRange.containsInclusive(contentStart) && nodeRange.containsInclusive(contentEnd)) {
339
                if (node instanceof Statement && nodeRange.containsInclusive(contentStart) && nodeRange.containsInclusive(contentEnd)) {
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/LineBreakpointBeanInfo.java (+67 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 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
package org.netbeans.modules.php.dbgp.breakpoints;
41
42
import java.beans.BeanDescriptor;
43
import java.beans.SimpleBeanInfo;
44
import java.util.logging.Level;
45
import java.util.logging.Logger;
46
import org.openide.util.Lookup;
47
48
/**
49
 * Don't change this class name. If it is changed, {@link LineBreakpoint} class name
50
 * must be changed.
51
 */
52
public class LineBreakpointBeanInfo extends SimpleBeanInfo {
53
54
    private static final Logger LOGGER = Logger.getLogger(LineBreakpointBeanInfo.class.getName());
55
56
    @Override
57
    public BeanDescriptor getBeanDescriptor() {
58
        Class customizer = null;
59
        try {
60
            customizer = Class.forName("org.netbeans.modules.php.dbgp.ui.DbgpLineBreakpointCustomizer", // NOI18N
61
                    true, Lookup.getDefault().lookup(ClassLoader.class));
62
        } catch (ClassNotFoundException cnfex) {
63
            LOGGER.log(Level.WARNING, "No BP customizer", cnfex); // NOI18N
64
        }
65
        return new BeanDescriptor(LineBreakpoint.class, customizer);
66
    }
67
}
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/UpdatePropertiesOnSaveTask.java (+99 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 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
package org.netbeans.modules.php.dbgp.breakpoints;
41
42
import javax.swing.text.Document;
43
import org.netbeans.api.debugger.Breakpoint;
44
import org.netbeans.api.debugger.DebuggerManager;
45
import org.netbeans.api.editor.mimelookup.MimeRegistration;
46
import org.netbeans.modules.editor.NbEditorUtilities;
47
import org.netbeans.modules.php.api.util.FileUtils;
48
import org.netbeans.spi.editor.document.OnSaveTask;
49
import org.openide.filesystems.FileObject;
50
51
/**
52
 * Save line number on save.
53
 */
54
public class UpdatePropertiesOnSaveTask implements OnSaveTask {
55
56
    private final Context context;
57
58
    private UpdatePropertiesOnSaveTask(Context context) {
59
        this.context = context;
60
    }
61
62
    @Override
63
    public void performTask() {
64
        Document document = context.getDocument();
65
        FileObject fileObject = NbEditorUtilities.getFileObject(document);
66
        if (fileObject == null) {
67
            return;
68
        }
69
        String fileUrl = fileObject.toURL().toString();
70
        DebuggerManager manager = DebuggerManager.getDebuggerManager();
71
        for (Breakpoint breakpoint : manager.getBreakpoints()) {
72
            if (breakpoint instanceof LineBreakpoint) {
73
                LineBreakpoint lineBreakpoint = (LineBreakpoint) breakpoint;
74
                if (fileUrl.equals(lineBreakpoint.getFileUrl())) {
75
                    lineBreakpoint.fireLineNumberChanged();
76
                }
77
            }
78
        }
79
    }
80
81
    @Override
82
    public void runLocked(Runnable run) {
83
        run.run();
84
    }
85
86
    @Override
87
    public boolean cancel() {
88
        return true;
89
    }
90
91
    @MimeRegistration(mimeType = FileUtils.PHP_MIME_TYPE, service = OnSaveTask.Factory.class, position = 1100)
92
    public static final class FactoryImpl implements Factory {
93
94
        @Override
95
        public OnSaveTask createTask(Context context) {
96
            return new UpdatePropertiesOnSaveTask(context);
97
        }
98
    }
99
}
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/Utils.java (+45 lines)
Lines 46-51 Link Here
46
import java.util.Set;
46
import java.util.Set;
47
import java.util.logging.Level;
47
import java.util.logging.Level;
48
import java.util.logging.Logger;
48
import java.util.logging.Logger;
49
import org.netbeans.api.annotations.common.CheckForNull;
49
import org.netbeans.api.debugger.Breakpoint;
50
import org.netbeans.api.debugger.Breakpoint;
50
import org.netbeans.api.debugger.DebuggerManager;
51
import org.netbeans.api.debugger.DebuggerManager;
51
import org.netbeans.api.options.OptionsDisplayer;
52
import org.netbeans.api.options.OptionsDisplayer;
Lines 80-85 Link Here
80
        Utils.lineFactory = lineFactory;
81
        Utils.lineFactory = lineFactory;
81
    }
82
    }
82
83
84
    /**
85
     * Get the current line.
86
     *
87
     * @return the current line if the file is php, otherwise {@code null}.
88
     */
89
    @CheckForNull
83
    public static Line getCurrentLine() {
90
    public static Line getCurrentLine() {
84
        FileObject fileObject = EditorContextDispatcher.getDefault().getCurrentFile();
91
        FileObject fileObject = EditorContextDispatcher.getDefault().getCurrentFile();
85
92
Lines 90-95 Link Here
90
        return EditorContextDispatcher.getDefault().getCurrentLine();
97
        return EditorContextDispatcher.getDefault().getCurrentLine();
91
    }
98
    }
92
99
100
    /**
101
     * Get the Line from FileObject.
102
     *
103
     * @param file the FileObject
104
     * @param lineNumber the line number
105
     * @return the line if it is found with the file and the line number,
106
     * otherwise {@code null}
107
     */
108
    @CheckForNull
109
    public static Line getLine(FileObject file, int lineNumber) {
110
        if (file == null || lineNumber < 0) {
111
            return null;
112
        }
113
114
        DataObject dataObject;
115
        try {
116
            dataObject = DataObject.find(file);
117
        } catch (DataObjectNotFoundException ex) {
118
            return null;
119
        }
120
        if (dataObject == null) {
121
            return null;
122
        }
123
        LineCookie lineCookie = dataObject.getLookup().lookup(LineCookie.class);
124
        if (lineCookie == null) {
125
            return null;
126
        }
127
        Line.Set ls = lineCookie.getLineSet();
128
        if (ls == null) {
129
            return null;
130
        }
131
        try {
132
            return ls.getCurrent(lineNumber);
133
        } catch (IndexOutOfBoundsException e) {
134
            return null;
135
        }
136
    }
137
93
    public static BrkpntSetCommand getCommand(DebugSession session, SessionId id, AbstractBreakpoint breakpoint) {
138
    public static BrkpntSetCommand getCommand(DebugSession session, SessionId id, AbstractBreakpoint breakpoint) {
94
        if (!breakpoint.isSessionRelated(session)) {
139
        if (!breakpoint.isSessionRelated(session)) {
95
            return null;
140
            return null;
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/BrkpntCommandBuilder.java (-1 / +7 lines)
Lines 55-64 Link Here
55
 *
55
 *
56
 */
56
 */
57
public final class BrkpntCommandBuilder {
57
public final class BrkpntCommandBuilder {
58
58
    private BrkpntCommandBuilder() {
59
    private BrkpntCommandBuilder() {
59
    }
60
    }
60
61
61
    public static BrkpntSetCommand buildLineBreakpoint(SessionId id, String transactionId, FileObject localFile, int lineNumber) {
62
    public static BrkpntSetCommand buildLineBreakpoint(SessionId id, String transactionId, FileObject localFile, int lineNumber) {
63
        return buildLineBreakpoint(id, transactionId, localFile, lineNumber, null);
64
    }
65
66
    public static BrkpntSetCommand buildLineBreakpoint(SessionId id, String transactionId, FileObject localFile, int lineNumber, String condition) {
62
        if (localFile == null) {
67
        if (localFile == null) {
63
            // #251806
68
            // #251806
64
            return null;
69
            return null;
Lines 71-83 Link Here
71
        command.setType(Types.LINE);
76
        command.setType(Types.LINE);
72
        command.setFile(uri);
77
        command.setFile(uri);
73
        command.setLineNumber(lineNumber);
78
        command.setLineNumber(lineNumber);
79
        command.setExpression(condition);
74
        return command;
80
        return command;
75
    }
81
    }
76
82
77
    public static BrkpntSetCommand buildLineBreakpoint(SessionId id, String transactionId, LineBreakpoint breakpoint) {
83
    public static BrkpntSetCommand buildLineBreakpoint(SessionId id, String transactionId, LineBreakpoint breakpoint) {
78
        Line line = breakpoint.getLine();
84
        Line line = breakpoint.getLine();
79
        FileObject fileObject = line.getLookup().lookup(FileObject.class);
85
        FileObject fileObject = line.getLookup().lookup(FileObject.class);
80
        BrkpntSetCommand command = buildLineBreakpoint(id, transactionId, fileObject, line.getLineNumber());
86
        BrkpntSetCommand command = buildLineBreakpoint(id, transactionId, fileObject, line.getLineNumber(), breakpoint.getCondition());
81
        if (command != null) {
87
        if (command != null) {
82
            command.setBreakpoint(breakpoint);
88
            command.setBreakpoint(breakpoint);
83
        }
89
        }
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/BrkpntSetCommand.java (-1 / +1 lines)
Lines 158-164 Link Here
158
    }
158
    }
159
159
160
    public void setExpression(String expression) {
160
    public void setExpression(String expression) {
161
        myException = expression;
161
        myExpression = expression;
162
    }
162
    }
163
163
164
    public void setTemporary(boolean isTemp) {
164
    public void setTemporary(boolean isTemp) {
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/ui/Bundle.properties (+7 lines)
Lines 41-46 Link Here
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
42
43
LBL_Settings=Settings
43
LBL_Settings=Settings
44
LBL_Condition=Condition
44
LBL_MethodName=&Method Name:
45
LBL_MethodName=&Method Name:
45
LBL_StopOn=&Stop On:
46
LBL_StopOn=&Stop On:
46
A11_SettingsName=Settings
47
A11_SettingsName=Settings
Lines 88-90 Link Here
88
LocalFilterPanel.myResource.AccessibleContext.accessibleDescription=Enable for resource
89
LocalFilterPanel.myResource.AccessibleContext.accessibleDescription=Enable for resource
89
LocalFilterPanel.myNull.AccessibleContext.accessibleDescription=Enable for null type
90
LocalFilterPanel.myNull.AccessibleContext.accessibleDescription=Enable for null type
90
LocalFilterPanel.mySelectLbl.AccessibleContext.accessibleName=Select types to show
91
LocalFilterPanel.mySelectLbl.AccessibleContext.accessibleName=Select types to show
92
DbgpLineBreakpointCustomizerPanel.conditionCheckBox.text=&Condition:
93
DbgpLineBreakpointCustomizerPanel.lineNumberTextField.text=
94
DbgpLineBreakpointCustomizerPanel.fileTextField.text=
95
DbgpLineBreakpointCustomizerPanel.lineNumberLabel.text=&Line Number:
96
DbgpLineBreakpointCustomizerPanel.fileLabel.text=&File:
97
DbgpLineBreakpointCustomizerPanel.conditionComboBox.toolTipText=Breakpoint is hit when this condition evaluates to true.
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/ui/ControllerProvider.java (+47 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 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
package org.netbeans.modules.php.dbgp.ui;
41
42
import org.netbeans.spi.debugger.ui.Controller;
43
44
public interface ControllerProvider {
45
46
    Controller getController();
47
}
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/ui/DbgpLineBreakpointCustomizer.java (+97 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 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
package org.netbeans.modules.php.dbgp.ui;
41
42
import java.awt.GridBagConstraints;
43
import java.awt.GridBagLayout;
44
import java.beans.Customizer;
45
import javax.swing.JPanel;
46
import org.netbeans.modules.php.dbgp.breakpoints.LineBreakpoint;
47
import org.netbeans.spi.debugger.ui.Controller;
48
import org.openide.util.NbBundle;
49
50
public class DbgpLineBreakpointCustomizer extends JPanel implements Customizer, Controller {
51
52
    private static final long serialVersionUID = 3626744241527549679L;
53
54
    private LineBreakpoint b;
55
    private DbgpLineBreakpointCustomizerPanel c;
56
57
    public DbgpLineBreakpointCustomizer() {
58
    }
59
60
    @NbBundle.Messages("ACSD_Breakpoint_Customizer_Dialog=Customize this breakpoint's properties")
61
    public static DbgpLineBreakpointCustomizerPanel getCustomizerComponent(LineBreakpoint lineBreakpoint) {
62
        DbgpLineBreakpointCustomizerPanel panel;
63
        panel = new DbgpLineBreakpointCustomizerPanel(lineBreakpoint);
64
        panel.getAccessibleContext().setAccessibleDescription(Bundle.ACSD_Breakpoint_Customizer_Dialog());
65
        return panel;
66
    }
67
68
    @Override
69
    public void setObject(Object bean) {
70
        if (!(bean instanceof LineBreakpoint)) {
71
            throw new IllegalArgumentException(bean.toString());
72
        }
73
        this.b = (LineBreakpoint) bean;
74
        init(b);
75
    }
76
77
    private void init(LineBreakpoint b) {
78
        c = getCustomizerComponent(b);
79
        setLayout(new GridBagLayout());
80
        GridBagConstraints gbc = new GridBagConstraints();
81
        gbc.fill = GridBagConstraints.BOTH;
82
        gbc.weightx = 1.0;
83
        gbc.weighty = 1.0;
84
        add(c, gbc);
85
    }
86
87
    @Override
88
    public boolean ok() {
89
        return c.getController().ok();
90
    }
91
92
    @Override
93
    public boolean cancel() {
94
        return c.getController().cancel();
95
    }
96
97
}
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/ui/DbgpLineBreakpointCustomizerPanel.form (+170 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14
  </AuxValues>
15
16
  <Layout>
17
    <DimensionLayout dim="0">
18
      <Group type="103" groupAlignment="0" attributes="0">
19
          <Component id="settingsPanel" max="32767" attributes="0"/>
20
          <Component id="conditionPanel" alignment="0" max="32767" attributes="0"/>
21
      </Group>
22
    </DimensionLayout>
23
    <DimensionLayout dim="1">
24
      <Group type="103" groupAlignment="0" attributes="0">
25
          <Group type="102" alignment="0" attributes="0">
26
              <Component id="settingsPanel" min="-2" max="-2" attributes="0"/>
27
              <EmptySpace max="-2" attributes="0"/>
28
              <Component id="conditionPanel" max="32767" attributes="0"/>
29
          </Group>
30
      </Group>
31
    </DimensionLayout>
32
  </Layout>
33
  <SubComponents>
34
    <Container class="javax.swing.JPanel" name="settingsPanel">
35
      <Properties>
36
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
37
          <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
38
            <TitledBorder title="Settings">
39
              <ResourceString PropertyName="titleX" bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="LBL_Settings" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
40
            </TitledBorder>
41
          </Border>
42
        </Property>
43
      </Properties>
44
45
      <Layout>
46
        <DimensionLayout dim="0">
47
          <Group type="103" groupAlignment="0" attributes="0">
48
              <Group type="102" alignment="0" attributes="0">
49
                  <Group type="103" groupAlignment="0" attributes="0">
50
                      <Component id="lineNumberLabel" alignment="0" min="-2" max="-2" attributes="0"/>
51
                      <Component id="fileLabel" alignment="0" min="-2" max="-2" attributes="0"/>
52
                  </Group>
53
                  <EmptySpace max="-2" attributes="0"/>
54
                  <Group type="103" groupAlignment="0" attributes="0">
55
                      <Component id="fileTextField" max="32767" attributes="0"/>
56
                      <Component id="lineNumberTextField" max="32767" attributes="0"/>
57
                  </Group>
58
              </Group>
59
          </Group>
60
        </DimensionLayout>
61
        <DimensionLayout dim="1">
62
          <Group type="103" groupAlignment="0" attributes="0">
63
              <Group type="102" alignment="0" attributes="0">
64
                  <Group type="103" groupAlignment="3" attributes="0">
65
                      <Component id="fileLabel" alignment="3" min="-2" max="-2" attributes="0"/>
66
                      <Component id="fileTextField" alignment="3" min="-2" max="-2" attributes="0"/>
67
                  </Group>
68
                  <EmptySpace max="-2" attributes="0"/>
69
                  <Group type="103" groupAlignment="3" attributes="0">
70
                      <Component id="lineNumberLabel" alignment="3" min="-2" max="-2" attributes="0"/>
71
                      <Component id="lineNumberTextField" alignment="3" min="-2" max="-2" attributes="0"/>
72
                  </Group>
73
              </Group>
74
          </Group>
75
        </DimensionLayout>
76
      </Layout>
77
      <SubComponents>
78
        <Component class="javax.swing.JLabel" name="fileLabel">
79
          <Properties>
80
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
81
              <ResourceString bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="DbgpLineBreakpointCustomizerPanel.fileLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
82
            </Property>
83
          </Properties>
84
        </Component>
85
        <Component class="javax.swing.JLabel" name="lineNumberLabel">
86
          <Properties>
87
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
88
              <ResourceString bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="DbgpLineBreakpointCustomizerPanel.lineNumberLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
89
            </Property>
90
          </Properties>
91
        </Component>
92
        <Component class="javax.swing.JTextField" name="fileTextField">
93
          <Properties>
94
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
95
              <ResourceString bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="DbgpLineBreakpointCustomizerPanel.fileTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
96
            </Property>
97
          </Properties>
98
        </Component>
99
        <Component class="javax.swing.JTextField" name="lineNumberTextField">
100
          <Properties>
101
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
102
              <ResourceString bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="DbgpLineBreakpointCustomizerPanel.lineNumberTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
103
            </Property>
104
          </Properties>
105
        </Component>
106
      </SubComponents>
107
    </Container>
108
    <Container class="javax.swing.JPanel" name="conditionPanel">
109
      <Properties>
110
        <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
111
          <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
112
            <TitledBorder title="Condition">
113
              <ResourceString PropertyName="titleX" bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="LBL_Condition" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
114
            </TitledBorder>
115
          </Border>
116
        </Property>
117
      </Properties>
118
119
      <Layout>
120
        <DimensionLayout dim="0">
121
          <Group type="103" groupAlignment="0" attributes="0">
122
              <Group type="102" alignment="0" attributes="0">
123
                  <Component id="conditionCheckBox" min="-2" max="-2" attributes="0"/>
124
                  <EmptySpace type="unrelated" max="-2" attributes="0"/>
125
                  <Component id="conditionComboBox" pref="281" max="32767" attributes="0"/>
126
              </Group>
127
          </Group>
128
        </DimensionLayout>
129
        <DimensionLayout dim="1">
130
          <Group type="103" groupAlignment="0" attributes="0">
131
              <Group type="102" alignment="0" attributes="0">
132
                  <EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
133
                  <Group type="103" groupAlignment="3" attributes="0">
134
                      <Component id="conditionCheckBox" alignment="3" min="-2" max="-2" attributes="0"/>
135
                      <Component id="conditionComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
136
                  </Group>
137
                  <EmptySpace max="32767" attributes="0"/>
138
              </Group>
139
          </Group>
140
        </DimensionLayout>
141
      </Layout>
142
      <SubComponents>
143
        <Component class="javax.swing.JCheckBox" name="conditionCheckBox">
144
          <Properties>
145
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
146
              <ResourceString bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="DbgpLineBreakpointCustomizerPanel.conditionCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
147
            </Property>
148
          </Properties>
149
          <Events>
150
            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="conditionCheckBoxActionPerformed"/>
151
          </Events>
152
        </Component>
153
        <Component class="javax.swing.JComboBox" name="conditionComboBox">
154
          <Properties>
155
            <Property name="editable" type="boolean" value="true"/>
156
            <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
157
              <StringArray count="0"/>
158
            </Property>
159
            <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
160
              <ResourceString bundle="org/netbeans/modules/php/dbgp/ui/Bundle.properties" key="DbgpLineBreakpointCustomizerPanel.conditionComboBox.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
161
            </Property>
162
          </Properties>
163
          <AuxValues>
164
            <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
165
          </AuxValues>
166
        </Component>
167
      </SubComponents>
168
    </Container>
169
  </SubComponents>
170
</Form>
(-)a/php.dbgp/src/org/netbeans/modules/php/dbgp/ui/DbgpLineBreakpointCustomizerPanel.java (+466 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 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
package org.netbeans.modules.php.dbgp.ui;
41
42
import java.beans.PropertyChangeListener;
43
import java.beans.PropertyChangeSupport;
44
import java.io.File;
45
import javax.swing.DefaultComboBoxModel;
46
import javax.swing.JPanel;
47
import javax.swing.SwingUtilities;
48
import javax.swing.event.DocumentEvent;
49
import javax.swing.event.DocumentListener;
50
import org.netbeans.api.debugger.DebuggerManager;
51
import org.netbeans.api.debugger.Properties;
52
import org.netbeans.modules.php.dbgp.breakpoints.LineBreakpoint;
53
import org.netbeans.modules.php.dbgp.breakpoints.Utils;
54
import org.netbeans.spi.debugger.ui.Controller;
55
import org.openide.DialogDisplayer;
56
import org.openide.NotifyDescriptor;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileUtil;
59
import org.openide.text.Line;
60
import org.openide.util.NbBundle;
61
62
public class DbgpLineBreakpointCustomizerPanel extends JPanel implements ControllerProvider {
63
64
    private static final int MAX_SAVED_CONDITIONS = 10;
65
    private static final String BP_CONDITIONS = "BPConditions"; // NOI18N
66
    private static final String DEBUGGER_PHP = "debugger.php"; // NOI18N
67
    private static final long serialVersionUID = 6364512868561614302L;
68
69
    private final LineBreakpoint lineBreakpoint;
70
    private final Controller controller;
71
    private boolean createBreakpoint;
72
73
    private static LineBreakpoint createLineBreakpoint() {
74
        Line currentLine = Utils.getCurrentLine();
75
        return createLineBreakpoint(currentLine);
76
    }
77
78
    private static LineBreakpoint createLineBreakpoint(Line line) {
79
        if (line != null) {
80
            return new LineBreakpoint(line);
81
        }
82
        return null;
83
    }
84
85
    public DbgpLineBreakpointCustomizerPanel() {
86
        this(createLineBreakpoint(), true);
87
        createBreakpoint = true;
88
    }
89
90
    public DbgpLineBreakpointCustomizerPanel(Line line) {
91
        this(createLineBreakpoint(line), true);
92
        createBreakpoint = true;
93
    }
94
95
    public DbgpLineBreakpointCustomizerPanel(LineBreakpoint lineBreakpoint) {
96
        this(lineBreakpoint, false);
97
    }
98
99
    private DbgpLineBreakpointCustomizerPanel(LineBreakpoint lineBreakpoint, boolean isEditable) {
100
        this.lineBreakpoint = lineBreakpoint;
101
        controller = createController();
102
        initComponents();
103
104
        DocumentListener defaultDocumentListener = new DocumentListener() {
105
            @Override
106
            public void insertUpdate(DocumentEvent e) {
107
                processUpdate();
108
            }
109
110
            @Override
111
            public void removeUpdate(DocumentEvent e) {
112
                processUpdate();
113
            }
114
115
            @Override
116
            public void changedUpdate(DocumentEvent e) {
117
                processUpdate();
118
            }
119
120
            private void processUpdate() {
121
                ((CustomizerController) controller).firePropertyChange();
122
            }
123
        };
124
        fileTextField.setEditable(isEditable);
125
        fileTextField.getDocument().addDocumentListener(defaultDocumentListener);
126
        lineNumberTextField.setEditable(isEditable);
127
        lineNumberTextField.getDocument().addDocumentListener(defaultDocumentListener);
128
        Object[] conditions = getSavedConditions();
129
        conditionComboBox.setModel(new DefaultComboBoxModel(conditions));
130
131
        if (lineBreakpoint != null) {
132
            Line line = lineBreakpoint.getLine();
133
            FileObject fo = line.getLookup().lookup(FileObject.class);
134
            updateComponents(fo, line.getLineNumber() + 1, lineBreakpoint.getCondition());
135
        }
136
    }
137
138
    private void updateComponents(FileObject fileObject, int lineNumber, String condition) {
139
        assert SwingUtilities.isEventDispatchThread();
140
        if (fileObject != null) {
141
            File file = FileUtil.toFile(fileObject);
142
            if (file != null) {
143
                fileTextField.setText(file.getAbsolutePath());
144
            } else {
145
                fileTextField.setText(fileObject.toURL().toExternalForm());
146
            }
147
        }
148
149
        lineNumberTextField.setText(Integer.toString(lineNumber));
150
151
        if (condition != null && !condition.isEmpty()) {
152
            conditionCheckBox.setSelected(true);
153
            conditionComboBox.setEnabled(true);
154
            conditionComboBox.getEditor().setItem(condition);
155
        } else {
156
            conditionCheckBox.setSelected(false);
157
            conditionComboBox.setEnabled(false);
158
        }
159
    }
160
161
    private static Object[] getSavedConditions() {
162
        return Properties.getDefault()
163
                .getProperties(DEBUGGER_PHP)
164
                .getArray(BP_CONDITIONS, new Object[0]);
165
    }
166
167
    private static void saveCondition(String condition) {
168
        Object[] savedConditions = getSavedConditions();
169
        Object[] conditions = null;
170
        boolean containsCondition = false;
171
        for (int i = 0; i < savedConditions.length; i++) {
172
            Object c = savedConditions[i];
173
            if (condition.equals(c)) {
174
                containsCondition = true;
175
                conditions = savedConditions;
176
                if (i > 0) {
177
                    System.arraycopy(conditions, 0, conditions, 1, i);
178
                    conditions[0] = condition;
179
                }
180
                break;
181
            }
182
        }
183
        if (!containsCondition) {
184
            if (savedConditions.length < MAX_SAVED_CONDITIONS) {
185
                conditions = new Object[savedConditions.length + 1];
186
                conditions[0] = condition;
187
                System.arraycopy(savedConditions, 0, conditions, 1, savedConditions.length);
188
            } else {
189
                conditions = savedConditions;
190
                System.arraycopy(conditions, 0, conditions, 1, conditions.length - 1);
191
                conditions[0] = condition;
192
            }
193
        }
194
        Properties.getDefault()
195
                .getProperties(DEBUGGER_PHP)
196
                .setArray(BP_CONDITIONS, conditions);
197
    }
198
199
    private Controller createController() {
200
        return new CustomizerController();
201
    }
202
203
    @Override
204
    public Controller getController() {
205
        return controller;
206
    }
207
208
    /**
209
     * This method is called from within the constructor to initialize the form.
210
     * WARNING: Do NOT modify this code. The content of this method is always
211
     * regenerated by the Form Editor.
212
     */
213
    @SuppressWarnings("unchecked")
214
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
215
    private void initComponents() {
216
217
        settingsPanel = new javax.swing.JPanel();
218
        fileLabel = new javax.swing.JLabel();
219
        lineNumberLabel = new javax.swing.JLabel();
220
        fileTextField = new javax.swing.JTextField();
221
        lineNumberTextField = new javax.swing.JTextField();
222
        conditionPanel = new javax.swing.JPanel();
223
        conditionCheckBox = new javax.swing.JCheckBox();
224
        conditionComboBox = new javax.swing.JComboBox<>();
225
226
        settingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "LBL_Settings"))); // NOI18N
227
228
        org.openide.awt.Mnemonics.setLocalizedText(fileLabel, org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "DbgpLineBreakpointCustomizerPanel.fileLabel.text")); // NOI18N
229
230
        org.openide.awt.Mnemonics.setLocalizedText(lineNumberLabel, org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "DbgpLineBreakpointCustomizerPanel.lineNumberLabel.text")); // NOI18N
231
232
        fileTextField.setText(org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "DbgpLineBreakpointCustomizerPanel.fileTextField.text")); // NOI18N
233
234
        lineNumberTextField.setText(org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "DbgpLineBreakpointCustomizerPanel.lineNumberTextField.text")); // NOI18N
235
236
        javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
237
        settingsPanel.setLayout(settingsPanelLayout);
238
        settingsPanelLayout.setHorizontalGroup(
239
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240
            .addGroup(settingsPanelLayout.createSequentialGroup()
241
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242
                    .addComponent(lineNumberLabel)
243
                    .addComponent(fileLabel))
244
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
245
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246
                    .addComponent(fileTextField)
247
                    .addComponent(lineNumberTextField)))
248
        );
249
        settingsPanelLayout.setVerticalGroup(
250
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251
            .addGroup(settingsPanelLayout.createSequentialGroup()
252
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
253
                    .addComponent(fileLabel)
254
                    .addComponent(fileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
255
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
256
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
257
                    .addComponent(lineNumberLabel)
258
                    .addComponent(lineNumberTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
259
        );
260
261
        conditionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "LBL_Condition"))); // NOI18N
262
263
        org.openide.awt.Mnemonics.setLocalizedText(conditionCheckBox, org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "DbgpLineBreakpointCustomizerPanel.conditionCheckBox.text")); // NOI18N
264
        conditionCheckBox.addActionListener(new java.awt.event.ActionListener() {
265
            public void actionPerformed(java.awt.event.ActionEvent evt) {
266
                conditionCheckBoxActionPerformed(evt);
267
            }
268
        });
269
270
        conditionComboBox.setEditable(true);
271
        conditionComboBox.setToolTipText(org.openide.util.NbBundle.getMessage(DbgpLineBreakpointCustomizerPanel.class, "DbgpLineBreakpointCustomizerPanel.conditionComboBox.toolTipText")); // NOI18N
272
273
        javax.swing.GroupLayout conditionPanelLayout = new javax.swing.GroupLayout(conditionPanel);
274
        conditionPanel.setLayout(conditionPanelLayout);
275
        conditionPanelLayout.setHorizontalGroup(
276
            conditionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
277
            .addGroup(conditionPanelLayout.createSequentialGroup()
278
                .addComponent(conditionCheckBox)
279
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
280
                .addComponent(conditionComboBox, 0, 281, Short.MAX_VALUE))
281
        );
282
        conditionPanelLayout.setVerticalGroup(
283
            conditionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
284
            .addGroup(conditionPanelLayout.createSequentialGroup()
285
                .addGap(0, 0, 0)
286
                .addGroup(conditionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
287
                    .addComponent(conditionCheckBox)
288
                    .addComponent(conditionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
289
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
290
        );
291
292
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
293
        this.setLayout(layout);
294
        layout.setHorizontalGroup(
295
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
296
            .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
297
            .addComponent(conditionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
298
        );
299
        layout.setVerticalGroup(
300
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301
            .addGroup(layout.createSequentialGroup()
302
                .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
303
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
304
                .addComponent(conditionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
305
        );
306
    }// </editor-fold>//GEN-END:initComponents
307
308
    private void conditionCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_conditionCheckBoxActionPerformed
309
        conditionComboBox.setEnabled(conditionCheckBox.isSelected());
310
        if (conditionCheckBox.isSelected()) {
311
            conditionComboBox.requestFocusInWindow();
312
        }
313
    }//GEN-LAST:event_conditionCheckBoxActionPerformed
314
315
    // Variables declaration - do not modify//GEN-BEGIN:variables
316
    private javax.swing.JCheckBox conditionCheckBox;
317
    private javax.swing.JComboBox<String> conditionComboBox;
318
    private javax.swing.JPanel conditionPanel;
319
    private javax.swing.JLabel fileLabel;
320
    private javax.swing.JTextField fileTextField;
321
    private javax.swing.JLabel lineNumberLabel;
322
    private javax.swing.JTextField lineNumberTextField;
323
    private javax.swing.JPanel settingsPanel;
324
    // End of variables declaration//GEN-END:variables
325
326
    //~ Inner classes
327
    private class CustomizerController implements Controller {
328
329
        private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
330
        private String errorMessage;
331
332
        @Override
333
        public boolean ok() {
334
            if (!isValid()) {
335
                final String message = getErrorMessage();
336
                if (message != null) {
337
                    if (SwingUtilities.isEventDispatchThread()) {
338
                        showMessageDialog(message);
339
                    } else {
340
                        SwingUtilities.invokeLater(() -> {
341
                            showMessageDialog(message);
342
                        });
343
                    }
344
                }
345
                return false;
346
            }
347
348
            String condition = null;
349
            if (conditionCheckBox.isSelected()) {
350
                condition = conditionComboBox.getSelectedItem().toString().trim();
351
            }
352
353
            if (createBreakpoint) {
354
                String fileName = fileTextField.getText();
355
                String lineNumberString = lineNumberTextField.getText();
356
                if (fileName == null) {
357
                    return false;
358
                }
359
                File file = new File(fileName.trim());
360
                FileObject fileObject = FileUtil.toFileObject(file);
361
                if (fileObject == null) {
362
                    return false;
363
                }
364
                Line line = Utils.getLine(fileObject, Integer.parseInt(lineNumberString) - 1);
365
                LineBreakpoint lb = createLineBreakpoint(line);
366
                setCondition(lb, condition);
367
                DebuggerManager.getDebuggerManager().addBreakpoint(lb);
368
            } else {
369
                setCondition(lineBreakpoint, condition);
370
            }
371
372
            return true;
373
        }
374
375
        private void setCondition(LineBreakpoint lb, String condition) {
376
            if (condition != null && !condition.isEmpty()) {
377
                lb.setCondition(condition);
378
                saveCondition(condition);
379
            } else {
380
                lb.setCondition(null);
381
            }
382
        }
383
384
        @Override
385
        public boolean cancel() {
386
            return true;
387
        }
388
389
        @NbBundle.Messages({
390
            "CustomizerController.invalid.file=Existing file must be set.",
391
            "CustomizerController.invalid.line=Valid line number must be set."
392
        })
393
        @Override
394
        public boolean isValid() {
395
            boolean isValid = true;
396
            // file
397
            String fileName = fileTextField.getText();
398
            if (fileName == null || fileName.trim().length() == 0) {
399
                setErrorMessage(Bundle.CustomizerController_invalid_file());
400
                return false;
401
            }
402
            File file = new File(fileName.trim());
403
            if (!file.exists()) {
404
                setErrorMessage(Bundle.CustomizerController_invalid_file());
405
                return false;
406
            }
407
            FileObject fileObject = FileUtil.toFileObject(file);
408
            if (fileObject == null) {
409
                setErrorMessage(Bundle.CustomizerController_invalid_file());
410
                return false;
411
            }
412
413
            // line number
414
            String lineNumberString = lineNumberTextField.getText();
415
            if (lineNumberString == null || lineNumberString.trim().length() == 0) {
416
                setErrorMessage(Bundle.CustomizerController_invalid_line());
417
                return false;
418
            }
419
            try {
420
                int lineNumber = Integer.parseInt(lineNumberTextField.getText());
421
                if (lineNumber <= 0) {
422
                    setErrorMessage(Bundle.CustomizerController_invalid_line());
423
                    return false;
424
                }
425
            } catch (NumberFormatException nfe) {
426
                setErrorMessage(Bundle.CustomizerController_invalid_line());
427
                isValid = false;
428
            }
429
430
            if (isValid) {
431
                setErrorMessage(null);
432
            }
433
            return isValid;
434
        }
435
436
        @Override
437
        public void addPropertyChangeListener(PropertyChangeListener l) {
438
            propertyChangeSupport.addPropertyChangeListener(l);
439
        }
440
441
        @Override
442
        public void removePropertyChangeListener(PropertyChangeListener l) {
443
            propertyChangeSupport.removePropertyChangeListener(l);
444
        }
445
446
        void firePropertyChange() {
447
            propertyChangeSupport.firePropertyChange(Controller.PROP_VALID, null, null);
448
        }
449
450
        void setErrorMessage(String message) {
451
            errorMessage = message;
452
            propertyChangeSupport.firePropertyChange(NotifyDescriptor.PROP_ERROR_NOTIFICATION, null, message);
453
        }
454
455
        String getErrorMessage() {
456
            return errorMessage;
457
        }
458
459
        private void showMessageDialog(String message) {
460
            NotifyDescriptor descr = new NotifyDescriptor.Message(message);
461
            DialogDisplayer.getDefault().notify(descr);
462
        }
463
464
    }
465
466
}

Return to bug 132066