12
12
package com .redhat .devtools .lsp4ij .settings .ui ;
13
13
14
14
import com .intellij .openapi .ui .ValidationInfo ;
15
- import com .intellij .ui .DocumentAdapter ;
16
15
import com .intellij .ui .JBColor ;
17
- import com .intellij .ui .components .JBTextArea ;
18
- import com .intellij .ui .components .JBTextField ;
19
16
import com .intellij .util .ui .JBUI ;
20
- import org .jetbrains .annotations .NotNull ;
21
17
22
18
import javax .swing .*;
23
- import javax . swing . event . DocumentEvent ;
19
+ import java . util . List ;
24
20
import java .awt .*;
25
- import java .awt .event .FocusAdapter ;
26
- import java .awt .event .FocusEvent ;
27
21
28
22
/**
29
23
* A shared interface meant to simplify creating validatable components used in
@@ -40,47 +34,5 @@ default void setErrorBorder(JComponent jComponent) {
40
34
jComponent .setBorder (JBUI .Borders .customLine (color , 1 ));
41
35
}
42
36
43
- /**
44
- * Add listeners that handle input validation. The first instance of validation should run on focus
45
- * and then on each change
46
- * @param jComponent interface implementor (e.g. addListeners(this);)
47
- */
48
- default void addListeners (JComponent jComponent ) {
49
- jComponent .addFocusListener (new FocusAdapter () {
50
- @ Override
51
- public void focusGained (FocusEvent e ) {
52
- validateInput ();
53
- super .focusGained (e );
54
- }
55
- });
56
-
57
- DocumentAdapter adapter = new DocumentAdapter () {
58
- @ Override
59
- protected void textChanged (@ NotNull DocumentEvent e ) {
60
- validateInput ();
61
- }
62
- };
63
- if (jComponent instanceof JBTextField jbTextField ) {
64
- jbTextField .getDocument ().addDocumentListener (adapter );
65
- } else if (jComponent instanceof JBTextArea jbTextArea ) {
66
- jbTextArea .getDocument ().addDocumentListener (adapter );
67
- }
68
- }
69
-
70
- /**
71
- * Overridable method that implements the field validation
72
- * Handles updating the style of the component for error/valid
73
- */
74
- void validateInput ();
75
-
76
- /**
77
- * Overridable method that returns a ValidationInfo, is the component is not valid
78
- * @return a ValidationInfo element if component validation fails, null if component is valid
79
- */
80
- ValidationInfo getValidationInfo ();
81
-
82
- /**
83
- * Overridable method that has to implement the validation check
84
- */
85
- boolean isValid ();
37
+ void validate (List <ValidationInfo > validations );
86
38
}
0 commit comments