Search in sources :

Example 1 with IValidator

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);
}
Also used : IValidator(org.freeplane.core.resources.components.IValidator) Properties(java.util.Properties) ScriptAddOnProperties(org.freeplane.plugin.script.addons.ScriptAddOnProperties) URL(java.net.URL) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Aggregations

URL (java.net.URL)1 Properties (java.util.Properties)1 IValidator (org.freeplane.core.resources.components.IValidator)1 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)1 ScriptAddOnProperties (org.freeplane.plugin.script.addons.ScriptAddOnProperties)1