- Common ways to obtain Controller
private void myMethod () {}
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); }
public static void install(final FormatController formatController) { Controller.getCurrentController().addExtension(FormatController.class, formatController); Controller.getCurrentController().addOptionValidator(formatController.createValidator()); }