Deactivate validation if control is disabled

This commit is contained in:
0xboobface 2019-01-31 14:16:41 +01:00
parent 6e58dd6be5
commit 2616d318c0
4 changed files with 26 additions and 0 deletions

View File

@ -60,6 +60,16 @@ public abstract class AbstractFileSelectionBox extends HBox {
fileInput.disableProperty().bind(disableProperty());
browse.disableProperty().bind(disableProperty());
HBox.setHgrow(fileInput, Priority.ALWAYS);
disabledProperty().addListener((obs, oldV, newV) -> {
if (newV) {
hideValidationHints();
} else {
if (StringUtil.isNotBlank(fileInput.getText())) {
setFile(new File(fileInput.getText()));
}
}
});
}
public AbstractFileSelectionBox(String initialValue) {
@ -104,6 +114,10 @@ public abstract class AbstractFileSelectionBox extends HBox {
}
protected String validate(File file) {
if(isDisabled()) {
return null;
}
if (file == null || !file.exists()) {
return "File does not exist";
} else {

View File

@ -25,6 +25,10 @@ public class DirectorySelectionBox extends AbstractFileSelectionBox {
@Override
protected String validate(File file) {
if(isDisabled()) {
return null;
}
String msg = super.validate(file);
if(msg != null) {
return msg;

View File

@ -12,6 +12,10 @@ public class FileSelectionBox extends AbstractFileSelectionBox {
@Override
protected String validate(File file) {
if(isDisabled()) {
return null;
}
String msg = super.validate(file);
if(msg != null) {
return msg;

View File

@ -12,6 +12,10 @@ public class ProgramSelectionBox extends FileSelectionBox {
@Override
protected String validate(File file) {
if(isDisabled()) {
return null;
}
String msg = super.validate(file);
if(msg != null) {
return msg;