Skip to content

Commit db538f8

Browse files
committed
Unnecessary error message is printed to the header of the debug configurations wizard for "Chrome Debug" if URL is selected #1295
Fixes: #1295
1 parent 4e536d5 commit db538f8

File tree

3 files changed

+45
-27
lines changed

3 files changed

+45
-27
lines changed

org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/AbstractRunHTMLDebugTab.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 Red Hat Inc. and others.
2+
* Copyright (c) 2018, 2023 Red Hat Inc. and others.
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -17,6 +17,9 @@
1717
import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.pathOrEmpty;
1818

1919
import java.io.File;
20+
import java.net.MalformedURLException;
21+
import java.net.URL;
22+
import java.text.MessageFormat;
2023

2124
import org.eclipse.core.resources.ResourcesPlugin;
2225
import org.eclipse.core.runtime.CoreException;
@@ -82,7 +85,9 @@ public void createControl(Composite parent) {
8285
.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
8386
decoration.setImage(fieldDecoration.getImage());
8487
this.programPathText.addModifyListener(event -> {
88+
setDirty(true);
8589
validateProgramPath();
90+
updateLaunchConfigurationDialog();
8691
});
8792
filePath = new Button(resComposite, SWT.PUSH);
8893
filePath.setText(Messages.AbstractRunHTMLDebugTab_browse);
@@ -115,6 +120,7 @@ public void createControl(Composite parent) {
115120
urlText.setLayoutData(urlTextGD);
116121
urlText.addModifyListener(e -> {
117122
setDirty(true);
123+
validateProgramPath();
118124
updateLaunchConfigurationDialog();
119125
});
120126

@@ -153,33 +159,43 @@ public void createControl(Composite parent) {
153159
private void validateProgramPath() {
154160
setDirty(true);
155161

156-
File file;
157-
try {
158-
file = new File(VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programPathText.getText()));
159-
if (!file.isFile()) {
160-
String errorMessage = Messages.RunProgramTab_error_unknownFile;
161-
setErrorMessage(errorMessage);
162-
decoration.setDescriptionText(errorMessage);
163-
decoration.show();
164-
} else if (!shortcut.canLaunch(file)) {
165-
String errorMessage = "Not a html file"; //$NON-NLS-1$
166-
setErrorMessage(errorMessage);
167-
decoration.setDescriptionText(errorMessage);
168-
decoration.show();
169-
} else if (!file.canRead()) {
170-
String errorMessage = Messages.RunProgramTab_error_nonReadableFile;
171-
setErrorMessage(errorMessage);
172-
decoration.setDescriptionText(errorMessage);
173-
decoration.show();
174-
} else {
175-
setErrorMessage(null);
176-
decoration.hide();
162+
String errorMessage = null;
163+
if (fileRadio.getSelection()) {
164+
try {
165+
if (programPathText.getText().length() > 0) {
166+
File file = new File(VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programPathText.getText()));
167+
if (!file.isFile()) {
168+
errorMessage = Messages.RunProgramTab_error_unknownFile;
169+
} else if (!shortcut.canLaunch(file)) {
170+
errorMessage = "Not a html file"; //$NON-NLS-1$
171+
} else if (!file.canRead()) {
172+
errorMessage = Messages.RunProgramTab_error_nonReadableFile;
173+
}
174+
}
175+
} catch (CoreException ex) {
176+
errorMessage = ex.getMessage();
177177
}
178-
} catch (CoreException ex) {
179-
setErrorMessage(ex.getMessage());
180-
decoration.setDescriptionText(ex.getMessage());
178+
} else if (urlRadio.getSelection()) {
179+
if (urlText.getText().length() > 0) {
180+
try {
181+
new URL(urlText.getText());
182+
} catch (MalformedURLException ex) {
183+
errorMessage = MessageFormat.format(
184+
Messages.RunProgramTab_error_malformedUR,
185+
ex.getMessage());
186+
}
187+
}
188+
}
189+
190+
if (errorMessage != null) {
191+
setErrorMessage(errorMessage);
192+
decoration.setDescriptionText(errorMessage);
181193
decoration.show();
194+
} else {
195+
setErrorMessage(null);
196+
decoration.hide();
182197
}
198+
183199
updateLaunchConfigurationDialog();
184200
}
185201

org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/Messages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 Red Hat Inc. and others.
2+
* Copyright (c) 2019, 2023 Red Hat Inc. and others.
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
@@ -28,6 +28,7 @@ public class Messages extends NLS {
2828
public static String RunProgramTab_error_nonReadableFile;
2929
public static String RunProgramTab_error_notJSFile;
3030
public static String RunProgramTab_error_unknownFile;
31+
public static String RunProgramTab_error_malformedUR;
3132
public static String RunProgramTab_program;
3233
public static String RunProgramTab_title;
3334
public static String RunProgramTab_workingDirectory;

org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
################################################################
2-
# Copyright (c) 2019 Red Hat Inc. and others.
2+
# Copyright (c) 2019, 2023 Red Hat Inc. and others.
33
#
44
# This program and the accompanying materials are made
55
# available under the terms of the Eclipse Public License 2.0
@@ -22,6 +22,7 @@ RunProgramTab_argument=Arguments
2222
RunProgramTab_error_nonReadableFile=Not allowed to read file.
2323
RunProgramTab_error_notJSFile=File is not a JS file.
2424
RunProgramTab_error_unknownFile=Given path doesn't reference a file.
25+
RunProgramTab_error_malformedUR=Malformed URL: ''{0}''.
2526
RunProgramTab_program=Program
2627
RunProgramTab_title=\u25B6\uFE0F Program
2728
RunProgramTab_workingDirectory=Working directory

0 commit comments

Comments
 (0)