Skip to content

Commit c4b2799

Browse files
author
Mitja Leino
committed
Clean up and add missing docs
1 parent 43f88e9 commit c4b2799

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

@@ -19,7 +19,6 @@
1919
import com.intellij.openapi.fileTypes.FileNameMatcher;
2020
import com.intellij.openapi.fileTypes.FileType;
2121
import com.intellij.openapi.project.Project;
22-
import com.intellij.openapi.ui.DialogWrapper;
2322
import com.intellij.openapi.ui.ValidationInfo;
2423
import com.intellij.ui.IdeBorderFactory;
2524
import com.intellij.util.ui.FormBuilder;

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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 8 additions & 4 deletions
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

@@ -84,11 +85,14 @@ private void createUI(FormBuilder builder, JComponent description, EditionMode m
8485
addDebugTab(tabbedPane, mode);
8586

8687
// Add validation
87-
var serverName = getServerName();
88-
if (serverName != null) {
89-
addValidator(serverName);
88+
var serverNameWidget = getServerName();
89+
if (serverNameWidget != null) {
90+
addValidator(serverNameWidget);
91+
}
92+
var commandLineWidget = getCommandLine();
93+
if (commandLineWidget != null) {
94+
addValidator(getCommandLine());
9095
}
91-
addValidator(getCommandLine());
9296
}
9397

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

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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 15 additions & 1 deletion
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)