Options Management
From AIBenchWiki
Contents |
Problem
It will be useful that AIBench contains a sub-system to manage user preferences. Some plugins need a few "global" properties to be configured in order to perform their operations. Today this is done making ad-hoc operations to configure global properties.
Possible solution (current design decissions)
New concept "option"
An option has:
- id.
- Name.
- Type: number or string.
- Default value. Mandatory. The option should always have a value.
- Closed set of values. A list of a closed set of possible values.
Extend the plugin.xml schema
Allow the programmer to add a new item (at a root level) similar to:
<options>
<option id="option_name" name="option happy name" type="string" defaultValue="foo">
<value>bar</value>
<value>bar2</value>
</option>
</option>
New file: /conf/options.conf
The preferences will be stored in this file, which is managed by the AIBench Core. It is a Java properties standard file. Each option should be prefixed by its plugin uid.
aibench.core.httpproxyhost=proxy.foo.com aibench.core.httpproxyport=8080 my.plugin.uid.option_name=myvalue
Extend the AIBench Core API
The API should give access to read and modify the options via a programatically view. It will access and manage the /conf/options.conf file.
- Create a new class: es.uvigo.ei.aibench.core.PreferencesManager, which can be retrieved from the Core, similar to Clipboard or History:
Core.getInstance().getPreferencesManager();
- The PreferencesManager should have a few methods:
void addValidator(Validator validator); HashMap<String, Collection<String>> getPropertiesNames(); //a plugin-options mapping Object getProperty(String uid, Object option); void storeProperty(String uid, String name, Object value) throws IllegalArgumentException; //if any validator fails
Options validation
The PreferencesManager has a method to add validators: addValidator(Validator v).
- Create the interface Validator
public interface Validator{
// called from the storeProperty method
void validate(String option, Object value) throws IllegalArgumentException;
}
Extend the Workbench
In order to display a dialog to see and set the properties.
- It could show the options from each plugin (separatted in some visual way).
- The options with a closed set of possible values, should be rendered with a combo-box.
- The Workbench MUST rely in the Core to retrieve and save the user preferences. Add a new option to the /conf/workbench.conf to set how this menu is accessed. For example, add a path to place it in the menu:
preferencesmenu.path=/edit/preferences
Add a new operation annotation: @Option
Optionally, it will be very useful to avoid operations to call the Core API directly in order to retrieve a property value. This can be achieved more declaratively by adding a new method level annotation to the operations: @Option.
AIBench will call this method (before any port) if this annotation is found and the requested option is available. The @Option annotation has two properties:
- Option name (not followed by the plugin name)
- Plugin uid (optional). By default, AIBench looks for the option in the operation's plugin.
- Example:
@Operation(...)
public class MyOperation{
@Option(name="my_option" uid="the_plugin_uid")
void setOption(Object value){ ... }
...

