Skip to content

Commit

Permalink
Add ValidatableDialog class
Browse files Browse the repository at this point in the history
  • Loading branch information
MituuZ committed Apr 21, 2024
1 parent 255af39 commit 49ccd6c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.SimpleListCellRenderer;
Expand All @@ -25,6 +24,7 @@
import com.redhat.devtools.lsp4ij.launching.templates.LanguageServerTemplateManager;
import com.redhat.devtools.lsp4ij.server.definition.launching.UserDefinedLanguageServerDefinition;
import com.redhat.devtools.lsp4ij.settings.ui.LanguageServerPanel;
import com.redhat.devtools.lsp4ij.settings.ui.ValidatableDialog;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -39,7 +39,7 @@
/**
* New language server dialog.
*/
public class NewLanguageServerDialog extends DialogWrapper {
public class NewLanguageServerDialog extends ValidatableDialog {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L42 was not covered by tests

private final ComboBox<LanguageServerTemplate> templateCombo = new ComboBox<>(new DefaultComboBoxModel<>(getLanguageServerTemplates()));
private final Project project;
Expand Down Expand Up @@ -69,7 +69,7 @@ public NewLanguageServerDialog(@NotNull Project project) {
// Template combo
createTemplateCombo(builder);
// Create server name, command line, mappings, configuration UI
this.languageServerPanel = new LanguageServerPanel(builder, null, LanguageServerPanel.EditionMode.NEW_USER_DEFINED);
this.languageServerPanel = new LanguageServerPanel(builder, null, LanguageServerPanel.EditionMode.NEW_USER_DEFINED, this);

Check warning on line 72 in src/main/java/com/redhat/devtools/lsp4ij/launching/ui/NewLanguageServerDialog.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L72 was not covered by tests

// Add validation
addValidator(this.languageServerPanel.getServerName());
Expand Down Expand Up @@ -164,20 +164,9 @@ public JComponent getPreferredFocusedComponent() {

@Override
protected @NotNull List<ValidationInfo> doValidateAll() {
List<ValidationInfo> validations = new ArrayList<>();
addValidationInfo(this.languageServerPanel.getCommandLine().getValidationInfo(), validations);
addValidationInfo(this.languageServerPanel.getServerName().getValidationInfo(), validations);
return validations;
return languageServerPanel.doValidateAll();

Check warning on line 167 in src/main/java/com/redhat/devtools/lsp4ij/launching/ui/NewLanguageServerDialog.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L167 was not covered by tests
}

private void addValidationInfo(ValidationInfo validationInfo, List<ValidationInfo> validations) {
if (validationInfo == null) {
return;
}
validations.add((validationInfo));
}


@Override
protected void doOKAction() {
super.doOKAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.redhat.devtools.lsp4ij.server.definition.launching.UserDefinedLanguageServerDefinition;
import com.redhat.devtools.lsp4ij.settings.ui.LanguageServerPanel;
import com.redhat.devtools.lsp4ij.settings.ui.ServerMappingsPanel;
import com.redhat.devtools.lsp4ij.settings.ui.ValidatableDialog;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -51,7 +52,7 @@
* <li>Suspend and wait for a debugger?</li>
* </ul>
*/
public class LanguageServerView extends DialogWrapper implements Disposable {
public class LanguageServerView extends ValidatableDialog implements Disposable {

private final LanguageServerNameProvider languageServerNameProvider;

Expand All @@ -71,7 +72,7 @@ public LanguageServerView(@NotNull LanguageServerDefinition languageServerDefini
@Nullable LanguageServerNameProvider languageServerNameProvider,
@NotNull Project project
) {
super(true);
super(project);

Check warning on line 75 in src/main/java/com/redhat/devtools/lsp4ij/settings/LanguageServerView.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L75 was not covered by tests
this.languageServerDefinition = languageServerDefinition;
this.languageServerNameProvider = languageServerNameProvider;
this.project = project;
Expand Down Expand Up @@ -288,7 +289,7 @@ private JPanel createSettings(JComponent description, boolean launchingServerDef
this.languageServerPanel = new LanguageServerPanel(builder,
description,
launchingServerDefinition ? LanguageServerPanel.EditionMode.EDIT_USER_DEFINED :
LanguageServerPanel.EditionMode.EDIT_EXTENSION);
LanguageServerPanel.EditionMode.EDIT_EXTENSION, this);

Check warning on line 292 in src/main/java/com/redhat/devtools/lsp4ij/settings/LanguageServerView.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L292 was not covered by tests
this.mappingPanel = languageServerPanel.getMappingsPanel();
return builder
.addComponentFillVertically(new JPanel(), 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.ui.*;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBScrollPane;
Expand All @@ -25,7 +26,11 @@
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
* Language server panel which show information about language server in several tabs:
Expand Down Expand Up @@ -56,8 +61,10 @@ public enum EditionMode {
private LanguageServerConfigurationWidget configurationWidget;

private LanguageServerInitializationOptionsWidget initializationOptionsWidget;
private final ValidatableDialog dialogWrapper;

Check warning on line 64 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#L64

Added line #L64 was not covered by tests

public LanguageServerPanel(FormBuilder builder, JComponent description, EditionMode mode) {
public LanguageServerPanel(FormBuilder builder, JComponent description, EditionMode mode, ValidatableDialog dialogWrapper) {
this.dialogWrapper = dialogWrapper;

Check warning on line 67 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#L66-L67

Added lines #L66 - L67 were not covered by tests
createUI(builder, description, mode);
}

Expand All @@ -75,6 +82,13 @@ private void createUI(FormBuilder builder, JComponent description, EditionMode m
}
// Debug tab
addDebugTab(tabbedPane, mode);

// Add validation
var serverName = getServerName();

Check warning on line 87 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#L86-L87

Added lines #L86 - L87 were not covered by tests
if (serverName != null) {
addValidator(serverName);
}
addValidator(getCommandLine());

Check warning on line 91 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#L89-L91

Added lines #L89 - L91 were not covered by tests
}

private void addServerTab(JBTabbedPane tabbedPane, JComponent description, EditionMode mode) {
Expand Down Expand Up @@ -229,4 +243,34 @@ public ComboBox<ServerTrace> getServerTraceComboBox() {
public ComboBox<ErrorReportingKind> getErrorReportingKindCombo() {
return errorReportingKindCombo;
}

public @NotNull List<ValidationInfo> doValidateAll() {
List<ValidationInfo> validations = new ArrayList<>();
var serverName = getServerName();

Check warning on line 249 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#L248-L249

Added lines #L248 - L249 were not covered by tests
if (serverName != null) {
addValidationInfo(serverName.getValidationInfo(), validations);

Check warning on line 251 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#L251

Added line #L251 was not covered by tests
}
var commandLine = getCommandLine();

Check warning on line 253 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#L253

Added line #L253 was not covered by tests
if (commandLine != null) {
addValidationInfo(commandLine.getValidationInfo(), validations);

Check warning on line 255 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#L255

Added line #L255 was not covered by tests
}
return validations;

Check warning on line 257 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#L257

Added line #L257 was not covered by tests
}

private void addValidationInfo(ValidationInfo validationInfo, List<ValidationInfo> validations) {
if (validationInfo == null) {
return;

Check warning on line 262 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#L262

Added line #L262 was not covered by tests
}
validations.add((validationInfo));
}

Check warning on line 265 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#L264-L265

Added lines #L264 - L265 were not covered by tests


private void addValidator(JTextComponent textComponent) {
textComponent.getDocument().addDocumentListener(new DocumentAdapter() {

Check warning on line 269 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#L269

Added line #L269 was not covered by tests
@Override
protected void textChanged(@NotNull DocumentEvent e) {
dialogWrapper.refreshValidation();
}

Check warning on line 273 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#L272-L273

Added lines #L272 - L273 were not covered by tests
});
}

Check warning on line 275 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#L275

Added line #L275 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.redhat.devtools.lsp4ij.settings.ui;

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

public abstract class ValidatableDialog extends DialogWrapper {
public ValidatableDialog(Project project) {
super(project);
}

Check warning on line 9 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#L8-L9

Added lines #L8 - L9 were not covered by tests

public void refreshValidation() {
super.initValidation();
}

Check warning on line 13 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#L12-L13

Added lines #L12 - L13 were not covered by tests

@Override
protected boolean continuousValidation() {
return false;

Check warning on line 17 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#L17

Added line #L17 was not covered by tests
}
}

0 comments on commit 49ccd6c

Please sign in to comment.