How to develop custom controls for FineReport ?, Finereport Control
FineReport is a plug-in-developed report software. Features with some special requirements need to be developed by yourself. The plug-in packages developed by FineReport are provided by the FineReport official team. You can go to the FineReport forum to find them, this article describes how to develop a custom control.
Step 1: instantiate an interface for registering controls
Give four pieces of information to 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 actparameterwidgetoptionprovider {@ 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 "Custom 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(); }}
To change the filtering method, you must rewrite a 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, Inherits 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);
Okay ~ The above is all code development ~ Then write an xml file and use ant to package it into a plug-in.
Code explanation:
First, let's see what this code means?
That is, I defined a control whose control type is CustomComboBoxEditor. It inherits all the methods and attributes of ComboBoxEditor, and I declare the newly defined control type as customcombo, the purpose of this mark is nothing other than the purpose. The purpose here is that JAVA itself cannot allow the front-end to generate any controls ~ Instead, you can tell the front-end a configuration. The front-end JS engine (let's call it this way )~ Execute the corresponding script according to this configuration to generate the corresponding dom style and so on ~ Cut, so you understand it ~ A configuration is returned in the background to generate the customcombo control ~ Then it finds the corresponding key value FR. CustomComboBoxEditor ~ like a map ~ Then, the control configuration is thrown into this method for execution. Then, our controls are generated.
In this example, there is no requirement for front-end modification ~ So no changes are made ~ See the background.
In this example, we want to modify the fuzzy match method.
So how did the original control matching mechanism work? It is like this: Suppose I am a boss (mom can only assume ), now I want to know the details of a paper contract, but how can I find a large contract ~ Of course I have invited a Secretary (the best girl). I told her what information I want in the contract ~ Then she finds out and gives me the final contract.
Here, the control ComboBox is the boss, and ComboBoxDataFilter is the secretary, which means that every secretary here must have a set of methods for finding a contract, in the past, the secretary was found out as long as there was something related. The new secretary was just looking for the contract matching the information prompted by the boss ~ The matching method is isMatch. This code is like this. The code development can be mapped to many transactions in real life through careful analysis ~ Because the code is also designed by people, the logic cannot escape the thinking of people to process transactions.