How to add values to ChooserValues class at runtime (Creating a custom destination)

asked 2018-10-26 08:41:56 -0600

Hello all,

I am implementing an custom destination where in one tab/field I ask the user to enter a string ModelNodeName corresponding to node names: public class ModelNodeName {

private static final Logger LOG = LoggerFactory.getLogger(ModelNodeName.class);


public ModelNodeName() {
    LOG.debug("*_*_*_*_Adding a new NodeName_*_*_*_*");
}

@ConfigDef(
        required = true,
        type = ConfigDef.Type.STRING,
        defaultValue = "",
        label = "Name",
        description = "Name of the node to be created",
        displayPosition = 10,
        group = "MODEL"
)
public String modelNodeName;

These strings ultimately are added to a List of ModelNodeName which has the annotation @ListBeanModel:

  @ConfigDef(
          required = true,
          type = ConfigDef.Type.MODEL,
          defaultValue = "",
          label = "Nodes",
          description = "Nodes",
          displayPosition = 10,
          group = "MODEL"
  )
  @ListBeanModel
  public List<ModelNodeName> modelNodeNames;

In a another tab I added a field of the type ConfigDef.Type.MODEL, which has the annotation @ValueChooserModel:

public class ModelNodeDetailsConfig {
    public ModelNodeDetailsConfig(){

    }

    @ConfigDef(
            required = true,
            type = ConfigDef.Type.MODEL,
            defaultValue = "",
            label = "Node",
            description = "The node associated to this property",
            dependsOn = "^[Neo4jDTarget.modelNodeNames]",
            displayPosition = 1,
            group = "MODEL"
    )
    @ValueChooserModel(NodeNameChooserValues.class)
    public String nodeNameProperty;

This is associated to a class NodeNameChooserValues that implements the ChooserValues:

public class NodeNameChooserValues implements ChooserValues {

    private static final Logger LOG = LoggerFactory.getLogger(NodeNameChooserValues.class);

    private static final List<String> VALUES = new ArrayList<String>();
    private static final List<String> LABELS = new ArrayList<String>();
    @Override
    public String getResourceBundle() {
        return null;
    }

    @Override
    public List<String> getValues() {
        return VALUES;
    }

    @Override
    public List<String> getLabels() {
        return LABELS;
    }
}

My problem is that I want the behavior to be such as when the user enters a values for the NodeNames in the first tab or field, those values are added automatically to the lists in the NodeNameChooserValues class so they can be picked up and set as a nodeNameProperty. I tried hardcoding some values in the lists and they are shown as a dropbox at runtime, however I want to insert values at run time only.

It this something supported ? Can someone please help me figure out where should I insert or call add methods to add the values to the NodeNameChooserValues ?

Thank you in advance for any help.

edit retag flag offensive close merge delete