Skip to content

Commit

Permalink
Clean up and add missing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitja Leino committed Apr 24, 2024
1 parent 2de6a9f commit 80a1f95
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
* Mitja Leino <[email protected]> - Extend ValidatableDialog for validations
******************************************************************************/
package com.redhat.devtools.lsp4ij.launching.ui;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* Contributors:
* Red Hat Inc. - initial API and implementation
* Mitja Leino <[email protected]> - Implement DialogWrapper for validations
* Mitja Leino <[email protected]> - Extend ValidatableDialog for validations
*******************************************************************************/
package com.redhat.devtools.lsp4ij.settings;

Expand All @@ -20,7 +20,6 @@
import com.intellij.openapi.fileTypes.FileNameMatcher;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.ui.FormBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.redhat.devtools.lsp4ij.LanguageServerBundle;

import javax.swing.border.Border;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -41,14 +42,17 @@ public CommandLineWidget() {

@Override
public void validate(List<ValidationInfo> validations) {
boolean valid = true;
List<ValidationInfo> widgetValidations = new ArrayList<>();

Check warning on line 45 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/CommandLineWidget.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L45 was not covered by tests

if (getDocument() != null && getText().isBlank()) {
setErrorBorder(this);
valid = false;
validations.add(new ValidationInfo(errorMessage, this));
widgetValidations.add(new ValidationInfo(errorMessage, this));

Check warning on line 48 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/CommandLineWidget.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L48 was not covered by tests
}
if (valid) {

if (widgetValidations.isEmpty()) {
this.setBorder(normalBorder);

Check warning on line 52 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/CommandLineWidget.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L52 was not covered by tests
} else {
validations.addAll(widgetValidations);
setErrorBorder(this);

Check warning on line 55 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/CommandLineWidget.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/CommandLineWidget.java#L54-L55

Added lines #L54 - L55 were not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
* Mitja Leino <[email protected]> - Add DialogWrapper for validations
******************************************************************************/
package com.redhat.devtools.lsp4ij.settings.ui;

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

Check warning on line 88 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/LanguageServerPanel.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L88 was not covered by tests
// Add validation
var serverName = getServerName();
if (serverName != null) {
addValidator(serverName);
var serverNameWidget = getServerName();
if (serverNameWidget != null) {
addValidator(serverNameWidget);

Check warning on line 92 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/LanguageServerPanel.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L92 was not covered by tests
}
var commandLineWidget = getCommandLine();
if (commandLineWidget != null) {
addValidator(getCommandLine());

Check warning on line 96 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/LanguageServerPanel.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L96 was not covered by tests
}
addValidator(getCommandLine());
}

private void addServerTab(JBTabbedPane tabbedPane, JComponent description, EditionMode mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.redhat.devtools.lsp4ij.LanguageServerBundle;

import javax.swing.border.Border;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -31,14 +32,17 @@ public ServerNameWidget() {

@Override
public void validate(List<ValidationInfo> validations) {
boolean isValid = true;
List<ValidationInfo> widgetValidations = new ArrayList<>();

Check warning on line 35 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L35 was not covered by tests

if (getDocument() != null && getText().isBlank()) {
setErrorBorder(this);
isValid = false;
validations.add(new ValidationInfo(errorMessage, this));
widgetValidations.add(new ValidationInfo(errorMessage, this));

Check warning on line 38 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L38 was not covered by tests
}
if (isValid) {

if (widgetValidations.isEmpty()) {
this.setBorder(originalBorder);

Check warning on line 42 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L42 was not covered by tests
} else {
validations.addAll(widgetValidations);
setErrorBorder(this);

Check warning on line 45 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java#L44-L45

Added lines #L44 - L45 were not covered by tests
}
}

Check warning on line 47 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ServerNameWidget.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L47 was not covered by tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ default void setErrorBorder(JComponent jComponent) {
jComponent.setBorder(JBUI.Borders.customLine(color, 1));
}

Check warning on line 35 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableConsoleWidget.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableConsoleWidget.java#L32-L35

Added lines #L32 - L35 were not covered by tests

/**
* Runs validations on the widget and handles border styling
* @param validations the dialog wrapper validation list,
* adds the validations to the list if there are any errors
*/
void validate(List<ValidationInfo> validations);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Mitja Leino <[email protected]> - Initial API and implementation
*******************************************************************************/
package com.redhat.devtools.lsp4ij.settings.ui;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;

/**
* Shareable component for shared validations using DialogWrapper
*/
public abstract class ValidatableDialog extends DialogWrapper {
public ValidatableDialog(Project project) {
protected ValidatableDialog(Project project) {
super(project);
}

Check warning on line 23 in src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableDialog.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/redhat/devtools/lsp4ij/settings/ui/ValidatableDialog.java#L22-L23

Added lines #L22 - L23 were not covered by tests

Expand Down

0 comments on commit 80a1f95

Please sign in to comment.