|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2018 Red Hat Inc. and others. |
| 2 | + * Copyright (c) 2018, 2023 Red Hat Inc. and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials are made
|
5 | 5 | * available under the terms of the Eclipse Public License 2.0
|
|
17 | 17 | import static org.eclipse.wildwebdeveloper.debug.SelectionUtils.pathOrEmpty;
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
| 20 | +import java.net.MalformedURLException; |
| 21 | +import java.net.URL; |
| 22 | +import java.text.MessageFormat; |
20 | 23 |
|
21 | 24 | import org.eclipse.core.resources.ResourcesPlugin;
|
22 | 25 | import org.eclipse.core.runtime.CoreException;
|
@@ -82,7 +85,9 @@ public void createControl(Composite parent) {
|
82 | 85 | .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
|
83 | 86 | decoration.setImage(fieldDecoration.getImage());
|
84 | 87 | this.programPathText.addModifyListener(event -> {
|
| 88 | + setDirty(true); |
85 | 89 | validateProgramPath();
|
| 90 | + updateLaunchConfigurationDialog(); |
86 | 91 | });
|
87 | 92 | filePath = new Button(resComposite, SWT.PUSH);
|
88 | 93 | filePath.setText(Messages.AbstractRunHTMLDebugTab_browse);
|
@@ -115,6 +120,7 @@ public void createControl(Composite parent) {
|
115 | 120 | urlText.setLayoutData(urlTextGD);
|
116 | 121 | urlText.addModifyListener(e -> {
|
117 | 122 | setDirty(true);
|
| 123 | + validateProgramPath(); |
118 | 124 | updateLaunchConfigurationDialog();
|
119 | 125 | });
|
120 | 126 |
|
@@ -153,33 +159,43 @@ public void createControl(Composite parent) {
|
153 | 159 | private void validateProgramPath() {
|
154 | 160 | setDirty(true);
|
155 | 161 |
|
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(); |
177 | 177 | }
|
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); |
181 | 193 | decoration.show();
|
| 194 | + } else { |
| 195 | + setErrorMessage(null); |
| 196 | + decoration.hide(); |
182 | 197 | }
|
| 198 | + |
183 | 199 | updateLaunchConfigurationDialog();
|
184 | 200 | }
|
185 | 201 |
|
|
0 commit comments