Browse Source

Merging in latest from upstream (TC/finekit:refs/heads/master)

* commit 'ef1ab0edaa99e0e3a87be2dfe5051523dbcfec0c':
  脚本公式API
  脚本公式API
  更多的API
  更多的API
  组件兼容
  兼容问题
  公式界面
  update:一些说明的修改。
  feat: 一些ui组件的finekit化。
  feat:新增UIDescriptionTextArea组件说明。
master
Mars.Ma 5 years ago
parent
commit
933e6c054c
  1. 19
      src/main/java/com/fanruan/api/cal/CalculatorKit.java
  2. 14
      src/main/java/com/fanruan/api/cal/FormulaKit.java
  3. 2
      src/main/java/com/fanruan/api/conf/BaseConfiguration.java
  4. 41
      src/main/java/com/fanruan/api/conf/ConfigurationKit.java
  5. 11
      src/main/java/com/fanruan/api/conf/Runner.java
  6. 26
      src/main/java/com/fanruan/api/conf/xml/XmlHolderKit.java
  7. 15
      src/main/java/com/fanruan/api/data/ConnectionKit.java
  8. 4
      src/main/java/com/fanruan/api/data/connection/NameDatabaseConnection.java
  9. 24
      src/main/java/com/fanruan/api/design/macro/UIConstants.java
  10. 3
      src/main/java/com/fanruan/api/design/ui/component/UIDescriptionTextArea.java
  11. 4
      src/main/java/com/fanruan/api/design/ui/component/UIPlaceholderTextField.java
  12. 24
      src/main/java/com/fanruan/api/design/ui/component/UIRoundedBorder.java
  13. 72
      src/main/java/com/fanruan/api/design/ui/component/UITitledBorder.java
  14. 6
      src/main/java/com/fanruan/api/design/ui/component/UIToolbar.java
  15. 2
      src/main/java/com/fanruan/api/design/ui/container/BasicBeanPane.java
  16. 24
      src/main/java/com/fanruan/api/design/ui/container/BasicDialog.java
  17. 93
      src/main/java/com/fanruan/api/design/ui/container/BasicPane.java
  18. 6
      src/main/java/com/fanruan/api/design/ui/container/DialogActionAdapter.java
  19. 36
      src/main/java/com/fanruan/api/design/ui/toolbar/ToolBarDef.java
  20. 36
      src/main/java/com/fanruan/api/design/util/GUICoreKit.java
  21. 12
      src/main/java/com/fanruan/api/design/work/AbstractTableDataPane.java
  22. 246
      src/main/java/com/fanruan/api/design/work/DatabaseConnectionPane.java
  23. 27
      src/main/java/com/fanruan/api/design/work/formula/FormulaUIKit.java
  24. 13
      src/main/java/com/fanruan/api/err/UtilEvalError.java
  25. 14
      src/main/java/com/fanruan/api/macro/EncodeConstants.java
  26. 4
      src/main/java/com/fanruan/api/net/CloudKit.java
  27. 16
      src/main/java/com/fanruan/api/util/IOKit.java
  28. 30
      src/main/java/com/fanruan/api/xml/XmlKit.java
  29. 15
      src/test/java/com/fanruan/api/cal/FormulaKitTest.java
  30. 3
      src/test/java/com/fanruan/api/net/http/HttpKitTest.java

19
src/main/java/com/fanruan/api/cal/CalculatorKit.java

@ -5,24 +5,25 @@ import com.fanruan.api.session.SessionKit;
import com.fr.base.ParameterMapNameSpace; import com.fr.base.ParameterMapNameSpace;
import com.fr.base.TableDataNameSpace; import com.fr.base.TableDataNameSpace;
import com.fr.data.TableDataSource; import com.fr.data.TableDataSource;
import com.fr.report.core.namespace.SimpleCellValueNameSpace;
import com.fr.report.report.Report; import com.fr.report.report.Report;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.script.CalculatorProvider; import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.script.NameSpace; import com.fr.stable.script.NameSpace;
import com.fr.stable.web.SessionProvider; import com.fr.stable.web.SessionProvider;
import org.jetbrains.annotations.Nullable;
import com.fr.web.core.ReportSessionIDInfor; import com.fr.web.core.ReportSessionIDInfor;
import com.fr.web.core.TemplateSessionIDInfo; import com.fr.web.core.TemplateSessionIDInfo;
import com.fr.web.session.SessionIDInfo; import com.fr.web.session.SessionIDInfo;
import org.jetbrains.annotations.Nullable;
import java.util.Map; import java.util.Map;
/** /**
* @author zack * @author zack
* @date 2019/8/23
* @version 10.0 * @version 10.0
* 帆软算子工具类主要用于公式计算 * 帆软算子工具类主要用于公式计算
* @date 2019/8/23
*/ */
public class CalculatorKit { public class CalculatorKit {
/** /**
@ -79,9 +80,19 @@ public class CalculatorKit {
/** /**
* 返回服务器数据集的算子空间可以通过调用calculator.pushNameSpace()将算子空间塞进算子实例从而支持服务器数据集相关的函数计算 * 返回服务器数据集的算子空间可以通过调用calculator.pushNameSpace()将算子空间塞进算子实例从而支持服务器数据集相关的函数计算
* @return 算子空间对象 *
* @return 服务器数据集名字空间
*/ */
public static NameSpace getServerTableDataNameSpace(){ public static NameSpace getServerTableDataNameSpace() {
return TableDataNameSpace.getInstance(); return TableDataNameSpace.getInstance();
} }
/**
* 用于计算单元格的名字空间
*
* @return 单元格名字空间
*/
public static NameSpace createSimpleCellValueNameSpace() {
return SimpleCellValueNameSpace.getInstance();
}
} }

14
src/main/java/com/fanruan/api/cal/FormulaKit.java

@ -1,7 +1,9 @@
package com.fanruan.api.cal; package com.fanruan.api.cal;
import com.fanruan.api.err.KitError; import com.fanruan.api.err.KitError;
import com.fanruan.api.util.GeneralKit;
import com.fr.base.BaseFormula; import com.fr.base.BaseFormula;
import com.fr.base.ScriptFormula;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.FormulaProvider; import com.fr.stable.FormulaProvider;
@ -54,10 +56,20 @@ public class FormulaKit {
* @param content 公式的内容 * @param content 公式的内容
* @return 公式对象 * @return 公式对象
*/ */
public static @NotNull FormulaProvider newFormula(Object content) { public static @NotNull BaseFormula newFormula(Object content) {
return BaseFormula.createFormulaBuilder().build(content); return BaseFormula.createFormulaBuilder().build(content);
} }
/**
* 生成脚本公式对象
*
* @param content 公式的内容是一段javascript脚本
* @return 脚本公式
*/
public @NotNull static BaseFormula newScriptFormula(Object content) {
return new ScriptFormula(GeneralKit.objectToString(content));
}
/** /**
* 检查公式内容合法性 * 检查公式内容合法性
* *

2
src/main/java/com/fanruan/api/conf/BaseConfiguration.java

@ -30,7 +30,7 @@ public abstract class BaseConfiguration extends DefaultConfiguration {
* @param <T> 类型 * @param <T> 类型
* @return 配置对象 * @return 配置对象
*/ */
static <T extends BaseConfiguration> T getConfigInstance(final Class<T> clazz) { public static <T extends BaseConfiguration> T getConfigInstance(final Class<T> clazz) {
return ConfigContext.getConfigInstance(clazz); return ConfigContext.getConfigInstance(clazz);
} }
} }

41
src/main/java/com/fanruan/api/conf/ConfigurationKit.java

@ -0,0 +1,41 @@
package com.fanruan.api.conf;
import com.fr.config.Configuration;
import com.fr.config.holder.ConfigChangeListener;
import com.fr.transaction.Configurations;
import com.fr.transaction.ValidateProxy;
import com.fr.transaction.WorkerFacade;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 配置监听管理器
*/
public class ConfigurationKit {
/**
* 注册监听配置变化的监听器
*
* @param listener 监听器
*/
public static void registerListener(ConfigChangeListener listener) {
ValidateProxy.getInstance().getValidateManager().registerListener(listener);
}
/**
* 保存配置
*
* @param type 配置的类型
* @param action 保存动作
*/
public static void modify(Class<? extends Configuration> type, Runner action) {
Configurations.modify(new WorkerFacade(type) {
@Override
public void run() {
action.run();
}
});
}
}

11
src/main/java/com/fanruan/api/conf/Runner.java

@ -0,0 +1,11 @@
package com.fanruan.api.conf;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
*/
public interface Runner {
void run();
}

26
src/main/java/com/fanruan/api/conf/xml/XmlHolderKit.java

@ -0,0 +1,26 @@
package com.fanruan.api.conf.xml;
import com.fr.config.holder.Conf;
import com.fr.config.holder.impl.xml.XmlConf;
import com.fr.stable.xml.XMLable;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 将xml文件写入fine_conf_entity的帮助类不建议使用
*/
public class XmlHolderKit {
/**
* 创建一个要写入配置的xml多项
* @param t 配置对象
* @param clazz 类型
* @param xmlTag xml标签
* @param <T> 类型
* @return 配置对象
*/
public static <T extends XMLable> Conf<T> obj(T t, Class<T> clazz, String xmlTag) {
return new XmlConf(t, clazz, xmlTag);
}
}

15
src/main/java/com/fanruan/api/data/ConnectionKit.java

@ -2,6 +2,7 @@ package com.fanruan.api.data;
import com.fanruan.api.util.TypeKit; import com.fanruan.api.util.TypeKit;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.data.impl.NameDatabaseConnection;
import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionConfig;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -17,7 +18,7 @@ public class ConnectionKit {
* @param name 名字 * @param name 名字
* @return 数据连接 * @return 数据连接
*/ */
public @Nullable Connection getConnection(@NotNull String name) { public static @Nullable Connection getConnection(@NotNull String name) {
return ConnectionConfig.getInstance().getConnection(name); return ConnectionConfig.getInstance().getConnection(name);
} }
@ -28,11 +29,21 @@ public class ConnectionKit {
* @param type 类型 * @param type 类型
* @return 数据连接 * @return 数据连接
*/ */
public <T extends Connection> @Nullable T getConnection(@NotNull String name, Class<? extends Connection> type) { public static <T extends Connection> @Nullable T getConnection(@NotNull String name, Class<? extends Connection> type) {
Connection connection = getConnection(name); Connection connection = getConnection(name);
if (TypeKit.objectInstanceOf(connection, type)) { if (TypeKit.objectInstanceOf(connection, type)) {
return (T) connection; return (T) connection;
} }
return null; return null;
} }
/**
* 生成一个使用名字来引用的数据连接对象
*
* @param name 数据连接的名字
* @return 数据连接
*/
public static Connection createNameConnection(String name) {
return new NameDatabaseConnection(name);
}
} }

4
src/main/java/com/fanruan/api/data/connection/NameDatabaseConnection.java

@ -1,4 +0,0 @@
package com.fanruan.api.data.connection;
public class NameDatabaseConnection extends com.fr.data.impl.NameDatabaseConnection{
}

24
src/main/java/com/fanruan/api/design/macro/UIConstants.java

@ -0,0 +1,24 @@
package com.fanruan.api.design.macro;
import java.awt.*;
/**
* 设计器界面使用的一些常量
*/
public interface UIConstants {
/**
* 边框线颜色
*/
Color LINE_COLOR = new Color(153, 153, 153);
/**
* 带标题的边框的颜色
*/
Color TITLED_BORDER_COLOR = new Color(0xe8e8e9);
/**
* 圆角弧度
*/
int ARC = 0;
}

3
src/main/java/com/fanruan/api/design/ui/component/UIDescriptionTextArea.java

@ -1,4 +1,7 @@
package com.fanruan.api.design.ui.component; package com.fanruan.api.design.ui.component;
/*
* 这个控件主要是用来在界面显示帮助信息的
* */
public class UIDescriptionTextArea extends com.fr.design.gui.itextarea.DescriptionTextArea{ public class UIDescriptionTextArea extends com.fr.design.gui.itextarea.DescriptionTextArea{
} }

4
src/main/java/com/fanruan/api/design/ui/component/UIPlaceholderTextField.java

@ -14,6 +14,10 @@ public class UIPlaceholderTextField extends PlaceholderTextField {
super(); super();
} }
public UIPlaceholderTextField(int columns) {
super(columns);
}
public UIPlaceholderTextField(String placeHolder) { public UIPlaceholderTextField(String placeHolder) {
super(); super();
setPlaceholder(placeHolder); setPlaceholder(placeHolder);

24
src/main/java/com/fanruan/api/design/ui/component/UIRoundedBorder.java

@ -0,0 +1,24 @@
package com.fanruan.api.design.ui.component;
import java.awt.*;
/**
* 圆角形状的边框
*/
public class UIRoundedBorder extends com.fr.design.border.UIRoundedBorder {
public UIRoundedBorder(Color color) {
super(color);
}
public UIRoundedBorder(Color color, int thickness) {
super(color, thickness);
}
public UIRoundedBorder(Color color, int thickness, int roundedCorners) {
super(color, thickness, roundedCorners);
}
public UIRoundedBorder(int lineStyle, Color color, int roundedCorners) {
super(lineStyle, color, roundedCorners);
}
}

72
src/main/java/com/fanruan/api/design/ui/component/UITitledBorder.java

@ -0,0 +1,72 @@
package com.fanruan.api.design.ui.component;
import com.fanruan.api.design.macro.UIConstants;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 带标题的边框
*/
public class UITitledBorder extends TitledBorder {
private static final long serialVersionUID = 1L;
public static UITitledBorder createBorderWithTitle(String title) {
return new UITitledBorder(title);
}
public static UITitledBorder createBorderWithTitle(String title, int roundedCorner) {
return new UITitledBorder(title, roundedCorner);
}
private UITitledBorder(String title) {
super(
BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(
0,
0,
5,
0),
new UIRoundedBorder(
UIConstants.TITLED_BORDER_COLOR,
1,
10)
),
title,
TitledBorder.LEADING,
TitledBorder.TOP,
null,
new Color(1, 159, 222)
);
}
/**
* @param title title
* @param roundedCorner corner width 圆弧宽度即圆角直径
*/
private UITitledBorder(String title, int roundedCorner) {
super(
BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(
0,
0,
5,
0),
new UIRoundedBorder(
UIConstants.TITLED_BORDER_COLOR,
1,
roundedCorner)
),
title,
TitledBorder.LEADING,
TitledBorder.TOP,
null,
new Color(1, 159, 222)
);
}
}

6
src/main/java/com/fanruan/api/design/ui/component/UIToolbar.java

@ -1,9 +1,7 @@
package com.fanruan.api.design.ui.component; package com.fanruan.api.design.ui.component;
import com.fr.design.gui.itoolbar.UIToolBarUI; public class UIToolbar extends com.fr.design.gui.itoolbar.UIToolbar {
public UIToolbar() {
public class UIToolbar extends com.fr.design.gui.itoolbar.UIToolbar{
public UIToolbar(){
} }

2
src/main/java/com/fanruan/api/design/ui/container/BasicBeanPane.java

@ -1,4 +1,4 @@
package com.fanruan.api.design.ui.container; package com.fanruan.api.design.ui.container;
public abstract class BasicBeanPane extends com.fr.design.beans.BasicBeanPane{ public abstract class BasicBeanPane<T> extends com.fr.design.beans.BasicBeanPane<T> {
} }

24
src/main/java/com/fanruan/api/design/ui/container/BasicDialog.java

@ -1,36 +1,40 @@
package com.fanruan.api.design.ui.container; package com.fanruan.api.design.ui.container;
import com.fanruan.api.design.ui.container.BasicPane;
import java.awt.*; import java.awt.*;
public class BasicDialog extends com.fr.design.dialog.BasicDialog{ public class BasicDialog extends com.fr.design.dialog.BasicDialog {
public BasicDialog(Dialog parent){
public BasicDialog(Dialog parent) {
super(parent); super(parent);
} }
public BasicDialog(Dialog parent, BasicPane pane){ public BasicDialog(Dialog parent, BasicPane pane) {
super(parent, pane); super(parent, pane);
} }
public BasicDialog(Dialog parent, BasicPane pane, boolean isNeedButton){ public BasicDialog(Dialog parent, BasicPane pane, boolean isNeedButton) {
super(parent, pane, isNeedButton); super(parent, pane, isNeedButton);
} }
public BasicDialog(Frame parent){ public BasicDialog(Frame parent) {
super(parent); super(parent);
} }
public BasicDialog(Frame parent, BasicPane pane){ public BasicDialog(Frame parent, BasicPane pane) {
super(parent, pane); super(parent, pane);
} }
public BasicDialog(Frame parent, BasicPane pane, boolean isNedButtonPane){ public BasicDialog(Frame parent, BasicPane pane, boolean isNedButtonPane) {
super(parent, pane, isNedButtonPane); super(parent, pane, isNedButtonPane);
} }
@Override @Override
public void checkValid(){ protected void setBasicDialogSize(Dimension dimension) {
super.setBasicDialogSize(dimension);
}
@Override
public void checkValid() throws Exception {
} }
} }

93
src/main/java/com/fanruan/api/design/ui/container/BasicPane.java

@ -1,5 +1,98 @@
package com.fanruan.api.design.ui.container; package com.fanruan.api.design.ui.container;
import com.fanruan.api.design.util.GUICoreKit;
import com.fr.design.dialog.DialogActionListener;
import com.fr.design.dialog.UIDialog;
import java.awt.*;
public abstract class BasicPane extends com.fr.design.dialog.BasicPane { public abstract class BasicPane extends com.fr.design.dialog.BasicPane {
/**
* 显示窗口
*
* @param window 窗口
* @return 对话框
*/
public BasicDialog showWindow(Window window) {
return this.showWindow(window, null);
}
/**
* 显示窗口
*
* @param window 窗口
* @param l 对话框监听器
* @return 对话框
*/
public BasicDialog showWindow(Window window, DialogActionListener l) {
return showWindowWithCustomSize(window, l, BasicDialog.DEFAULT);
}
public BasicDialog showWindowWithCustomSize(Window window, DialogActionListener l, Dimension dimension) {
BasicDialog dg;
if (window instanceof Frame) {
dg = new DIALOG((Frame) window);
} else {
dg = new DIALOG((Dialog) window);
}
if (l != null) {
dg.addDialogActionListener(l);
}
dg.setBasicDialogSize(dimension);
GUICoreKit.centerWindow(dg);
dg.setResizable(false);
return dg;
}
private class DIALOG extends BasicDialog {
public DIALOG(Frame parent) {
super(parent, BasicPane.this);
this.setTitle(BasicPane.this.title4PopupWindow());
}
public DIALOG(Dialog parent) {
super(parent, BasicPane.this);
this.setTitle(BasicPane.this.title4PopupWindow());
}
public DIALOG(Frame parent, boolean isNeedButtonPane) {
super(parent, BasicPane.this, isNeedButtonPane);
this.setTitle(BasicPane.this.title4PopupWindow());
}
public DIALOG(Dialog parent, boolean isNeedButtonPane) {
super(parent, BasicPane.this, isNeedButtonPane);
this.setTitle(BasicPane.this.title4PopupWindow());
}
public void checkValid() throws Exception {
BasicPane.this.checkValid();
}
}
private class UnsizedDialog extends UIDialog {
public UnsizedDialog(Frame parent) {
super(parent, BasicPane.this);
this.setTitle(BasicPane.this.title4PopupWindow());
}
public UnsizedDialog(Dialog parent) {
super(parent, BasicPane.this);
this.setTitle(BasicPane.this.title4PopupWindow());
}
public void checkValid() throws Exception {
BasicPane.this.checkValid();
}
}
} }

6
src/main/java/com/fanruan/api/design/ui/container/DialogActionAdapter.java

@ -1,8 +1,8 @@
package com.fanruan.api.design.ui.container; package com.fanruan.api.design.ui.container;
import com.fr.design.layout.FRGUIPaneFactory;
public class DialogActionAdapter extends com.fr.design.dialog.DialogActionAdapter{ public class DialogActionAdapter extends com.fr.design.dialog.DialogActionAdapter {
public DialogActionAdapter(){
public DialogActionAdapter() {
} }
} }

36
src/main/java/com/fanruan/api/design/ui/toolbar/ToolBarDef.java

@ -0,0 +1,36 @@
package com.fanruan.api.design.ui.toolbar;
import com.fanruan.api.design.ui.component.UIToolbar;
import com.fr.design.gui.itoolbar.UIToolBarUI;
import javax.swing.*;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
*/
public class ToolBarDef extends com.fr.design.menu.ToolBarDef {
public static UIToolbar createJToolBar(final Color background) {
UIToolbar toolbar = new UIToolbar(FlowLayout.LEFT);
toolbar.setUI(new UIToolBarUI() {
@Override
public void paint(Graphics g, JComponent c) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(background);
g2.fillRect(0, 0, c.getWidth(), c.getHeight());
}
});
toolbar.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
return toolbar;
}
public static UIToolbar createJToolBar() {
UIToolbar toolbar = new UIToolbar(FlowLayout.LEFT);
toolbar.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
return toolbar;
}
}

36
src/main/java/com/fanruan/api/design/util/GUICoreKit.java

@ -1,5 +1,6 @@
package com.fanruan.api.design.util; package com.fanruan.api.design.util;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*; import javax.swing.*;
@ -99,4 +100,39 @@ public class GUICoreKit {
public static void showPopupMenu(JPopupMenu menu, Component component, int x, int y) { public static void showPopupMenu(JPopupMenu menu, Component component, int x, int y) {
GUICoreUtils.showPopupMenu(menu, component, x, y); GUICoreUtils.showPopupMenu(menu, component, x, y);
} }
/**
* 创建一个带有左空边框的面板
*
* @return 返回一个JPanel对象
*/
public static JPanel createNormalFlowInnerContainerPane() {
return FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane();
}
/**
* 创建一个带有边框面板
*
* @return 返回一个JPanel对象
*/
public static JPanel createBorderLayoutPane() {
return FRGUIPaneFactory.createBorderLayout_S_Pane();
}
/**
* 设置一个窗口居中
*/
public static void centerWindow(Window win) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension winSize = win.getSize();
if (winSize.height > screenSize.height) {
winSize.height = screenSize.height;
}
if (winSize.width > screenSize.width) {
winSize.width = screenSize.width;
}
win.setLocation((screenSize.width - winSize.width) / 2, (screenSize.height - winSize.height) / 2 - 20);
}
} }

12
src/main/java/com/fanruan/api/design/work/AbstractTableDataPane.java

@ -0,0 +1,12 @@
package com.fanruan.api.design.work;
import com.fr.base.TableData;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 数据插件继承此抽象类
*/
public abstract class AbstractTableDataPane<T extends TableData> extends com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane<T> {
}

246
src/main/java/com/fanruan/api/design/work/DatabaseConnectionPane.java

@ -1,7 +1,249 @@
package com.fanruan.api.design.work; package com.fanruan.api.design.work;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.ui.component.UIComboBox;
import com.fanruan.api.design.ui.component.UILabel;
import com.fanruan.api.design.ui.container.BasicBeanPane;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.macro.EncodeConstants;
import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.StringKit;
import com.fr.data.impl.Connection;
import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.impl.JNDIDatabaseConnection;
import com.fr.data.operator.DataOperator;
import com.fr.design.data.datapane.connect.JDBCDefPane;
import com.fr.design.data.datapane.connect.JNDIDefPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.scrollruler.ModLineBorder;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*; import javax.swing.*;
public abstract class DatabaseConnectionPane extends com.fr.design.data.datapane.connect.DatabaseConnectionPane{ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* 数据连接面板
*
* @param <E> 数据连接类型
*/
public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connection> extends BasicBeanPane<Connection> {
private UILabel message;
private UIButton okButton;
private UIButton cancelButton;
private JDialog dialog;
private UILabel uiLabel;
private UIComboBox<String> charSetComboBox;
private String originalCharSet = null;
public DatabaseConnectionPane() {
this.initComponents();
}
protected void initComponents() {
message = new UILabel();
uiLabel = new UILabel();
okButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_OK"));
cancelButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel"));
String[] defaultEncode = new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Encode_Auto")};
charSetComboBox = new UIComboBox<>(ArrayKit.addAll(defaultEncode, EncodeConstants.ENCODING_ARRAY));
this.setLayout(new BorderLayout());
JPanel northPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
this.add(northPane, BorderLayout.NORTH);
JPanel testPane = FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane();
northPane.add(testPane, BorderLayout.NORTH);
UIButton testButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection"));
testPane.add(testButton);
testButton.addActionListener(testConnectionActionListener);
testPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 4));
northPane.add(mainPanel(), BorderLayout.CENTER);
JPanel chartSetPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(2);
northPane.add(chartSetPane);
chartSetPane.setBorder(BorderFactory.createTitledBorder(
new ModLineBorder(ModLineBorder.TOP),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Advanced")
));
chartSetPane.add(GUICoreUtils.createNamedPane(charSetComboBox, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Charset") + ":"));
}
protected abstract JPanel mainPanel();
@Override
public void populateBean(com.fr.data.impl.Connection ob) {
this.originalCharSet = ob.getOriginalCharsetName();
if (StringKit.isBlank(originalCharSet)) {
this.charSetComboBox.setSelectedItem(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Encode_Auto"));
} else {
this.charSetComboBox.setSelectedItem(ob.getOriginalCharsetName());
}
populateSubDatabaseConnectionBean((E) ob);
}
protected abstract void populateSubDatabaseConnectionBean(E ob);
@Override
public com.fr.data.impl.Connection updateBean() {
E ob = updateSubDatabaseConnectionBean();
ob.setOriginalCharsetName(this.originalCharSet);
if (this.charSetComboBox.getSelectedIndex() == 0) {
ob.setNewCharsetName(null);
ob.setOriginalCharsetName(null);
} else {
ob.setNewCharsetName(EncodeConstants.ENCODING_GBK);
ob.setOriginalCharsetName(((String) this.charSetComboBox.getSelectedItem()));
}
return ob;
}
protected abstract E updateSubDatabaseConnectionBean();
ActionListener testConnectionActionListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
final SwingWorker connectionThread = new SwingWorker() {
protected Object doInBackground() throws Exception {
try {
com.fr.data.impl.Connection database = DatabaseConnectionPane.this.updateBean();
boolean connect = DataOperator.getInstance().testConnection(database);
okButton.setEnabled(true);
message.setText(database.connectMessage(connect));
if (connect) {
uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully"));
} else {
uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon"));
message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connection_Failed"));
}
} catch (Exception exp) {
LogKit.error(exp.getMessage(), exp);
}
return null;
}
};
connectionThread.execute();
initDialogPane();
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
connectionThread.cancel(true);
}
});
dialog.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
connectionThread.cancel(true);
}
});
dialog.show();
dialog.dispose();
}
};
private void initDialogPane() {
message.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection") + "...");
message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0));
okButton.setEnabled(false);
dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(DatabaseConnectionPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection"), true);
dialog.setSize(new Dimension(268, 118));
okButton.setEnabled(false);
JPanel jp = new JPanel();
JPanel upPane = new JPanel();
JPanel downPane = new JPanel();
uiLabel = new UILabel(UIManager.getIcon("OptionPane.informationIcon"));
upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
upPane.add(uiLabel);
upPane.add(message);
downPane.setLayout(new FlowLayout(FlowLayout.CENTER, 6, 0));
downPane.add(okButton);
downPane.add(cancelButton);
jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS));
jp.add(upPane);
jp.add(downPane);
dialog.add(jp);
dialog.setResizable(false);
dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(DatabaseConnectionPane.this));
}
public static class JDBC extends com.fr.design.data.datapane.connect.DatabaseConnectionPane<JDBCDatabaseConnection> {
private static JDBCDefPane jdbcDefPane = new JDBCDefPane();
@Override
protected JPanel mainPanel() {
return jdbcDefPane;
}
@Override
protected boolean isFineBI() {
return false;
}
@Override
protected void populateSubDatabaseConnectionBean(JDBCDatabaseConnection ob) {
jdbcDefPane.populate(ob);
}
@Override
protected JDBCDatabaseConnection updateSubDatabaseConnectionBean() {
return jdbcDefPane.update();
}
@Override
protected String title4PopupWindow() {
return "JDBC";
}
}
public static class JNDI extends com.fr.design.data.datapane.connect.DatabaseConnectionPane<JNDIDatabaseConnection> {
private static JNDIDefPane jndiDefPane = new JNDIDefPane();
@Override
protected JPanel mainPanel() {
return jndiDefPane;
}
@Override
protected boolean isFineBI() {
return false;
}
@Override
protected void populateSubDatabaseConnectionBean(JNDIDatabaseConnection ob) {
jndiDefPane.populate(ob);
}
@Override
protected JNDIDatabaseConnection updateSubDatabaseConnectionBean() {
return jndiDefPane.update();
}
@Override
protected String title4PopupWindow() {
return "JNDI";
}
}
} }

27
src/main/java/com/fanruan/api/design/work/formula/FormulaUIKit.java

@ -0,0 +1,27 @@
package com.fanruan.api.design.work.formula;
import com.fr.design.formula.UIFormula;
/**
* 获取公式编辑器面板工具类
*/
public class FormulaUIKit {
/**
* 获取普通公式面板
*
* @return 公式面板
*/
public static UIFormula createFormulaPane() {
return com.fr.design.formula.FormulaFactory.createFormulaPane();
}
/**
* 获取可设置导出excel时是否保留公式的公式面板
*
* @return 公式面板
*/
public static UIFormula createFormulaPaneWhenReserveFormula() {
return com.fr.design.formula.FormulaFactory.createFormulaPaneWhenReserveFormula();
}
}

13
src/main/java/com/fanruan/api/err/UtilEvalError.java

@ -1,4 +1,15 @@
package com.fanruan.api.err; package com.fanruan.api.err;
public class UtilEvalError extends com.fr.stable.UtilEvalError{ /**
* 公式计算异常
*/
public class UtilEvalError extends com.fr.stable.UtilEvalError {
public UtilEvalError() {
}
public UtilEvalError(String message) {
super(message);
}
} }

14
src/main/java/com/fanruan/api/macro/EncodeConstants.java

@ -45,4 +45,18 @@ public interface EncodeConstants {
* cp850编码 * cp850编码
*/ */
String ENCODING_CP850 = com.fr.stable.EncodeConstants.ENCODING_CP850; String ENCODING_CP850 = com.fr.stable.EncodeConstants.ENCODING_CP850;
/**
* 所有编码的集合
*/
String[] ENCODING_ARRAY = {
ENCODING_GBK,
ENCODING_BIG5,
ENCODING_ISO_8859_1,
ENCODING_UTF_8,
ENCODING_UTF_16,
ENCODING_EUC_JP,
ENCODING_EUC_KR,
ENCODING_CP850
};
} }

4
src/main/java/com/fanruan/api/net/CloudKit.java

@ -20,7 +20,7 @@ public class CloudKit {
* @param defaultSiteUrl 默认值 * @param defaultSiteUrl 默认值
* @return 键对应的值如果没有值则返回默认值 * @return 键对应的值如果没有值则返回默认值
*/ */
public @Nullable String acquireUrlByKind(@NotNull String kind, @NotNull String defaultSiteUrl) { public static @Nullable String acquireUrlByKind(@NotNull String kind, @NotNull String defaultSiteUrl) {
return CloudCenter.getInstance().acquireUrlByKind(kind, defaultSiteUrl); return CloudCenter.getInstance().acquireUrlByKind(kind, defaultSiteUrl);
} }
@ -30,7 +30,7 @@ public class CloudKit {
* @param kind * @param kind
* @return 键对应的值如果没有值则返回空 * @return 键对应的值如果没有值则返回空
*/ */
public @Nullable String acquireUrlByKind(@NotNull String kind) { public static @Nullable String acquireUrlByKind(@NotNull String kind) {
return CloudCenter.getInstance().acquireUrlByKind(kind); return CloudCenter.getInstance().acquireUrlByKind(kind);
} }
} }

16
src/main/java/com/fanruan/api/util/IOKit.java

@ -125,6 +125,19 @@ public class IOKit {
return CommonIOUtils.inputStream2String(is, charset.toString()); return CommonIOUtils.inputStream2String(is, charset.toString());
} }
/**
* 从输入流中按指定的编码读取字符串
*
* @param is 输入流
* @param charset 读取字符串的编码方式
* @return 读取出来的字符串
* @throws UnsupportedEncodingException 编码类型不支持则抛出此异常
*/
public static String inputStream2String(InputStream is, String charset)
throws UnsupportedEncodingException {
return CommonIOUtils.inputStream2String(is, charset);
}
/** /**
* 将输入流转为byte数组 * 将输入流转为byte数组
* <p/> * <p/>
@ -214,6 +227,7 @@ public class IOKit {
/** /**
* 关闭通道 * 关闭通道
*
* @param device 通道 * @param device 通道
*/ */
public static void close(Channel device) { public static void close(Channel device) {
@ -222,6 +236,7 @@ public class IOKit {
/** /**
* 关闭输出流 * 关闭输出流
*
* @param stream 输出流 * @param stream 输出流
*/ */
public static void close(OutputStream stream) { public static void close(OutputStream stream) {
@ -230,6 +245,7 @@ public class IOKit {
/** /**
* 关闭输入流 * 关闭输入流
*
* @param stream 输入流 * @param stream 输入流
*/ */
public static void close(InputStream stream) { public static void close(InputStream stream) {

30
src/main/java/com/fanruan/api/xml/XmlKit.java

@ -1,5 +1,7 @@
package com.fanruan.api.xml; package com.fanruan.api.xml;
import com.fr.data.core.DataCoreXmlUtils;
import com.fr.data.impl.Connection;
import com.fr.general.xml.GeneralXMLTools; import com.fr.general.xml.GeneralXMLTools;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable; import com.fr.stable.xml.XMLReadable;
@ -45,5 +47,33 @@ public class XmlKit {
GeneralXMLTools.writeXMLable(writer, xml, tagName); GeneralXMLTools.writeXMLable(writer, xml, tagName);
} }
/**
* 读取connection对象
*
* @param reader XMLableReader对象
* @return Connection对象
*/
public static Connection readXMLConnectionMap(XMLableReader reader) {
return DataCoreXmlUtils.readXMLConnectionMap(reader);
}
/**
* 从xml中读取数据连接对象
* @param reader xml读取器
* @return 数据连接对象
*/
public static Connection readXMLConnection(XMLableReader reader) {
return DataCoreXmlUtils.readXMLConnection(reader);
}
/**
* 写connection对象
*
* @param writer XMLPrintWriter对象
* @param connection Connection对象
*/
public static void writeXMLConnection(XMLPrintWriter writer, Connection connection) {
DataCoreXmlUtils.writeXMLConnection(writer, connection);
}
} }

15
src/test/java/com/fanruan/api/cal/FormulaKitTest.java

@ -2,9 +2,11 @@ package com.fanruan.api.cal;
import com.fanruan.api.Prepare; import com.fanruan.api.Prepare;
import com.fanruan.api.err.KitError; import com.fanruan.api.err.KitError;
import com.fr.base.BaseFormula;
import com.fr.base.Formula; import com.fr.base.Formula;
import com.fr.base.ParameterMapNameSpace; import com.fr.base.ParameterMapNameSpace;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.UtilEvalError;
import com.fr.stable.script.CalculatorProvider; import com.fr.stable.script.CalculatorProvider;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -43,6 +45,19 @@ public class FormulaKitTest extends Prepare {
Assert.fail(); Assert.fail();
} }
} }
@Test
public void testScriptFormula() {
BaseFormula formula = FormulaKit.newScriptFormula("=return Math.abs(-1)");
CalculatorProvider provider = CalculatorKit.createCalculator();
try {
Object r = formula.evalValue(provider);
Assert.assertEquals(1, r);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test @Test
public void testCheckFormulaContent() { public void testCheckFormulaContent() {
assertEquals(true, FormulaKit.checkFormulaContent(new Formula(""))); assertEquals(true, FormulaKit.checkFormulaContent(new Formula("")));

3
src/test/java/com/fanruan/api/net/http/HttpKitTest.java

@ -1,6 +1,7 @@
package com.fanruan.api.net.http; package com.fanruan.api.net.http;
import com.fanruan.api.Prepare; import com.fanruan.api.Prepare;
import com.fanruan.api.macro.EncodeConstants;
import com.fanruan.api.net.http.rs.HttpRequest; import com.fanruan.api.net.http.rs.HttpRequest;
import com.fanruan.api.net.http.rs.HttpResponseType; import com.fanruan.api.net.http.rs.HttpResponseType;
import com.fanruan.api.net.http.rs.StreamResponseHandle; import com.fanruan.api.net.http.rs.StreamResponseHandle;
@ -72,6 +73,8 @@ public class HttpKitTest extends Prepare {
InputStream in = HttpKit.post("https://cloud.fanruan.com/site", map, HttpResponseType.STREAM); InputStream in = HttpKit.post("https://cloud.fanruan.com/site", map, HttpResponseType.STREAM);
String text = IOKit.inputStream2String(in, StandardCharsets.UTF_8); String text = IOKit.inputStream2String(in, StandardCharsets.UTF_8);
assertEquals("{\"value\":\"http://bbs.fanruan.com/\"}", text); assertEquals("{\"value\":\"http://bbs.fanruan.com/\"}", text);
String text2 = IOKit.inputStream2String(in, EncodeConstants.ENCODING_UTF_8);
assertEquals("{\"value\":\"http://bbs.fanruan.com/\"}", text2);
} catch (SocketTimeoutException ignore) { } catch (SocketTimeoutException ignore) {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

Loading…
Cancel
Save