use of org.freeplane.core.resources.components.IValidator in project freeplane by freeplane.
the class ScriptingRegistration method addPropertiesToOptionPanel.
private void addPropertiesToOptionPanel() {
final URL preferences = this.getClass().getResource("preferences.xml");
if (preferences == null)
throw new RuntimeException("cannot open preferences");
Controller.getCurrentController().addOptionValidator(new IValidator() {
@Override
public ValidationResult validate(Properties properties) {
final ValidationResult result = new ValidationResult();
final String readAccessString = properties.getProperty(ScriptingPermissions.RESOURCES_EXECUTE_SCRIPTS_WITHOUT_READ_RESTRICTION);
final String writeAccessString = properties.getProperty(ScriptingPermissions.RESOURCES_EXECUTE_SCRIPTS_WITHOUT_WRITE_RESTRICTION);
final String classpath = properties.getProperty(ScriptResources.RESOURCES_SCRIPT_CLASSPATH);
final boolean readAccess = readAccessString != null && Boolean.parseBoolean(readAccessString);
final boolean writeAccess = writeAccessString != null && Boolean.parseBoolean(writeAccessString);
final boolean classpathIsSet = classpath != null && classpath.length() > 0;
if (classpathIsSet && !readAccess) {
result.addError(TextUtils.getText("OptionPanel.validate_classpath_needs_readaccess"));
}
if (writeAccess && !readAccess) {
result.addWarning(TextUtils.getText("OptionPanel.validate_write_without_read"));
}
return result;
}
});
final MModeController modeController = (MModeController) Controller.getCurrentModeController();
modeController.getOptionPanelBuilder().load(preferences);
}
Aggregations