|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.fr.solution.plugin.design.formula.compat; |
|
|
|
|
|
|
|
|
|
import com.fanruan.api.function.FunctionKit; |
|
|
|
|
import com.fanruan.api.log.LogKit; |
|
|
|
|
import com.fanruan.api.macro.EncodeConstants; |
|
|
|
|
import com.fanruan.api.util.GeneralKit; |
|
|
|
|
import com.fanruan.api.util.OperatingKit; |
|
|
|
@ -17,7 +18,6 @@ import com.fr.function.MIN;
|
|
|
|
|
import com.fr.function.RANGE; |
|
|
|
|
import com.fr.function.SUM; |
|
|
|
|
import com.fr.function.TIME; |
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
|
import com.fr.plugin.ExtraClassManager; |
|
|
|
|
import com.fr.stable.fun.FunctionDefContainer; |
|
|
|
|
import com.fr.stable.fun.mark.Mutable; |
|
|
|
@ -63,7 +63,8 @@ public final class FunctionConstants {
|
|
|
|
|
/** |
|
|
|
|
* Don't let anyone instantiate this class. |
|
|
|
|
*/ |
|
|
|
|
private FunctionConstants() {} |
|
|
|
|
private FunctionConstants() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void loadEmbededFunctions() { |
|
|
|
|
String pkgName = "com.fr.function"; |
|
|
|
@ -73,7 +74,7 @@ public final class FunctionConstants {
|
|
|
|
|
try { |
|
|
|
|
urlEnumeration = classloader.getResources(pkgName.replace('.', '/')); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
FRLogger.getLogger().error(e.getMessage()); |
|
|
|
|
LogKit.error(e.getMessage()); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
while (urlEnumeration.hasMoreElements()) { |
|
|
|
@ -86,9 +87,9 @@ public final class FunctionConstants {
|
|
|
|
|
try { |
|
|
|
|
classFilePath = URLDecoder.decode(classFilePath, EncodeConstants.ENCODING_UTF_8); |
|
|
|
|
} catch (UnsupportedEncodingException e1) { |
|
|
|
|
FRLogger.getLogger().error(e1.getMessage(), e1); |
|
|
|
|
LogKit.error(e1.getMessage(), e1); |
|
|
|
|
} |
|
|
|
|
FRLogger.getLogger().info("ClassFilePath:" + classFilePath); |
|
|
|
|
LogKit.info("ClassFilePath:" + classFilePath); |
|
|
|
|
if (isCustomFormulaPath(classFilePath)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -97,7 +98,7 @@ public final class FunctionConstants {
|
|
|
|
|
Class<?> cls = Class.forName(pkgName + "." + fileName.substring(0, fileName.length() - 6)); |
|
|
|
|
if (TypeKit.classInstanceOf(cls, iface)) { |
|
|
|
|
Function inst; |
|
|
|
|
inst = (Function)cls.newInstance(); |
|
|
|
|
inst = (Function) cls.newInstance(); |
|
|
|
|
for (NameAndTypeAndFunctionList EMBFUNCTION : EMBFUNCTIONS) { |
|
|
|
|
if (EMBFUNCTION.test(inst)) { |
|
|
|
|
break; |
|
|
|
@ -107,7 +108,7 @@ public final class FunctionConstants {
|
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
} catch (Throwable e) { |
|
|
|
|
// 不要因为个别公式加载失败,而导致整个函数面板无法启动
|
|
|
|
|
FRLogger.getLogger().error(e.getMessage()); |
|
|
|
|
LogKit.error(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -127,24 +128,26 @@ public final class FunctionConstants {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 将函数分组插件中的函数添加到对应的列表中 |
|
|
|
|
* |
|
|
|
|
* @param listModel |
|
|
|
|
*/ |
|
|
|
|
public static void addFunctionGroupFromPlugins(DefaultListModel listModel){ |
|
|
|
|
public static void addFunctionGroupFromPlugins(DefaultListModel listModel) { |
|
|
|
|
//hugh:自定义函数分组
|
|
|
|
|
Set<Mutable> containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING); |
|
|
|
|
if(!containers.isEmpty()){ |
|
|
|
|
for(Mutable container : containers){ |
|
|
|
|
listModel.addElement(createFunctionGroup((FunctionDefContainer)container)); |
|
|
|
|
if (!containers.isEmpty()) { |
|
|
|
|
for (Mutable container : containers) { |
|
|
|
|
listModel.addElement(createFunctionGroup((FunctionDefContainer) container)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建一个新的分组 |
|
|
|
|
* |
|
|
|
|
* @param container |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private static FunctionGroup createFunctionGroup(final FunctionDefContainer container){ |
|
|
|
|
private static FunctionGroup createFunctionGroup(final FunctionDefContainer container) { |
|
|
|
|
return new FunctionGroup() { |
|
|
|
|
@Override |
|
|
|
|
public String getGroupName() { |
|
|
|
@ -156,7 +159,7 @@ public final class FunctionConstants {
|
|
|
|
|
FunctionDef[] fs = container.getFunctionDefs(); |
|
|
|
|
int count = fs.length; |
|
|
|
|
FunctionDefNAD[] nads = new FunctionDefNAD[count]; |
|
|
|
|
for (int i = 0; i < count; i ++) { |
|
|
|
|
for (int i = 0; i < count; i++) { |
|
|
|
|
nads[i] = new FunctionDefNAD(fs[i]); |
|
|
|
|
} |
|
|
|
|
return nads; |
|
|
|
@ -172,10 +175,10 @@ public final class FunctionConstants {
|
|
|
|
|
String[] arr = filePath.split("!/"); |
|
|
|
|
String jarPath = arr[0].substring(6); |
|
|
|
|
String classPath = arr[1]; |
|
|
|
|
if(classPath.endsWith("/")){ |
|
|
|
|
if (classPath.endsWith("/")) { |
|
|
|
|
classPath = classPath.substring(0, classPath.length() - 1); |
|
|
|
|
} |
|
|
|
|
if (!OperatingKit.isWindows()){ |
|
|
|
|
if (!OperatingKit.isWindows()) { |
|
|
|
|
//windows里substring后是d:\123\456, mac下substring后是Application/123/456
|
|
|
|
|
jarPath = StringKit.perfectStart(jarPath, "/"); |
|
|
|
|
} |
|
|
|
@ -198,7 +201,7 @@ public final class FunctionConstants {
|
|
|
|
|
classNameList.add(entryName.substring(classPath.length() + 1)); |
|
|
|
|
} |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
FRLogger.getLogger().error(e.getMessage(), e); |
|
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
File dir = new File(filePath); |
|
|
|
@ -228,7 +231,7 @@ public final class FunctionConstants {
|
|
|
|
|
FunctionDef[] fs = ExtraClassManager.getInstance().getFunctionDef(); |
|
|
|
|
int count = fs.length; |
|
|
|
|
FunctionDefNAD[] nads = new FunctionDefNAD[count]; |
|
|
|
|
for (int i = 0; i < count; i ++) { |
|
|
|
|
for (int i = 0; i < count; i++) { |
|
|
|
|
nads[i] = new FunctionDefNAD(fs[i]); |
|
|
|
|
} |
|
|
|
|
return nads; |
|
|
|
@ -251,13 +254,13 @@ public final class FunctionConstants {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static NameAndFunctionList getCommonFunctionList() { |
|
|
|
|
return new NameAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Most_Recently_Used"), new Function[] { |
|
|
|
|
return new NameAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Most_Recently_Used"), new Function[]{ |
|
|
|
|
new SUM(), new COUNT(), new AVERAGE(), new CHAR(), new DATE(), new MAX(), new MIN(), new TIME(), new RANGE() |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static NameAndTypeAndFunctionList[] getEmbededFunctionListArray() { |
|
|
|
|
return new NameAndTypeAndFunctionList[] { |
|
|
|
|
return new NameAndTypeAndFunctionList[]{ |
|
|
|
|
new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Math_&_Trig"), Function.MATH), |
|
|
|
|
new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Text"), Function.TEXT), |
|
|
|
|
new NameAndTypeAndFunctionList(DesignToolkit.getLocText("Plugin-Design_Basic_FormulaD_Date_&_Time"), Function.DATETIME), |
|
|
|
@ -286,9 +289,9 @@ public final class FunctionConstants {
|
|
|
|
|
Collections.addAll(all, CUSTOM.getDescriptions()); |
|
|
|
|
//hugh:自定义函数分组
|
|
|
|
|
Set<Mutable> containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING); |
|
|
|
|
if(!containers.isEmpty()){ |
|
|
|
|
for(Mutable container : containers){ |
|
|
|
|
Collections.addAll(all,createFunctionGroup(((FunctionDefContainer)container)).getDescriptions()); |
|
|
|
|
if (!containers.isEmpty()) { |
|
|
|
|
for (Mutable container : containers) { |
|
|
|
|
Collections.addAll(all, createFunctionGroup(((FunctionDefContainer) container)).getDescriptions()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|