vendredi 2 février 2018

How to set value of parameter of the custom annotation

I created own annotations, for creating visualization components. Following annotation is used during the creation of a combo-boxes.

@Retention(value = RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SelectParam {

    public String paramName() default "param";

    public int defaultIndex() default 0;

    public String[] options() default "";
}

It is perfectly when I have 5 or fewer options. I can use it as follow:

@SelectParam(options = {"NON ORDERED", "ORDERED"}, paramName = "order")
public void setTreeType(final String index) {
    switch (index) {
        case "NON ORDERED":
            fdt = new FDTu(fdt);
            break;
        case "ORDERED":
            fdt = new FDTo(fdt);
            break;
    }
    outputFDTport.setClassifier(fdt);
}

I have problem, when I want to create combobox, where his items are stored in array, or List. Is there any possilbe way how to initialize value to anotattion parameter by array? eq. something like this:

String [] opts = {"NON ORDERED", "ORDERED"}; 
@SelectParam(options = opts, paramName = "order")
public void setTreeType(final String index) {
    switch (index) {
        case "NON ORDERED":
            fdt = new FDTu(fdt);
            break;
        case "ORDERED":
            fdt = new FDTo(fdt);
            break;
    }
    outputFDTport.setClassifier(fdt);
}





Aucun commentaire:

Enregistrer un commentaire