Browse Source

单元格条件属性扩展插件示例

pull/1/head
richie 6 years ago
parent
commit
f62188f88d
  1. 5
      .gitignore
  2. 7
      README.md
  3. 25
      build.xml
  4. 0
      lib/report/.gitkeep
  5. 23
      plugin-dynamichighlight.iml
  6. 21
      plugin.xml
  7. 18
      pom.xml
  8. 0
      screenshots/e0.png
  9. 0
      screenshots/e1.png
  10. 0
      screenshots/e2.png
  11. BIN
      shop/icon_200.png
  12. BIN
      shop/icon_400.png
  13. 28
      src/com/fr/plugin/cell/highlight/fun/MyCellFunctionProcessor.java
  14. 4
      src/com/fr/plugin/cell/highlight/locale/align.properties
  15. 4
      src/com/fr/plugin/cell/highlight/locale/align_zh_CN.properties
  16. 11
      src/main/java/com/fr/plugin/cell/highlight/AlignCellHighlightBridge.java
  17. 2
      src/main/java/com/fr/plugin/cell/highlight/AlignHighlightLocaleBridge.java
  18. 55
      src/main/java/com/fr/plugin/cell/highlight/fun/AlignHighlightAction.java
  19. 6
      src/main/java/com/fr/plugin/cell/highlight/fun/AlignHighlightConstants.java
  20. 17
      src/main/java/com/fr/plugin/cell/highlight/ui/AlignHighlightPane.java
  21. 7
      src/main/resources/com/fr/plugin/cell/highlight/locale/align.properties
  22. 7
      src/main/resources/com/fr/plugin/cell/highlight/locale/align_zh_CN.properties

5
.gitignore vendored

@ -0,0 +1,5 @@
*.iml
.idea/
.classpath
lib/report/*.jar
.DS_Store

7
README.md

@ -1,15 +1,16 @@
# 自定义条件属性
当前已有的条件属性包含下图中的几种类型
![0](effect/e0.png)
![0](screenshots/e0.png)
在特殊情况下,已有的几种类型并不能完全满足需求,典型的就是,根据不同的条件把单元格内的内容做不同的对齐。
这个时候,就可以使用条件属性接口```com.fr.design.fun.HighlightProvider```以及其抽象类```com.fr.design.fun.impl.AbstractHighlightProvider```了。
通过这个接口可以制作出如下如所示的插件效果
![1](effect/e1.png)
![1](screenshots/e1.png)
可以看到多出了一个"我的条件属性"的项,当然这个名字是可以根据实际情况修改的。
选择了以后,就可以设置单元格的对齐方式了
![2](effect/e2.png)
![2](screenshots/e2.png)

25
build.xml

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="plugin">
<!-- JDK路径,根据自己机器上实际位置修改-->
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home"/>
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home"/>
<property name="libs" value="${basedir}/lib"/>
<property name="publicLibs" value=""/>
<property name="reportLibs" value="${basedir}/../webroot/WEB-INF/lib"/>
<property name="destLoc" value="."/>
<property name="classes" value="classes"/>
<xmlproperty file="${basedir}/plugin.xml"/>
@ -13,7 +14,7 @@
<!-- 插件版本-->
<property name="plugin-version" value="${current-version}"/>
<!-- 插件名字-->
<property name="plugin-name" value="align-highlight"/>
<property name="plugin-name" value="highlight-align"/>
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/>
<target name="prepare">
@ -29,6 +30,9 @@
<fileset dir="${publicLibs}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${reportLibs}">
<include name="**/*.jar"/>
</fileset>
</path>
<patternset id="resources4Jar">
<exclude name="**/.settings/**"/>
@ -44,7 +48,7 @@
<echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/>
<delete dir="tmp"/>
<copy todir="tmp">
<fileset dir="${resources_from}\src">
<fileset dir="${resources_from}/src/main/resources">
<patternset refid="resources4Jar"/>
</fileset>
</copy>
@ -59,11 +63,15 @@
target="${target_jdk_version}"
fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}"
executable="${compile_jdk_version}/bin/javac">
<src path="${basedir}/src"/>
<src path="${basedir}/src/main/java"/>
<exclude name="**/.svn/**"/>
<compilerarg line="-encoding UTF8 "/>
<classpath refid="compile.classpath"/>
</javac>
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask">
<classpath refid="compile.classpath"/>
</taskdef>
<pretreatment baseDir="${basedir}"/>
</target>
<target name="jar_classes">
@ -93,6 +101,7 @@
<delete dir="${classes}"/>
</target>
<target name="jar" depends="super_jar">
<antcall target="zip"/>
</target>
@ -106,12 +115,16 @@
<include name="${plugin-jar}"/>
<include name="plugin.xml"/>
</fileset>
<fileset dir="${libs}">
<include name="*.jar"/>
<include name="*.dll"/>
</fileset>
</copy>
<zip destfile="${basedir}/${plugin-folder}.zip" basedir=".">
<include name="${plugin-folder}/*.jar"/>
<include name="${plugin-folder}/*.dll"/>
<include name="${plugin-folder}/plugin.xml"/>
</zip>
<xmlproperty file="${basedir}/plugin.xml"/>
<move file="${plugin-folder}.zip" todir="${destLoc}/${plugin.name}"/>
<move file="${plugin-folder}.zip" todir="${destLoc}/install"/>
</target>
</project>

0
lib/report/.gitkeep

23
plugin-dynamichighlight.iml

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../../../env/8.0/WebReport/WEB-INF/classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="jdk1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="module" module-name="base" />
<orderEntry type="module" module-name="base-basic" />
<orderEntry type="module" module-name="base-calculate" />
<orderEntry type="module" module-name="base-data" />
<orderEntry type="module" module-name="base-file" />
<orderEntry type="module" module-name="base-performance" />
<orderEntry type="module" module-name="base-stable" />
<orderEntry type="module" module-name="chart-base" />
<orderEntry type="module" module-name="designer" />
<orderEntry type="module" module-name="engine" />
<orderEntry type="module" module-name="designer_base" />
</component>
</module>

21
plugin.xml

@ -1,23 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.cell.highlight.align</id>
<id>com.fr.plugin.cell.highlight.align.v10</id>
<main-package>com.fr.plugin.cell.highlight</main-package>
<name><![CDATA[单元格对齐条件属性]]></name>
<active>yes</active>
<version>2.1</version>
<env-version>8.0</env-version>
<jartime>2016-03-20</jartime>
<price>1000</price>
<vendor email="solution@finereport.com">solution.richie</vendor>
<env-version>10.0</env-version>
<jartime>2018-09-20</jartime>
<vendor>author</vendor>
<description><![CDATA[可以设置单元格为左对齐,右对齐以及居中对齐]]></description>
<change-notes><![CDATA[
<p>[2016-01-20]增加了插件功能说明</p>
<p>[2016-03-21]增加了国际化支持(美国英语)</p>
<p>[2016-01-20]增加了插件功能说明<br/>
<p>[2016-03-21]增加了国际化支持(美国英语)<br/>
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fr.plugin.cell.highlight.MyCellHighlightLocaleFinder"/>
<LocaleFinder class="com.fr.plugin.cell.highlight.AlignHighlightLocaleBridge"/>
</extra-core>
<extra-report>
</extra-report>
<extra-designer>
<HighlightProvider class="com.fr.plugin.cell.highlight.MyCellHighlight"/>
<HighlightProvider class="com.fr.plugin.cell.highlight.AlignCellHighlightBridge"/>
</extra-designer>
<function-recorder class="com.fr.plugin.cell.highlight.fun.AlignHighlightAction"/>
</plugin>

18
pom.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.plugin</groupId>
<artifactId>starter</artifactId>
<version>10.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>demo-highlight-align</artifactId>
<build>
<!---如果要更改调试插件,改这里的配置就可以了-->
<outputDirectory>${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.cell.highlight.align.v10-1.0/classes</outputDirectory>
</build>
</project>

0
effect/e0.png → screenshots/e0.png

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

0
effect/e1.png → screenshots/e1.png

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB

0
effect/e2.png → screenshots/e2.png

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

BIN
shop/icon_200.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

BIN
shop/icon_400.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

28
src/com/fr/plugin/cell/highlight/fun/MyCellFunctionProcessor.java

@ -1,28 +0,0 @@
package com.fr.plugin.cell.highlight.fun;
import com.fr.plugin.cell.highlight.MyConstants;
import com.fr.stable.fun.FunctionHelper;
import com.fr.stable.fun.FunctionProcessor;
import com.fr.stable.fun.impl.AbstractFunctionProcessor;
/**
* Created by richie on 16/1/22.
*/
public class MyCellFunctionProcessor extends AbstractFunctionProcessor {
private static MyCellFunctionProcessor instance = new MyCellFunctionProcessor();
public static FunctionProcessor getInstance() {
return instance;
}
@Override
public int getId() {
return FunctionHelper.generateFunctionID(MyConstants.PLUGIN_ID);
}
@Override
public String getLocaleKey() {
return "Plugin-Highlight_Align";
}
}

4
src/com/fr/plugin/cell/highlight/locale/align.properties

@ -1,4 +0,0 @@
Plugin-Highlight_Align=Align
Plugin-Highlight_Align_Left=Left
Plugin-Highlight_Align_Center=Center
Plugin-Highlight_Align_Right=Right

4
src/com/fr/plugin/cell/highlight/locale/align_zh_CN.properties

@ -1,4 +0,0 @@
Plugin-Highlight_Align=\u5BF9\u9F50
Plugin-Highlight_Align_Left=\u5DE6\u5BF9\u9F50
Plugin-Highlight_Align_Center=\u5C45\u4E2D\u5BF9\u9F50
Plugin-Highlight_Align_Right=\u53F3\u5BF9\u9F50

11
src/com/fr/plugin/cell/highlight/MyCellHighlight.java → src/main/java/com/fr/plugin/cell/highlight/AlignCellHighlightBridge.java

@ -3,6 +3,9 @@ package com.fr.plugin.cell.highlight;
import com.fr.design.condition.ConditionAttrSingleConditionPane;
import com.fr.design.condition.ConditionAttributesPane;
import com.fr.design.fun.impl.AbstractHighlightProvider;
import com.fr.plugin.cell.highlight.fun.AlignHighlightAction;
import com.fr.plugin.cell.highlight.fun.AlignHighlightConstants;
import com.fr.plugin.cell.highlight.ui.AlignHighlightPane;
import com.fr.stable.fun.Authorize;
/**
@ -10,8 +13,8 @@ import com.fr.stable.fun.Authorize;
* @date 2015-03-26
* @since 8.0
*/
@Authorize(callSignKey = MyConstants.PLUGIN_ID)
public class MyCellHighlight extends AbstractHighlightProvider {
@Authorize(callSignKey = AlignHighlightConstants.PLUGIN_ID)
public class AlignCellHighlightBridge extends AbstractHighlightProvider {
@Override
public int currentAPILevel() {
@ -20,11 +23,11 @@ public class MyCellHighlight extends AbstractHighlightProvider {
@Override
public Class<?> classForHighlightAction() {
return MyHighlightAction.class;
return AlignHighlightAction.class;
}
@Override
public ConditionAttrSingleConditionPane appearanceForCondition(ConditionAttributesPane conditionAttributesPane) {
return new MyHighlightPane(conditionAttributesPane);
return new AlignHighlightPane(conditionAttributesPane);
}
}

2
src/com/fr/plugin/cell/highlight/MyCellHighlightLocaleFinder.java → src/main/java/com/fr/plugin/cell/highlight/AlignHighlightLocaleBridge.java

@ -5,7 +5,7 @@ import com.fr.stable.fun.impl.AbstractLocaleFinder;
/**
* Created by richie on 16/1/22.
*/
public class MyCellHighlightLocaleFinder extends AbstractLocaleFinder {
public class AlignHighlightLocaleBridge extends AbstractLocaleFinder {
@Override
public int currentAPILevel() {

55
src/com/fr/plugin/cell/highlight/MyHighlightAction.java → src/main/java/com/fr/plugin/cell/highlight/fun/AlignHighlightAction.java

@ -1,15 +1,14 @@
package com.fr.plugin.cell.highlight;
package com.fr.plugin.cell.highlight.fun;
import com.fr.base.Style;
import com.fr.plugin.ExtraClassManager;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.cell.highlight.fun.MyCellFunctionProcessor;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.report.cell.cellattr.highlight.AbstractStyleHighlightAction;
import com.fr.stable.AssistUtils;
import com.fr.stable.Constants;
import com.fr.stable.fun.FunctionHelper;
import com.fr.stable.fun.FunctionProcessor;
import com.fr.stable.fun.impl.AbstractFunctionProcessor;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
@ -18,27 +17,16 @@ import com.fr.stable.xml.XMLableReader;
* @date 2015-03-26
* @since 8.0
*/
public class MyHighlightAction extends AbstractStyleHighlightAction {
private static final FunctionProcessor PPP = new AbstractFunctionProcessor() {
@Override
public int getId() {
return FunctionHelper.generateFunctionID(MyConstants.PLUGIN_ID);
}
@Override
public String getLocaleKey() {
return "Plugin-Highlight_Align";
}
};
@EnableMetrics
public class AlignHighlightAction extends AbstractStyleHighlightAction {
private int align = Constants.RIGHT;
public MyHighlightAction() {
public AlignHighlightAction() {
this(Constants.RIGHT, 0);
}
public MyHighlightAction(int align, int scope) {
public AlignHighlightAction(int align, int scope) {
super(scope);
this.align = align;
}
@ -48,12 +36,9 @@ public class MyHighlightAction extends AbstractStyleHighlightAction {
}
@Override
@Focus(id = AlignHighlightConstants.PLUGIN_ID, text = "Plugin-Highlight_Align", source = Original.PLUGIN)
protected Style modStyle(Style style) {
FunctionProcessor processor= ExtraClassManager.getInstance().getFunctionProcessor();
if(processor!=null){
processor.recordFunction(PPP);
}
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(MyConstants.PLUGIN_ID);
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(AlignHighlightConstants.PLUGIN_ID);
if (pluginLicense != null && pluginLicense.isAvailable()) {
return style.deriveHorizontalAlignment(align);
}
@ -64,7 +49,7 @@ public class MyHighlightAction extends AbstractStyleHighlightAction {
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String tagName = reader.getTagName();
if (tagName.equals("MyAlign")) {
if (tagName.equals("Align")) {
align = reader.getAttrAsInt("align", Constants.RIGHT);
}
}
@ -72,13 +57,23 @@ public class MyHighlightAction extends AbstractStyleHighlightAction {
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG("MyAlign").attr("align", align);
writer.startTAG("Align").attr("align", align);
writer.end();
}
@Override
public boolean equals(Object o) {
return o instanceof AlignHighlightAction && super.equals(o) && ((AlignHighlightAction) o).align == align;
}
@Override
public int hashCode() {
return AssistUtils.hashCode(align);
}
public Object clone() throws CloneNotSupportedException {
MyHighlightAction cloned = (MyHighlightAction)super.clone();
AlignHighlightAction cloned = (AlignHighlightAction) super.clone();
cloned.align = align;
return cloned;
return cloned;
}
}

6
src/com/fr/plugin/cell/highlight/MyConstants.java → src/main/java/com/fr/plugin/cell/highlight/fun/AlignHighlightConstants.java

@ -1,10 +1,10 @@
package com.fr.plugin.cell.highlight;
package com.fr.plugin.cell.highlight.fun;
/**
* Created by richie on 16/3/30.
*/
public class MyConstants {
public class AlignHighlightConstants {
public static final String PLUGIN_ID = "com.fr.plugin.cell.highlight.align";
public static final String PLUGIN_ID = "com.fr.plugin.cell.highlight.align.v10";
}

17
src/com/fr/plugin/cell/highlight/MyHighlightPane.java → src/main/java/com/fr/plugin/cell/highlight/ui/AlignHighlightPane.java

@ -1,10 +1,11 @@
package com.fr.plugin.cell.highlight;
package com.fr.plugin.cell.highlight.ui;
import com.fr.design.condition.ConditionAttrSingleConditionPane;
import com.fr.design.condition.ConditionAttributesPane;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIDictionaryComboBox;
import com.fr.general.Inter;
import com.fr.plugin.cell.highlight.fun.AlignHighlightAction;
import com.fr.report.cell.cellattr.highlight.HighlightAction;
import com.fr.stable.Constants;
@ -15,11 +16,11 @@ import javax.swing.*;
* @date 2015-03-26
* @since 8.0
*/
public class MyHighlightPane extends ConditionAttrSingleConditionPane<HighlightAction> {
public class AlignHighlightPane extends ConditionAttrSingleConditionPane<HighlightAction> {
private UIDictionaryComboBox<Integer> alignComboBox;
private JComboBox scopeComboBox;
public MyHighlightPane(ConditionAttributesPane conditionAttributesPane) {
public AlignHighlightPane(ConditionAttributesPane conditionAttributesPane) {
super(conditionAttributesPane);
this.alignComboBox = new UIDictionaryComboBox<Integer>(
new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT},
@ -30,9 +31,9 @@ public class MyHighlightPane extends ConditionAttrSingleConditionPane<HighlightA
);
add(alignComboBox);
this.scopeComboBox = new UIComboBox(new String[]{
Inter.getLocText("Utils-Current_Cell"),
Inter.getLocText("Utils-Current_Row"),
Inter.getLocText("Utils-Current_Column")});
Inter.getLocText("Plugin-Highlight_Align_Current_Cell"),
Inter.getLocText("Plugin-Highlight_Align_Current_Row"),
Inter.getLocText("Plugin-Highlight_Align_Current_Column")});
this.add(this.scopeComboBox);
}
@ -44,14 +45,14 @@ public class MyHighlightPane extends ConditionAttrSingleConditionPane<HighlightA
@Override
public void populate(HighlightAction condition) {
MyHighlightAction action = (MyHighlightAction) condition;
AlignHighlightAction action = (AlignHighlightAction) condition;
scopeComboBox.setSelectedIndex(action.getScope());
alignComboBox.setSelectedItem(action.getAlign());
}
@Override
public HighlightAction update() {
return new MyHighlightAction(alignComboBox.getSelectedItem(), scopeComboBox.getSelectedIndex());
return new AlignHighlightAction(alignComboBox.getSelectedItem(), scopeComboBox.getSelectedIndex());
}
}

7
src/main/resources/com/fr/plugin/cell/highlight/locale/align.properties

@ -0,0 +1,7 @@
Plugin-Highlight_Align=Align
Plugin-Highlight_Align_Left=Left
Plugin-Highlight_Align_Center=Center
Plugin-Highlight_Align_Right=Right
Plugin-Highlight_Align_Current_Row=Current row
Plugin-Highlight_Align_Current_Column=Current column
Plugin-Highlight_Align_Current_Cell Current cell

7
src/main/resources/com/fr/plugin/cell/highlight/locale/align_zh_CN.properties

@ -0,0 +1,7 @@
Plugin-Highlight_Align=\u5BF9\u9F50
Plugin-Highlight_Align_Left=\u5DE6\u5BF9\u9F50
Plugin-Highlight_Align_Center=\u5C45\u4E2D\u5BF9\u9F50
Plugin-Highlight_Align_Right=\u53F3\u5BF9\u9F50
Plugin-Highlight_Align_Current_Row=\u5F53\u524D\u884C
Plugin-Highlight_Align_Current_Column=\u5F53\u524D\u5217
Plugin-Highlight_Align_Current_Cell=\u5F53\u524D\u683C\u5B50
Loading…
Cancel
Save