As a reporting software developed by plug-in, FineReport needs to be developed by itself. The plug-in package developed by Fanruan is officially provided by Fanruan forum. You can search on Fanruan forum. This article will mainly introduce how to develop a custom control. Here is a methodology.
Step 1: Instantiate an interface that registers the control
Give four 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 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 "Custom drop-down box"; }}The second step is to rewrite 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 filtering method, you have to 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: 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~The above is all the code development~ Then write an xml and package it into a plug-in with ant.
Code explanation:
First, let’s see what this code means?
I defined a control with the control type CustomComboBoxEditor. It inherits all methods and properties of ComboBoxEditor, and I declared the tag of the newly defined control type as customcombo. What is the use of this tag? I won't talk about other uses. Just the purpose here is that JAVA itself cannot let the front-end get what control it generates~ Instead, by telling the front-end a configuration, the front-end JS engine (let's call it that's the name) ~ execute the corresponding script according to this configuration to generate the corresponding dom styles and so on ~ shortcut You understand this ~ Returning a configuration in the background is to generate the customcombo control~ Then it finds the corresponding key value FR.CustomComboBoxEditor like a map~ and then throws the configuration of the control into this method to execute. Our control is generated.
Because there is no requirement for any modification to the front-end in this example~ so no changes are made~ Let’s look at the back-end.
Our example is to modify the fuzzy matching method.
So what did the original control matching mechanism do? It's like this: Suppose I'm a boss (I can only assume it). Now I want to know the details of a paper contract, but the company has a big piece of paper contract, how can I find it? Of course, I hire a secretary (beauty is the best), and I told her what information I wanted. Then she went to find it and gave me the last contract she found.
The control ComboBox here is the boss, ComboBoxDataFilter is the secretary, that's what it means. Every secretary here must have his own set of methods to find a contract. In the past, the secretary found everything if it was a little related. The new secretary only found the contract that was matched with the information prompted by the boss. The method to find the match is Match. This code is like this. In fact, as long as the code is carefully analyzed, it can be mapped to many transactions in real life. Because the code is also designed by humans, logic can never escape the thinking of humans handling affairs.
The above is all the content of this article. I hope that the content of this article will be of some help to everyone’s study or work. I also hope to support Wulin.com more!