Skip to content

Commit 79dac8a

Browse files
author
Vitaliy
authored
Merge pull request #308 from bohdan-harniuk/306-add-highlighting-to-inputs-on-error
306: Added highlighting in error style to JComponent elements
2 parents 85448f7 + f6a46bb commit 79dac8a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2plugin.actions.generation.dialog;
77

8+
import com.magento.idea.magento2plugin.actions.generation.dialog.util.HighlightDialogFieldOnErrorUtil;
89
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
910
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidations;
1011
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.ValidationRule;
@@ -74,6 +75,7 @@ protected boolean validateFormFields() {
7475
if (errorMessageFieldValidationRuleMap.containsKey(field)
7576
&& errorMessageFieldValidationRuleMap.get(field).containsKey(rule)) {
7677
showErrorMessage(errorMessageFieldValidationRuleMap.get(field).get(rule));
78+
highlightFieldWithErrorStyle(field);
7779
}
7880
return false;
7981
}
@@ -186,4 +188,17 @@ private String resolveFieldValueByComponentType(final Object field) {
186188
}
187189
return null;
188190
}
191+
192+
/**
193+
* Highlight field with error style.
194+
*
195+
* @param field Object
196+
*/
197+
private void highlightFieldWithErrorStyle(final Object field) {
198+
if (field instanceof JTextField) {
199+
HighlightDialogFieldOnErrorUtil.execute((JTextField) field);
200+
} else if (field instanceof JComboBox) {
201+
HighlightDialogFieldOnErrorUtil.execute((JComboBox) field);
202+
}
203+
}
189204
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.magento.idea.magento2plugin.actions.generation.dialog.util;
2+
3+
import java.awt.Color;
4+
import java.awt.event.FocusEvent;
5+
import java.awt.event.FocusListener;
6+
import javax.swing.BorderFactory;
7+
import javax.swing.JComponent;
8+
9+
public final class HighlightDialogFieldOnErrorUtil {
10+
private static final Color ERROR_BORDER_COLOR = new Color(252, 119, 83);
11+
private static final Color ERROR_BACKGROUND_COLOR = new Color(252, 119, 83, 15);
12+
13+
private HighlightDialogFieldOnErrorUtil() {}
14+
15+
/**
16+
* Add error highlighting for JComponent.
17+
*
18+
* @param field JComponent
19+
*/
20+
public static void execute(final JComponent field) {
21+
final Color defaultBackgroundColor = field.getBackground();
22+
23+
field.setBorder(BorderFactory.createLineBorder(ERROR_BORDER_COLOR));
24+
field.setBackground(ERROR_BACKGROUND_COLOR);
25+
26+
field.addFocusListener(new FocusListener() {
27+
@Override
28+
public void focusGained(final FocusEvent event) {
29+
field.setBorder(null);
30+
field.setBackground(defaultBackgroundColor);
31+
}
32+
33+
@Override
34+
public void focusLost(FocusEvent e) {}//NOPMD
35+
});
36+
}
37+
}

0 commit comments

Comments
 (0)