Skip to content

Commit 80a1f95

Browse files
author
Mitja Leino
committed
Clean up and add missing docs
1 parent 2de6a9f commit 80a1f95

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed

src/main/java/com/redhat/devtools/lsp4ij/launching/ui/NewLanguageServerDialog.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* Red Hat, Inc. - initial API and implementation
10+
* Mitja Leino <[email protected]> - Extend ValidatableDialog for validations
1011
******************************************************************************/
1112
package com.redhat.devtools.lsp4ij.launching.ui;
1213

src/main/java/com/redhat/devtools/lsp4ij/settings/LanguageServerView.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Contributors:
1212
* Red Hat Inc. - initial API and implementation
13-
* Mitja Leino <[email protected]> - Implement DialogWrapper for validations
13+
* Mitja Leino <[email protected]> - Extend ValidatableDialog for validations
1414
*******************************************************************************/
1515
package com.redhat.devtools.lsp4ij.settings;
1616

@@ -20,7 +20,6 @@
2020
import com.intellij.openapi.fileTypes.FileNameMatcher;
2121
import com.intellij.openapi.fileTypes.FileType;
2222
import com.intellij.openapi.project.Project;
23-
import com.intellij.openapi.ui.DialogWrapper;
2423
import com.intellij.openapi.ui.ValidationInfo;
2524
import com.intellij.ui.IdeBorderFactory;
2625
import com.intellij.util.ui.FormBuilder;

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/CommandLineWidget.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.redhat.devtools.lsp4ij.LanguageServerBundle;
2121

2222
import javax.swing.border.Border;
23+
import java.util.ArrayList;
2324
import java.util.List;
2425

2526
/**
@@ -41,14 +42,17 @@ public CommandLineWidget() {
4142

4243
@Override
4344
public void validate(List<ValidationInfo> validations) {
44-
boolean valid = true;
45+
List<ValidationInfo> widgetValidations = new ArrayList<>();
46+
4547
if (getDocument() != null && getText().isBlank()) {
46-
setErrorBorder(this);
47-
valid = false;
48-
validations.add(new ValidationInfo(errorMessage, this));
48+
widgetValidations.add(new ValidationInfo(errorMessage, this));
4949
}
50-
if (valid) {
50+
51+
if (widgetValidations.isEmpty()) {
5152
this.setBorder(normalBorder);
53+
} else {
54+
validations.addAll(widgetValidations);
55+
setErrorBorder(this);
5256
}
5357
}
5458
}

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/LanguageServerPanel.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* Red Hat, Inc. - initial API and implementation
10+
* Mitja Leino <[email protected]> - Add DialogWrapper for validations
1011
******************************************************************************/
1112
package com.redhat.devtools.lsp4ij.settings.ui;
1213

@@ -86,11 +87,14 @@ private void createUI(FormBuilder builder, JComponent description, EditionMode m
8687
addDebugTab(tabbedPane, mode);
8788

8889
// Add validation
89-
var serverName = getServerName();
90-
if (serverName != null) {
91-
addValidator(serverName);
90+
var serverNameWidget = getServerName();
91+
if (serverNameWidget != null) {
92+
addValidator(serverNameWidget);
93+
}
94+
var commandLineWidget = getCommandLine();
95+
if (commandLineWidget != null) {
96+
addValidator(getCommandLine());
9297
}
93-
addValidator(getCommandLine());
9498
}
9599

96100
private void addServerTab(JBTabbedPane tabbedPane, JComponent description, EditionMode mode) {

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.redhat.devtools.lsp4ij.LanguageServerBundle;
1717

1818
import javax.swing.border.Border;
19+
import java.util.ArrayList;
1920
import java.util.List;
2021

2122
/**
@@ -31,14 +32,17 @@ public ServerNameWidget() {
3132

3233
@Override
3334
public void validate(List<ValidationInfo> validations) {
34-
boolean isValid = true;
35+
List<ValidationInfo> widgetValidations = new ArrayList<>();
36+
3537
if (getDocument() != null && getText().isBlank()) {
36-
setErrorBorder(this);
37-
isValid = false;
38-
validations.add(new ValidationInfo(errorMessage, this));
38+
widgetValidations.add(new ValidationInfo(errorMessage, this));
3939
}
40-
if (isValid) {
40+
41+
if (widgetValidations.isEmpty()) {
4142
this.setBorder(originalBorder);
43+
} else {
44+
validations.addAll(widgetValidations);
45+
setErrorBorder(this);
4246
}
4347
}
4448

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableConsoleWidget.java

+5
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ default void setErrorBorder(JComponent jComponent) {
3434
jComponent.setBorder(JBUI.Borders.customLine(color, 1));
3535
}
3636

37+
/**
38+
* Runs validations on the widget and handles border styling
39+
* @param validations the dialog wrapper validation list,
40+
* adds the validations to the list if there are any errors
41+
*/
3742
void validate(List<ValidationInfo> validations);
3843
}

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableDialog.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Red Hat Inc. and others.
3+
* This program and the accompanying materials are made
4+
* available under the terms of the Eclipse Public License 2.0
5+
* which is available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Mitja Leino <[email protected]> - Initial API and implementation
11+
*******************************************************************************/
112
package com.redhat.devtools.lsp4ij.settings.ui;
213

314
import com.intellij.openapi.project.Project;
415
import com.intellij.openapi.ui.DialogWrapper;
516

17+
/**
18+
* Shareable component for shared validations using DialogWrapper
19+
*/
620
public abstract class ValidatableDialog extends DialogWrapper {
7-
public ValidatableDialog(Project project) {
21+
protected ValidatableDialog(Project project) {
822
super(project);
923
}
1024

0 commit comments

Comments
 (0)