Browse Source

提交demo代码

10.0
hugh 4 years ago
parent
commit
a3d49fb472
  1. 5
      README.md
  2. 124
      build.gradle
  3. 13
      encrypt.xml
  4. BIN
      lib/common-kit-10.0-20210309.jar
  5. BIN
      lib/finekit-10.0-20210309.jar
  6. 21
      plugin.xml
  7. 89
      src/main/java/com/tptj/demo/hg/extension/button/provider/AbstractExportToolBarPane.java
  8. 105
      src/main/java/com/tptj/demo/hg/extension/button/provider/Demo.java
  9. 69
      src/main/java/com/tptj/demo/hg/extension/button/provider/DemoPane.java
  10. 125
      src/main/java/com/tptj/demo/hg/extension/button/provider/SubBtnA.java
  11. 118
      src/main/java/com/tptj/demo/hg/extension/button/provider/SubBtnB.java
  12. BIN
      src/main/resources/com/tptj/demo/hg/extension/button/provider/demo.png

5
README.md

@ -1,3 +1,6 @@
# demo-extension-button-provider # demo-extension-button-provider
导出类型扩展接口demo 导出类型扩展接口demo\
demo生效后,设计器上的本身的导出按钮编辑时会新增Hell A和Hello B两个类型可选择。\
在预览模板导出时,导出下拉菜单选项会增加Hello选项和 Hello A、Hello B两个子选项\
点击会有alert弹窗

124
build.gradle

@ -0,0 +1,124 @@
apply plugin: 'java'
[compileJava,compileTestJava]*.options*.encoding = 'UTF-8'
ext {
/**
* jar的路径
* 1.jar需要打包到zip中,lib根目录下
* 2.jar仅仅是编译时需要lib下子目录下即可
*/
libPath = "$projectDir/../webroot/WEB-INF/lib"
/**
* class进行加密保护
*/
guard = false
def pluginInfo = getPluginInfo()
pluginPre = "fine-plugin"
pluginName = pluginInfo.id
pluginVersion = pluginInfo.version
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes"
}
group = 'com.fr.plugin'
version = '10.0'
sourceCompatibility = '8'
sourceSets {
main {
java.outputDir = file(outputPath)
output.resourcesDir = file(outputPath)
}
}
ant.importBuild("encrypt.xml")
//ant变量
ant.projectDir = projectDir
ant.references["compile.classpath"] = ant.path {
fileset(dir: libPath, includes: '**/*.jar')
fileset(dir: ".",includes:"**/*.jar" )
}
classes.dependsOn('clean')
task copyFiles(type: Copy,dependsOn: 'classes'){
from outputPath
into "$projectDir/classes"
}
task preJar(type:Copy,dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas'){
from "$projectDir/classes"
into "$projectDir/transform-classes"
include "**/*.*"
}
jar.dependsOn("preJar")
task makeJar(type: Jar,dependsOn: preJar){
from fileTree(dir: "$projectDir/transform-classes")
baseName pluginPre
appendix pluginName
version pluginVersion
destinationDir = file("$buildDir/libs")
doLast(){
delete file("$projectDir/classes")
delete file("$projectDir/transform-classes")
}
}
task copyFile(type: Copy,dependsOn: ["makeJar"]){
from "$buildDir/libs"
from("$projectDir/lib") {
include "*.jar"
}
from "$projectDir/plugin.xml"
into file("$buildDir/temp/plugin")
}
task zip(type:Zip,dependsOn:["copyFile"]){
from "$buildDir/temp/plugin"
destinationDir file("$buildDir/install")
baseName pluginPre
appendix pluginName
version pluginVersion
}
//build时包含哪些文件,
processResources {
// exclude everything
// *.css没效果
// exclude '**/*.css'
// except this file
// include 'xx.xml'
}
/*读取plugin.xml中的version*/
def getPluginInfo(){
def xmlFile = file("plugin.xml")
if (!xmlFile.exists()) {
return ["id":"none", "version":"1.0.0"]
}
def plugin = new XmlParser().parse(xmlFile)
def version = plugin.version[0].text()
def id = plugin.id[0].text()
return ["id":id,"version":version]
}
repositories {
mavenLocal()
maven {
url = uri('http://mvn.finedevelop.com/repository/maven-public/')
}
}
dependencies {
//使jar
implementation fileTree(dir: 'lib', include: ['**/*.jar'])
implementation fileTree(dir: libPath, include: ['**/*.jar'])
}

13
encrypt.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<target name="compile_encrypt_javas" depends="copyFiles">
<echo message="加密文件"/>
<echo message="${projectDir}"/>
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask">
<classpath refid="compile.classpath"/>
</taskdef>
<pretreatment baseDir="${projectDir}"/>
</target>
<target name="compile_plain_javas" depends="copyFiles">
</target>
</project>

BIN
lib/common-kit-10.0-20210309.jar

Binary file not shown.

BIN
lib/finekit-10.0-20210309.jar

Binary file not shown.

21
plugin.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.tptj.demo.hg.extension.button.provider.v10</id>
<name><![CDATA[ extension button provider ]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>10.0</env-version>
<vendor>tptj</vendor>
<jartime>2019-07-18</jartime>
<description><![CDATA[ ]]></description>
<change-notes><![CDATA[]]></change-notes>
<main-package>com.tptj.demo.hg.extension.button.provider</main-package>
<function-recorder class="com.tptj.demo.hg.extension.button.provider.Demo"/>
<extra-report>
<ExtensionButtonProvider class="com.tptj.demo.hg.extension.button.provider.Demo"/>
<ExtensionButtonProvider class="com.tptj.demo.hg.extension.button.provider.SubBtnA"/>
<ExtensionButtonProvider class="com.tptj.demo.hg.extension.button.provider.SubBtnB"/>
</extra-report>
<extra-designer>
<ExportToolBarProvider class="com.tptj.demo.hg.extension.button.provider.DemoPane"/>
</extra-designer>
</plugin>

89
src/main/java/com/tptj/demo/hg/extension/button/provider/AbstractExportToolBarPane.java

@ -0,0 +1,89 @@
package com.tptj.demo.hg.extension.button.provider;
import com.fr.design.fun.ExportToolBarProvider;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.general.ComparatorUtils;
import com.fr.report.fun.ExtensionButtonProvider;
import com.fr.stable.fun.impl.AbstractProvider;
import com.fr.stable.fun.mark.API;
import javax.swing.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@API(level = ExportToolBarProvider.CURRENT_LEVEL)
public abstract class AbstractExportToolBarPane extends AbstractProvider implements ExportToolBarProvider {
private static final int STRUT_LENGTH = 2;
protected List<UICheckBox> boxes = new ArrayList<UICheckBox>();
protected Set<ExtensionButtonProvider> providers = new HashSet<ExtensionButtonProvider>();
public boolean equals(Object obj) {
return obj instanceof AbstractExportToolBarPane &&
ComparatorUtils.equals(boxes, ((AbstractExportToolBarPane) obj).boxes) &&
ComparatorUtils.equals(providers, ((AbstractExportToolBarPane) obj).providers);
}
public int currentAPILevel() {
return CURRENT_LEVEL;
}
@Override
public String mark4Provider() {
return getClass().getName();
}
/**
* 根据设计器段checkbox是否被选中更新web端相应的按钮是否显示
*/
public void populate() {
updateOrPopulateRelatedValue(false);
}
/**
* 根据web端(xml)里按钮是否显示的更新设计器端checkbox的状态
*/
public void update() {
updateOrPopulateRelatedValue(true);
}
/**
* web端按钮和设计器端checkbox的相互关系
*
* @param isUpdateFromWeb 待说明
*/
private void updateOrPopulateRelatedValue(boolean isUpdateFromWeb) {
for (int i = 0; i < boxes.size(); i++) {
UICheckBox box = boxes.get(i);
for (ExtensionButtonProvider provider : providers) {
if (!ComparatorUtils.equals(box.getText(), provider.getRelatedCheckBoxTitle())) {
continue;
}
if (isUpdateFromWeb) {
provider.setSelected(box.isSelected());
continue;
}
box.setSelected(provider.isSelected());
}
}
}
/**
* 更新面板
*
* @param pane 面板
* @return JPanel 面板
*/
public JPanel updateCenterPane(JPanel pane) {
for (int i = 0; i < boxes.size(); i++) {
pane.add(boxes.get(i));
pane.add(Box.createVerticalStrut(STRUT_LENGTH));
}
return pane;
}
}

105
src/main/java/com/tptj/demo/hg/extension/button/provider/Demo.java

@ -0,0 +1,105 @@
package com.tptj.demo.hg.extension.button.provider;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.report.SundryKit;
import com.fr.form.ui.Button;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import com.fr.intelli.record.Focus;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.report.ExtraReportClassManager;
import com.fr.report.fun.ExtensionButtonProvider;
import com.fr.report.fun.impl.AbstractExtensionMenuButton;
import com.fr.stable.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-16
**/
@EnableMetrics
public class Demo extends AbstractExtensionMenuButton {
public final static String NAME = "hello";
public final static String ICON = "com/tptj/demo/hg/extension/button/provider/demo.png";
public Demo() {
super(NAME,NAME);
SundryKit.loadToolbarIcon(NAME, ICON);
}
@Override
public Class<? extends Widget> classForDirectoryButton() {
return this.getClass();
}
@Override
public String getParentDirectory() {
return null;
}
@Override
public String getType() {
return "Hello";
}
@Override
public String getRelatedCheckBoxTitle() {
return StringUtils.EMPTY;
}
private boolean selected = true;
@Override
public boolean isSelected() {
return selected;
}
@Override
public void setSelected(boolean isSelected) {
this.selected = isSelected;
}
@Override
@Focus(id = "com.tptj.demo.hg.extension.button.provider.v10",text = "extension button provider")
public Button[] createMenuItems() {
List list = new ArrayList();
Set<ExtensionButtonProvider> adapters = ExtraReportClassManager.getInstance().getArray(ExtensionButtonProvider.XML_TAG);
if (adapters != null) {
for (ExtensionButtonProvider adapter : adapters) {
if (adapter.getParentDirectory() != null && ComparatorUtils.equals(this.getType(), adapter.getParentDirectory()) && adapter.isSelected()) {
Class export = adapter.classForDirectoryButton();
;
try {
Button button = (Button) export.newInstance();
list.add(button);
} catch (InstantiationException e) {
LogKit.error(e.getMessage());
} catch (IllegalAccessException e) {
LogKit.error(e.getMessage());
}
}
}
}
return (Button[]) list.toArray(new Button[list.size()]);
}
@Override
public boolean supportMobile() {
return false;
}
@Override
public boolean equals(Object obj) {
return obj instanceof Demo &&
selected == ((Demo)obj).selected ;
}
}

69
src/main/java/com/tptj/demo/hg/extension/button/provider/DemoPane.java

@ -0,0 +1,69 @@
package com.tptj.demo.hg.extension.button.provider;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.report.ExtraReportClassManager;
import com.fr.report.fun.ExtensionButtonProvider;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Set;
public class DemoPane extends AbstractExportToolBarPane {
private String[] texts = { "Hello A","Hello B"};
private void initComps(){
if(boxes == null || boxes.isEmpty()){
boxes = new ArrayList<UICheckBox>();
for (String text : texts) {
UICheckBox box = new UICheckBox(text);
box.setSelected(true);
boxes.add(box);
}
}
Set<ExtensionButtonProvider> set = ExtraReportClassManager.getInstance().getArray(ExtensionButtonProvider.XML_TAG);
for (ExtensionButtonProvider provider : set) {
providers.add(provider);
}
}
@Override
/**
* 待说明
*/
public void populate() {
initComps();
super.populate();
}
@Override
/**
* 待说明
*/
public void update() {
initComps();
super.update();
}
/**
* 更新面板
* @param pane 面板
* @return JPanel 面板
*/
public JPanel updateCenterPane(JPanel pane) {
initComps();
return super.updateCenterPane(pane);
}
/**
* 是否相等
* @param obj 待比较对象
* @boolean 是否相等
*/
public boolean equals(Object obj){
return obj instanceof DemoPane &&
ComparatorUtils.equals(this.texts, ((DemoPane)obj).texts);
}
}

125
src/main/java/com/tptj/demo/hg/extension/button/provider/SubBtnA.java

@ -0,0 +1,125 @@
package com.tptj.demo.hg.extension.button.provider;
import com.fanruan.api.report.SundryKit;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import com.fr.js.JavaScriptImpl;
import com.fr.report.fun.impl.AbstractExtensionButton;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLableReader;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-16
**/
public class SubBtnA extends AbstractExtensionButton {
public final static String NAME = "helloA";
public final static String ICON = "com/tptj/demo/hg/extension/button/provider/demo.png";
public SubBtnA() {
super(NAME,NAME);
SundryKit.loadToolbarIcon(NAME, ICON);
}
@Override
public Class<? extends Widget> classForDirectoryButton() {
return this.getClass();
}
@Override
public String getParentDirectory() {
return "Hello";
}
private String title = "Hello A";
@Override
public String getType() {
return title;
}
@Override
public String getRelatedCheckBoxTitle() {
return title;
}
/**
* 实测导出类型是否被选中必须自己建一个变量来存储且初始值必须为true
*/
private boolean selected=true;
/**
* 实测这个接口方法初始化的时候必须返回true否则所有配置信息无法保存到模板中
* @return
*/
@Override
public boolean isSelected() {
return selected;
}
@Override
public void setSelected(boolean isSelected) {
this.selected = isSelected;
}
@Override
protected JavaScriptImpl clickAction( Repository repo ) {
return new JavaScriptImpl("alert('Hello World! A')");
}
@Override
public boolean supportMobile() {
return false;
}
public void writeXML(XMLPrintWriter writer) {
writer.startTAG("ExtraButton").attr("ButtonName", "SubBtnA");
writer.startTAG("Buttons")
.attr("SubBtnA", selected)
.end();
super.writeXML(writer);
writer.end();
}
/**
* 读取XML
*
* @param reader XML读取对象
*/
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if(nodeName.equals("ExtraButton")){
if(reader.getAttrAsString("ButtonName", "").equals("SubBtnA")){
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
SubBtnA.super.readXML(reader);
if (reader.getTagName().equals("Buttons")) {
SubBtnA.this.setSelected(reader.getAttrAsBoolean("SubBtnA", true));
}
}
});
}
}
//兼容老的
if (reader.getTagName().equals("Buttons")) {
SubBtnA.this.setSelected(reader.getAttrAsBoolean("SubBtnA" , this.isSelected()));
}
}
}
/**
* 是否相等
*
* @param obj 对象
* @return 同上
*/
public boolean equals(Object obj) {
return obj instanceof SubBtnA && this.selected == ((SubBtnA) obj).selected
&& ComparatorUtils.equals(this.title, ((SubBtnA) obj).title);
}
}

118
src/main/java/com/tptj/demo/hg/extension/button/provider/SubBtnB.java

@ -0,0 +1,118 @@
package com.tptj.demo.hg.extension.button.provider;
import com.fanruan.api.report.SundryKit;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import com.fr.js.JavaScriptImpl;
import com.fr.report.fun.impl.AbstractExtensionButton;
import com.fr.stable.web.Repository;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLableReader;
/**
* @author 秃破天际
* @version 10.0
* Created by 秃破天际 on 2021-04-16
**/
public class SubBtnB extends AbstractExtensionButton {
public final static String NAME = "helloB";
public final static String ICON = "com/tptj/demo/hg/extension/button/provider/demo.png";
public SubBtnB() {
super(NAME,NAME);
SundryKit.loadToolbarIcon(NAME, ICON);
}
@Override
public Class<? extends Widget> classForDirectoryButton() {
return this.getClass();
}
@Override
public String getParentDirectory() {
return "Hello";
}
private String title = "Hello B";
@Override
public String getType() {
return title;
}
@Override
public String getRelatedCheckBoxTitle() {
return title;
}
private boolean selected = true;
@Override
public boolean isSelected() {
return selected;
}
@Override
public void setSelected(boolean isSelected) {
this.selected = isSelected;
}
@Override
protected JavaScriptImpl clickAction(Repository repo ) {
return new JavaScriptImpl("alert('Hello World! B')");
}
@Override
public boolean supportMobile() {
return false;
}
public void writeXML(XMLPrintWriter writer) {
writer.startTAG("ExtraButton").attr("ButtonName", "SubBtnB");
writer.startTAG("Buttons")
.attr("SubBtnB", selected)
.end();
super.writeXML(writer);
writer.end();
}
/**
* 读取XML
*
* @param reader XML读取对象
*/
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if(nodeName.equals("ExtraButton")){
if(reader.getAttrAsString("ButtonName", "").equals("SubBtnB")){
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
SubBtnB.super.readXML(reader);
if (reader.getTagName().equals("Buttons")) {
SubBtnB.this.setSelected(reader.getAttrAsBoolean("SubBtnB", true));
}
}
});
}
}
//兼容老的
if (reader.getTagName().equals("Buttons")) {
SubBtnB.this.setSelected(reader.getAttrAsBoolean("SubBtnB" , this.isSelected()));
}
}
}
/**
* 是否相等
*
* @param obj 对象
* @return 同上
*/
public boolean equals(Object obj) {
return obj instanceof SubBtnB && this.selected == ((SubBtnB) obj).selected
&& ComparatorUtils.equals(this.title, ((SubBtnB) obj).title);
}
}

BIN
src/main/resources/com/tptj/demo/hg/extension/button/provider/demo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Loading…
Cancel
Save