I have the following problem:
I’m implementing a RCP application based on Netbeans platform. I added a new custom secondary option panel to the application.
After designing the panel and setting up the proper methods (I implemented the part that is calling the changed method from the controller when fields change) I modified the valid method from the option panel (the view) to have a proper validation on all the fields. From what I understood this is called by the controller to validate the form before saving. The only issue is that this method is never called from what I can see so any validation that is done in it is not activated.
Could somebody tell me what I’m doing wrong? Thank you!
boolean valid() {
if (addressTextField.getText().isEmpty()) {
return false;
}
if (portTextField.getText().isEmpty()) {
return false;
}
if (userTextField.getText().isEmpty()) {
return false;
}
if (passwordPasswordField.getPassword().length == 0) {
return false;
}
if (databaseNameTextField.getText().isEmpty()) {
return false;
}
//TODO: change this back to the connection string builder after testing
String databaseURL = "jdbc:mysql://" + addressTextField.getText().trim() + ":" + portTextField.getText().trim() + "/" + databaseNameTextField.getText().trim() +
"?user=" + userTextField.getText().trim() + "&password=" + StringUtilities.charToString(passwordPasswordField.getPassword());
if(!SQLDatabaseConnectionManagerImpl.testPing(databaseURL)) {
messageLabel.setText("");
messageLabel.setForeground(Color.red);
messageLabel.setText(NbBundle.getBundle(ImportDataOptionsPanel.class).getString("ImportDataOptionsPanel.connectionErrorMessage.text"));
debug("Error on database connection with the following connection string: " + databaseURL, ImportDataOptionsPanel.IMPORTANT);
return false;
}
return true;
}
The hint is in this code comment
You need to tell the controller when something has changed and when to validate the data.
So in a simplistic scenario you could listen on a keytyped event and then called controller.changed()