doValidate() not getting invoked when Panel from class is added in createCenterPanel()

Answered

I have extended dialog wrapper as below:

public class MyCustomDialog extends DialogWrapper {

private MyScreen myScreen;
public MyCustomDialog(){
super(false);
init();
}

@Override
protected JComponent createCenterPanel(){
myScreen = new MyScreen();
return myScreen.getRootPanel();
}

@Override
protected ValidationInfo doValidate(){
String element1 = myScreen.getTextFieldElement1().getText().trim();
String fileLocation = myScreen.getTextFieldFileLocation().getText().trim();

if(element1.equals("<some value>")){
return new ValidationInfo("Error");
} else if (fileLocation.equals("<some value>")){
return new ValidationInfo("Error");
}
return null;
}

}

MyScreen is having .form as UI and related java class is something like:


public class MyClass{
private JPanel panel;
private JTextField textFieldElement1;
private TextFieldWithBrowseButton textFieldFileLocation;

public JTextField getTextFieldElement1(){
return textFieldElement1;
}

public TextFieldWithBrowseButton getTextFieldFileLocation(){
return textFieldFileLocation;
}

public JPanel getRootPanel(){
return panel;
}

}

When createCenterPanel() of dialog wrapper creates UI from this MyScreen or any other similar class, doValidate() does not get invoked automatically. It does not getting invoked automatically as mentioned https://jetbrains.org/intellij/sdk/docs/user_interface_components/dialog_wrapper.html#dialogwrapper

Is doValidate() meant for invoked automatically only for the Panel created through code inside createCenterPanel() ?

@...: any help is appreciated.

 

0
4 comments
Avatar
Permanently deleted user

First time validation is being called just after you press OK button. Then is proceed on the fly when you type etc.

Your example works for me.

Please note that you can specify a component in ValidationInfo like this:

if(element1.equals("<some value>")){
return new ValidationInfo("Error", myScreen.getTextFieldElement1());
} else if (fileLocation.equals("<some value>")){
return new ValidationInfo("Error", myScreen.getTextFieldFileLocation());
}
1

Thank you for the reply. 

I got your point. 

I am working on creating plugin for Android Studio. Now if the validation triggers first time when the OK button is clicked, I wonder how it is handled in New Project option of Android Studio. While creating new project, for project name, as soon as the project name is entered and it contains not recommended value like numbers or anything, it starts popping warning immediately without OK click. Even when the default project suggestion is deleted, It immediately shows error without Action click.

Any suggestion how it can be achieved? Is it through some listeners?

0
Avatar
Permanently deleted user

Please override com.intellij.openapi.ui.DialogWrapper#postponeValidation in MyCustomDialog

1

Overriding com.intellij.openapi.ui.DialogWrapper#postponeValidation starts immediate  validation. And I think that is the reason that Android Studio -> New Project option has pre-filled value which pass the validation. Overall, I am clear on the working of this.

Thank you.

0

Please sign in to leave a comment.