Interface ExtensionFieldHandler


  • public interface ExtensionFieldHandler
    Extension field handler - Java API.
    Supports custom value retrieval and calculation. Enables to define custom query operators and their evaluation.
    Must be implemented as a Netbeans ServiceProvider to be found.

    Example implementation - doubling molecular weight:

     @ServiceProvider(service = ExtensionFieldHandler.class)
     public class DoubleMolWeightField implements ExtensionFieldHandler {
    
         private DFField molWeight;
    
         @Override
         public void init(DFField field, Map<String, Object> config) {
             molWeight = field.getEntity().getFields().findItemByName("Mol Weight");
         }
    
         @Override
         public Class<?> getFieldClass() {
             return Double.class;
         }
    
         @Override
         public Set<DFField> getFieldDependencies(DFField field) {
             if (molWeight == null) {
                 return Collections.emptySet();
             }
             HashSet<DFField> ret = new HashSet<>();
             ret.add(molWeight);
             return ret;
         }
    
         @Override
         public Object getValue(Comparable<?> rowId, Map<String, Object> inputRowData, DFField field) {
             if (molWeight == null) {
                 return null;
             }
             Double value = (Double) inputRowData.get(molWeight.getId());
             return value != null ? value * 2.0 : null;
         }
     }
     
    Since:
    21.16.0
    • Method Detail

      • init

        default void init​(com.im.df.api.ddl.DFField field,
                          Map<String,​Object> config)
        Passes configuration which was set in Extension field customizer.
        Parameters:
        field - Extension field which uses this handler
        config - key-value configuration
      • getFieldClass

        Class<?> getFieldClass()
        Java type of field values. Type determines column renderer, available query operators, etc.
        Returns:
        class of field values
      • getFieldDependencies

        default Set<com.im.df.api.ddl.DFField> getFieldDependencies​(com.im.df.api.ddl.DFField field)
        Set of fields this Extension field depends on. Can be empty.
        Parameters:
        field - Extension field which uses this handler
        Returns:
        set of field dependencies
      • getValues

        default Map<Comparable<?>,​Object> getValues​(List<Comparable<?>> rowIds,
                                                          Map<Comparable<?>,​Map<String,​Object>> inputData,
                                                          com.im.df.api.ddl.DFField field)
        Retrieves field values for all row ids.
        Parameters:
        rowIds - row ids
        inputData - Mapping of row ids to fields ids and values. Supplies data from dependent fields.
        field - Extension field which uses this handler
        Returns:
        mapping of row id to field value
      • customValueCache

        default boolean customValueCache()
        Does this field implement custom value cache?
        Returns:
        true if field implements custom value cache, false otherwise
      • customOperators

        default Set<com.im.df.api.dml.DFOperator> customOperators​(com.im.df.api.ddl.DFField field)
        Set of custom operators used by this field. Can be empty.
        Parameters:
        field - Extension field which uses this handler
        Returns:
        set of custom operators
      • createFieldMatcher

        default com.chemaxon.dif.query.spi.ExtensionFieldMatcher createFieldMatcher​(com.im.df.api.ddl.DFField field,
                                                                                    com.im.df.api.dml.DFOperator operator,
                                                                                    Map<String,​Object> options,
                                                                                    List<?> operands)
        Creates field matcher for in-memory operator evaluation.
        Parameters:
        field - Extension field which uses this handler
        operator - custom operator
        options - operator options
        operands - operator parameters
        Returns:
        extension field matcher
      • clearQuery

        default void clearQuery()
        Called before query execution to clear any cache or previous results.
      • findFieldIcon

        default Image findFieldIcon​(int iconKind)
        Enables to define a custom icon.
        Parameters:
        iconKind - The kind of icon requested. This should be one of the constant values ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16 or ICON_MONO_32x32.
        Returns:
        An image object representing the requested icon. May return null if no suitable icon is available.