QuickBuild2 Documentation
|
We use plugin setting to explain how to use the bean editor to generate plugin UI. As introduced in [QBTEAM:Write a Simple Plugin], user can provide a plugin setting class by overriding getPluginSettingClass() method in the plugin class. If provided, this class will be used by QuickBuild to generate plugin setting user interface. The setting will be saved as an instance of this class and can be retrieved later through getPluginSetting() method when this plugin runs. Let's start with a very simple plugin setting class: A simple editorpublic class PluginSetting { public enum FaithType {CHRISTIANISM, CATHOLICISM, BUDDHISM, ISLAMISM, JUDAISM}; private String name; private FaithType faith; private boolean married; private Date birthday; private int workingYears; @Editable(order=100, description="Specify the name") public String getName() { return name; } public void setName(String name) { this.name = name; } @Editable(order=200, description="Choose your faith") public FaithType getFaith() { return faith; } public void setFaith(FaithType faith) { this.faith = faith; } @Editable(order=300, name="Are You Married?") public boolean isMarried() { return married; } public void setMarried(boolean married) { this.married = married; } @Editable(order=400) public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } @Editable(order=500) public int getWorkingYears() { return workingYears; } public void setWorkingYears(int workingYears) { this.workingYears = workingYears; } } By specifying the @Editable annotation for getter method, that property will be editable with user interface. The generated interface to edit this plugin setting looks as following: Please note:
List editorQuickBuild editor is able to generate user interface to edit list if the list element is of the same type. For example in the above plugin, we add a new property of type List to this class as follows: public class PluginSetting { ... private List<Dog> dogs; ... @Editable(order=600) public List getDogs() { return dogs; } public void setDogs(List<Dog> dogs) { this.dogs = dogs; } } And the Dog bean is defined as: public class Dog { public enum DogType {HUNTAWAY, MASTIFF, CHOWCHOW, MALAMUTE}; private String name; private int age; private DogType type; @Editable(order=100) public String getName() { return name; } public void setName(String name) { this.name = name; } @Editable(order=200) public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Editable(order=300) public DogType getType() { return type; } public void setType(DogType type) { this.type = type; } } The resulting edit page will look like: Please note that:
Polymorphic editorQuickBuild editor is able to generate user interface to edit polymorphic properties. For example, for the plugin setting class above: public class PluginSetting { ... Private Vehicle vehicle; ... @Editable(order=700) public Vehicle getVehicle() { return vehicle; } public void setVehicle(Vehicle vehicle) { this.vehicle = vehicle; } } Vehicle class is defined as: public abstract class Vehicle { private String manufacturer; private int price; @Editable(order=100) @NotEmpty public String getManufacturer() { return manufacturer; } public void setManufacturer(String manufacturer) { this.manufacturer = manufacturer; } @Editable(order=200) @Range(min=100, max=1000000) public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } } and Vehicle class has two implementations subclasses in the same package as the Vehicle class: SUV and Car: @Editable(name="SUV") public class SUV extends Vehicle { private int size; @Editable(order=1000) public int getSize() { return size; } public void setSize(int size) { this.size = size; } } @Editable(name="Car") public class Car extends Vehicle { private int maxSpeed; @Editable(order=1000) public int getMaxSpeed() { return maxSpeed; } public void setMaxSpeed(int maxSpeed) { this.maxSpeed = maxSpeed; } } Then the user interface for the plugin will be:
Edit variablesVariables are widely used in QuickBuild to add flexibility. To define variables: public class PluginSetting { ... private List<Variable> attributes; ... @Editable(order=800, description="Specify some attributes") public List<Variable> getAttributes { return attributes; } public void setAttributes(List<Variable> attributes) { this.attributes = attributes; } } The editor recognizes a variable definition automatically and provides following interface to define variables (the last property attributes): Expression edit helperSometimes the bean defines property that expects expressions. Proving some predefined expressions will be convenient for the user. The annotation PresetExpressions serves this purpose. For example: public class PluinSetting { ... private String runCondition; ... @Editable(order=600, name="Condition to Run") @Expressions({ "always run", "true", "do not run", "false" }) public String getRunCondition() { return runCondition; } public void setRunCondition(String runCondition) { this.runCondition = runCondition; } } The generated user interface will be: public class PluginSetting { ... private String runNode; ... @Editable(order=700, name="Node Address to Run") @ExpressionProvider("getAvailableNodes") public String getRunNode() { return runNode; } public void setRunNode(String runNode) { this.runNode = runNode; } private Map<String, String> getAvailableNodes() { Map<String, String> availableNodes = new LinkedHashMap<String, String>(); Collection<BuildGridNode> allNodes = Quickbuild.getInstance(BuildGrid.class).getAllNodes(); for (BuildGridNode node: allNodes) { availableNodes.put("node '" + node.getAddress() + "'", node.getAddress()); } return availableNodes; } } As the code demonstrates, the @ExpressionProvider annotation specifies a method in the bean, which QuickBuild can call to get the expressions associated with the menu and the generated user interface looks as follows: Input validation
You may specify validation annotation(s) to the properties to put restraint on values of these properties. For example: @Editable(order=200, description="Specify the faith") @NotNull public FaithType getFaith() { Return faith; } @Editable(order=500) @Range(0, 100) public int getWorkingYears() { return workingYears; } The validation annotations are the annotation validations defined in Hibernate validation framework.
Enable scripting support |