Resolve how to develop custom controls for FineReport

  • 2020-05-24 05:33:46
  • OfStack

As a report software of plug-in development, FineReport needs to develop some functions with special requirements by itself. The plug-in package developed by fansoft is provided by fansoft official, you can go to fansoft forum to find it. This paper will mainly introduce how to develop a custom control, here about the methodology.

Step 1: instantiate the interface of a registered control

Give 4 information about our control class, interface class, icon path, control type name


package com.hg.free.plugin.customcombo.param;
import com.fr.design.designer.creator.XComboBox;
import com.fr.design.fun.impl.AbstractParameterWidgetOptionProvider;
import com.fr.form.ui.Widget;
public class WidgetRegister extends AbstractParameterWidgetOptionProvider {
  @Override
  public Class<? extends Widget> classForWidget() {
    return CustomComboBox.class;
  }
  @Override
  public Class<?> appearanceForWidget() {
    return XComboBox.class;
  }
  @Override
  public String iconPathForWidget() {
    return "/com/fr/web/images/combobox.png";
  }
  @Override
  public String nameForWidget() {
    return " Customize the drop-down box ";
  }
} 

Step 2, override the control class


package com.hg.free.plugin.customcombo.param;
import com.fr.form.ui.ComboBox;
import com.fr.ui.DataFilter;
public class CustomComboBox extends ComboBox {
  private static final long serialVersionUID = 7169771062153345236L;
  @Override
  public String getXType() {
  return "customcombo";
 }
  @Override
  protected DataFilter createDataFilter() {
  return new CustomComboBoxDataFilter();
 }
}

Because to change the filter, you have to override 1 filter


package com.hg.free.plugin.customcombo.param;
import com.fr.form.ui.ComboBoxDataFilter;
public class CustomComboBoxDataFilter extends ComboBoxDataFilter {
  @Override
  public boolean isMatch(String txt, String filter) {
    if(null==txt && null!=filter)return false;
    if(null==txt && null==filter)return true;
    return txt.indexOf(filter)!=-1;
  }
} 

Step 3, inherit the front-end control JS


(function($){
  FR.CustomComboBoxEditor = FR.extend(FR.ComboBoxEditor, {
   _init: function () {
   FR.CustomComboBoxEditor.superclass._init.apply(this, arguments);
   }
  });
  $.shortcut("customcombo", FR.CustomComboBoxEditor);
})(jQuery);

Ok, so that's all for code development, and then write an xml and package it as a plug-in with ant.

Code explanation:

So what does this code mean?

Is my 1 defines the control types for CustomComboBoxEditor controls, he inherited the ComboBoxEditor all methods and properties, and tag statement I define new types of controls for customcombo, the tag has a purpose, other purposes only, just here, USES what is JAVA itself is cannot let the front-end fetch generated control ~ but by telling front 1 configuration, Front-end JS engine (let's call him so) - according to the configuration to execute the corresponding script to generate the corresponding dom style ~ shortcut so you understand ~ the background such as return 1 configuration is to generate a customcombo this control ~ it is like a map1 sample to find the corresponding keys FR. CustomComboBoxEditor ~ and then throw the configuration of the control into the method. We generate our control.

Since there is no requirement to modify the front-end in this example, no changes have been made. Let's look at the background.

Our example is to modify the method of fuzzy matching.

Then what happened to the original control matching mechanism, is this: suppose I am a boss (also can only assume 1 under the abominable), now I want to know about 1 paper details of the contract, but the company has a big tuo paper contract ~ how do I find? Of course is a secretary, please (beauty) best, I told her I want to contract is probably ~ and then she went to find out what information the finally found the contract is ok for me.

We control ComboBox is the boss here, ComboBoxDataFilter is secretary, is so mean, here every secretary must have your own contract 1 set method, before the secretary is as long as a little related all find out, the secretary is only looking for a new boss prompt information matching to the contract to find matching method is isMatch, this code is that, in fact as long as a careful analysis of coding can be mapped to a lot of transaction processing in real life ~ because the code above is to design, logic thinking always escape is not the person to handle the affairs.


Related articles: