datacleaner / DataCleaner

The premier open source Data Quality solution
GNU Lesser General Public License v3.0
595 stars 180 forks source link

Creating configuration widget with dropdown selectors #1873

Open ghost opened 3 years ago

ghost commented 3 years ago

I am currently working on a custom writer in data cleaner. The configuration widget of the writer should offer the user to select a from a list of predefined fields (corresponding to roles in the output file) in a dropdown menu. I already checked the existing analyzers and while there are some with dropdown options in the configuration menu (such as the "insert into table"), I cannot get it working. I always get editable text fields instead of comboboxes. I even resorted to copying the whole "insert into table" writer into a test writer but I still get the text widgets

What kind of magic is deciding how the options are displayed? Is there any comprehensive documentation how to write the config widgets?

What I want: grafik

What I get grafik

kaspersorensen commented 3 years ago

The best we have is rather comprehensive Javadoc in the DataCleaner-api and DataCleaner-desktop-api modules.

And then some good examples:

From InsertIntoTableAnalyzer (removed a few lines that are besides the point):

    @Configured(PROPERTY_NAME_VALUES)
    InputColumn<?>[] values;

    @Configured
    @MappedProperty(PROPERTY_NAME_VALUES)
    String[] columnNames;

So here you see how @MappedProperty maps the two fields. Instead of a String array you could have an array of your own enum type for example.

ghost commented 3 years ago

Thanks a lot. By using an enum I can make it work for version 1

However, I still do not understand how this works with the String array. Where does it get the available values from?

kaspersorensen commented 3 years ago

In that case the values are being populated because the String array was also decorated with the @ColumnProperty annotation. If you have a truly bespoke situation then you probably have to implement your own renderer for the property. I honestly can't remember how to do it anymore off hand, but there should be examples in the code that you can follow. Look for classes annotated with @Renderer and named something like "PropertyWidgetRenderer" or such.