Browse Source
* commit '5828bb4304bcf79b8e78c34eb8e6d060621d1065': (46 commits) REPORT-83849 && REPORT-89327 修改代码质量 REPORT-83849 && REPORT-89327 【问题原因】未设计远程调用接口;脱敏计算获取的部门id api接口有误,未拼接部分id与职位id 【改动思路】增加远程调用接口;修改获取部分id 的api接口 修改一下写法 REPORT-89353 && REPORT-89358 && REPORT-89237 【问题原因】 REPORT-89358:上移下移删除未触发模版保存事件 EPORT-89353:未将脱敏设置list写入到frm决策表 REPORT-89237:预览时单元格格式生效在写入html时,在SE中仅对原始值进行了脱敏;单元格形态计算在脱敏计算后 【解决思路】 EPORT-89358:操作增加触发模版保存事件 EPORT-89353:frm决策报表添加读取写入list信息 REPORT-89237:若单元格设置了格式属性,将在写入html时再进行脱敏;将脱敏计算修改到形态计算后执行 REPORT-88826 修改类实现 REPORT-88426 模板数据集和服务器数据集重名时,保存模板会错误校验--修改一下,避免重复获取 REPORT-88826 修改类名 REPORT-88426 模板数据集和服务器数据集重名时,保存模板会错误校验 REPORT-88426 模板数据集和服务器数据集重名时,保存模板会错误校验 REPORT-87542 复制模板,点击刷新按钮,触发粘贴,会提示没有权限 REPORT-88826 设计器新增不支持的数据库类型未受到限制 封装DataBaseNotSupportedException用于rpc调用 REPORT-83628 数据脱敏配置功能存在整段文本,但key被拆分为多部分组合,需要调整——设计器部分 【问题原因】国际组同学提的bug 【改动思路】按照国际组同学的要求,拆分key以方便翻译 【review建议】 REPORT-89171 设计器新增不支持的数据库类型未受到限制 【问题原因】未考虑远程设计下,获取服务器的lic信息 【改动思路】增加rpc接口,获取服务器lic是否限制数据库类型 Revert "KERNEL-12978 fix: 适配CBB改动" REPORT-80693 数据脱敏远程设计下的性能问题 漏了代码,补充下 REPORT-80693 数据脱敏远程设计下的性能问题 变量名写错了,改一下 REPORT-80693 数据脱敏远程设计下的性能问题 【问题原因】rt 【改动思路】再改一版远程下的性能问题 1. 之前的SwingWorker提前到父容器页面,只查询一次数据库,此后面板与子面板均复用 2. 增加Loading页面,避免卡UI的误会 3. 修改规则管理器DesensitizationRuleManager中的接口方法,倒逼调用者使用一次性的查询;以及相应调用接口方法适配 【review建议】 REPORT-89249 fix: 设计器启动FineAnalyzer需要注入Instrumentation REPORT-88826 设计器新增不支持的数据库类型未受到限制 【问题原因】未考虑远程设计下,获取服务器的lic信息 【改动思路】增加rpc接口,获取服务器lic是否限制数据库类型 REPORT-29522 设计器内导出按钮部分文字带有"..." 部分文字又没有 ...new-design
42 changed files with 1853 additions and 323 deletions
@ -0,0 +1,42 @@ |
|||||||
|
package com.fr.design.data.datapane.preview.desensitization.view.common; |
||||||
|
|
||||||
|
import com.fr.design.gui.ibutton.UIRadioButton; |
||||||
|
|
||||||
|
import javax.swing.AbstractCellEditor; |
||||||
|
import javax.swing.JTable; |
||||||
|
import javax.swing.table.TableCellEditor; |
||||||
|
import javax.swing.table.TableCellRenderer; |
||||||
|
import java.awt.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* 标记选中的CellEditor |
||||||
|
* |
||||||
|
* @author Yvan |
||||||
|
* @version 11.0 |
||||||
|
* Created by Yvan on 2022/12/20 |
||||||
|
*/ |
||||||
|
public class ChooseMark extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { |
||||||
|
|
||||||
|
private final UIRadioButton selectedButton; |
||||||
|
|
||||||
|
public ChooseMark() { |
||||||
|
this.selectedButton = new UIRadioButton(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||||
|
selectedButton.setSelected(isSelected); |
||||||
|
return selectedButton; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getCellEditorValue() { |
||||||
|
return selectedButton.isSelected(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||||||
|
selectedButton.setSelected(isSelected); |
||||||
|
return selectedButton; |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 1.6 KiB |
@ -0,0 +1,18 @@ |
|||||||
|
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
|
public interface ClipboardProvider { |
||||||
|
|
||||||
|
/** |
||||||
|
* 剪切到剪贴板 |
||||||
|
* |
||||||
|
* @param o 剪切对象 |
||||||
|
*/ |
||||||
|
void cut2Clipboard(Object o); |
||||||
|
|
||||||
|
/** |
||||||
|
* 复制到剪贴板 |
||||||
|
* |
||||||
|
* @param o 复制对象 |
||||||
|
*/ |
||||||
|
void copy2Clipboard(Object o); |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用来管理不同剪贴板,以及之间的数据同步 |
||||||
|
*/ |
||||||
|
public class DashboardClipboardManager { |
||||||
|
private static class Holder { |
||||||
|
private static final DashboardClipboardManager HOLDER = new DashboardClipboardManager(); |
||||||
|
} |
||||||
|
|
||||||
|
private static final List<ClipboardProvider> CLIPBOARD_LIST = new ArrayList<>(); |
||||||
|
|
||||||
|
|
||||||
|
public void registerDashboardClipboard(ClipboardProvider clipboard) { |
||||||
|
CLIPBOARD_LIST.add(clipboard); |
||||||
|
} |
||||||
|
|
||||||
|
public void removeDashboardClipboard(ClipboardProvider clipboard) { |
||||||
|
CLIPBOARD_LIST.remove(clipboard); |
||||||
|
} |
||||||
|
|
||||||
|
public static DashboardClipboardManager getInstance() { |
||||||
|
return Holder.HOLDER; |
||||||
|
} |
||||||
|
|
||||||
|
private DashboardClipboardManager() { |
||||||
|
} |
||||||
|
|
||||||
|
public void cut2Clipboard(Object o) { |
||||||
|
for (ClipboardProvider clipboard : CLIPBOARD_LIST) { |
||||||
|
//同步其他剪贴板
|
||||||
|
clipboard.cut2Clipboard(o); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void copy2Clipboard(Object o) { |
||||||
|
for (ClipboardProvider clipboard : CLIPBOARD_LIST) { |
||||||
|
//同步其他剪贴板
|
||||||
|
clipboard.copy2Clipboard(o); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormSelection; |
||||||
|
|
||||||
|
public class FormSelectionClipboard implements ClipboardProvider { |
||||||
|
private static final FormSelection FRM_CLIPBOARD = new FormSelection(); |
||||||
|
|
||||||
|
static { |
||||||
|
DashboardClipboardManager.getInstance().registerDashboardClipboard(FormSelectionClipboard.getInstance()); |
||||||
|
} |
||||||
|
|
||||||
|
private static class Holder { |
||||||
|
private static final FormSelectionClipboard HOLDER = new FormSelectionClipboard(); |
||||||
|
} |
||||||
|
|
||||||
|
public static FormSelectionClipboard getInstance() { |
||||||
|
return Holder.HOLDER; |
||||||
|
} |
||||||
|
|
||||||
|
private FormSelectionClipboard() { |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public boolean isEmpty() { |
||||||
|
return FRM_CLIPBOARD.isEmpty(); |
||||||
|
} |
||||||
|
|
||||||
|
public FormSelection getClipboard() { |
||||||
|
return FRM_CLIPBOARD; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void cut2Clipboard(Object o) { |
||||||
|
if (o instanceof FormSelection) { |
||||||
|
((FormSelection) o).cut2ClipBoard(FRM_CLIPBOARD); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void copy2Clipboard(Object o) { |
||||||
|
if (o instanceof FormSelection) { |
||||||
|
((FormSelection) o).copy2ClipBoard(FRM_CLIPBOARD); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
package com.fr.design.mainframe.cell.settingpane.desensitization; |
||||||
|
|
||||||
|
import com.fr.design.constants.UIConstants; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itableeditorpane.UITableEditAction; |
||||||
|
import com.fr.design.gui.itableeditorpane.UITableEditorPane; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.layout.VerticalFlowLayout; |
||||||
|
import com.fr.design.mainframe.cell.settingpane.AbstractCellAttrPane; |
||||||
|
import com.fr.design.mainframe.cell.settingpane.desensitization.model.CellDesensitizationTableModel; |
||||||
|
import com.fr.report.cell.desensitization.CellDesensitizationBean; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.JTable; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据脱敏规则设置面板 |
||||||
|
* |
||||||
|
* @author Leo.Qin |
||||||
|
* @version 11.0 |
||||||
|
* Created by Leo.Qin on 2022/11/15 |
||||||
|
*/ |
||||||
|
public class CellDesensitizationGroupsPane extends JPanel { |
||||||
|
private final CellDesensitizationTableModel model; |
||||||
|
|
||||||
|
// 规则编辑面板
|
||||||
|
UITableEditorPane<CellDesensitizationBean> editorPane; |
||||||
|
|
||||||
|
// 添加规则按钮面板
|
||||||
|
private JPanel addRulePane; |
||||||
|
|
||||||
|
public CellDesensitizationGroupsPane(AbstractCellAttrPane pane) { |
||||||
|
model = new CellDesensitizationTableModel(pane, this); |
||||||
|
|
||||||
|
initComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initComponent() { |
||||||
|
this.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 10, true)); |
||||||
|
|
||||||
|
addRulePane = initAddPane(model); |
||||||
|
editorPane = initEditorPane(model); |
||||||
|
|
||||||
|
this.add(addRulePane); |
||||||
|
this.add(editorPane); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化添加脱敏设置面板 |
||||||
|
* |
||||||
|
* @param model |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private JPanel initAddPane(CellDesensitizationTableModel model) { |
||||||
|
UIButton addButton = new UIButton(model.getAction()); |
||||||
|
UILabel addLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Setting")); |
||||||
|
|
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double f = TableLayout.FILL; |
||||||
|
double[] columnSize = {p, f}; |
||||||
|
double[] rowSize = {p, p}; |
||||||
|
|
||||||
|
Component[][] components = new Component[][]{ |
||||||
|
new Component[]{addLabel, addButton} |
||||||
|
}; |
||||||
|
|
||||||
|
return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 20, 0); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化脱敏设置编辑面板 |
||||||
|
* |
||||||
|
* @param model |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private UITableEditorPane<CellDesensitizationBean> initEditorPane(CellDesensitizationTableModel model) { |
||||||
|
UITableEditorPane<CellDesensitizationBean> tableEditorPane = new UITableEditorPane<CellDesensitizationBean>(model) { |
||||||
|
@Override |
||||||
|
protected void initComponent(UITableEditAction[] action) { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
|
||||||
|
JTable editTable = getTableModel().createTable(); |
||||||
|
editTable.getTableHeader().setBackground(UIConstants.DEFAULT_BG_RULER); |
||||||
|
setEditTable(editTable); |
||||||
|
|
||||||
|
initbuttonPane(action); |
||||||
|
getbuttonPane().setBackground(UIConstants.DEFAULT_BG_RULER); |
||||||
|
|
||||||
|
JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
controlPane.setBackground(Color.WHITE); |
||||||
|
controlPane.add(getbuttonPane(), BorderLayout.WEST); |
||||||
|
|
||||||
|
JPanel pane = new JPanel(new BorderLayout(4, 4)); |
||||||
|
pane.add(editTable, BorderLayout.CENTER); |
||||||
|
pane.add(controlPane, BorderLayout.NORTH); |
||||||
|
|
||||||
|
this.add(pane, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
}; |
||||||
|
return tableEditorPane; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新数据 |
||||||
|
*/ |
||||||
|
public List<CellDesensitizationBean> update() { |
||||||
|
return editorPane.update(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 填充数据 |
||||||
|
*/ |
||||||
|
public void populate(List<CellDesensitizationBean> desensitizationBeans) { |
||||||
|
if (Objects.nonNull(desensitizationBeans)) { |
||||||
|
editorPane.populate(desensitizationBeans.toArray(new CellDesensitizationBean[]{})); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,108 @@ |
|||||||
|
package com.fr.design.mainframe.cell.settingpane.desensitization.model; |
||||||
|
|
||||||
|
import com.fr.design.gui.itableeditorpane.UITableEditAction; |
||||||
|
import com.fr.design.gui.itableeditorpane.UITableModelAdapter; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.mainframe.cell.settingpane.AbstractCellAttrPane; |
||||||
|
import com.fr.report.cell.desensitization.CellDesensitizationBean; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
|
||||||
|
/** |
||||||
|
* 单元格数据脱敏model |
||||||
|
* |
||||||
|
* @author Leo.Qin |
||||||
|
* @version 11.0 |
||||||
|
* Created by Leo.Qin on 2023/1/4 |
||||||
|
*/ |
||||||
|
public class CellDesensitizationTableModel extends UITableModelAdapter<CellDesensitizationBean> { |
||||||
|
private final int ROW_HEIGHT = 60; |
||||||
|
/** |
||||||
|
* 属性面板 |
||||||
|
*/ |
||||||
|
private AbstractCellAttrPane attrPane; |
||||||
|
/** |
||||||
|
* 添加脱敏设置action |
||||||
|
*/ |
||||||
|
private AddDesensitizationAction action; |
||||||
|
|
||||||
|
public CellDesensitizationTableModel(AbstractCellAttrPane attrPane, Component parent) { |
||||||
|
super(new String[]{StringUtils.EMPTY}); |
||||||
|
this.attrPane = attrPane; |
||||||
|
this.action = new AddDesensitizationAction(); |
||||||
|
this.table.getTableHeader().setVisible(false); |
||||||
|
this.table.setRowHeight(ROW_HEIGHT); |
||||||
|
|
||||||
|
setColumnClass(new Class[]{ |
||||||
|
DesensitizationCellEditor.class |
||||||
|
}); |
||||||
|
|
||||||
|
this.setDefaultEditor(DesensitizationCellEditor.class, new DesensitizationCellEditor(parent, this)); |
||||||
|
this.setDefaultRenderer(DesensitizationCellEditor.class, new DesensitizationCellRender(parent, this)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public UITableEditAction[] createAction() { |
||||||
|
|
||||||
|
return new UITableEditAction[]{ |
||||||
|
new MoveUpAction(), |
||||||
|
new MoveDownAction(), |
||||||
|
new DeleteDesensitizationAction() |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public AddDesensitizationAction getAction() { |
||||||
|
return action; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 添加脱敏规则action |
||||||
|
*/ |
||||||
|
public class AddDesensitizationAction extends AddTableRowAction { |
||||||
|
|
||||||
|
public AddDesensitizationAction() { |
||||||
|
this.setName(StringUtils.EMPTY); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
super.actionPerformed(e); |
||||||
|
// 添加一条空白数据
|
||||||
|
addRow(CellDesensitizationBean.createEmptyBean()); |
||||||
|
table.getSelectionModel().setSelectionInterval(table.getRowCount() - 1, table.getRowCount() - 1); |
||||||
|
fireTableDataChanged(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private class DeleteDesensitizationAction extends DeleteAction { |
||||||
|
public DeleteDesensitizationAction() { |
||||||
|
super(); |
||||||
|
this.setDeleteTipText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Remove_Tip")); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getValueAt(int rowIndex, int columnIndex) { |
||||||
|
CellDesensitizationBean desensitizationBean = getList().get(rowIndex); |
||||||
|
if (desensitizationBean == null) { |
||||||
|
desensitizationBean = CellDesensitizationBean.createEmptyBean(); |
||||||
|
} |
||||||
|
return desensitizationBean; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isCellEditable(int row, int col) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void fireTableDataChanged() { |
||||||
|
super.fireTableDataChanged(); |
||||||
|
attrPane.attributeChanged(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
package com.fr.design.mainframe.cell.settingpane.desensitization.model; |
||||||
|
|
||||||
|
import com.fr.report.cell.desensitization.CellDesensitizationBean; |
||||||
|
|
||||||
|
import javax.swing.AbstractCellEditor; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.JTable; |
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import javax.swing.border.LineBorder; |
||||||
|
import javax.swing.table.TableCellEditor; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 脱敏规则设置cellEditor |
||||||
|
* @author Leo.Qin |
||||||
|
* @version 11.0 |
||||||
|
* Created by Leo.Qin on 2023/1/4 |
||||||
|
*/ |
||||||
|
public class DesensitizationCellEditor extends AbstractCellEditor implements TableCellEditor { |
||||||
|
private final DesensitizationCellPane editPane; |
||||||
|
|
||||||
|
DesensitizationCellEditor(Component parent, CellDesensitizationTableModel model) { |
||||||
|
editPane = new DesensitizationCellPane(parent, model); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
||||||
|
// 点击脱敏设置时刷新用户组信息和所有规则
|
||||||
|
SwingWorker<Map<String, Object>, Void> updateDateWorker = new UpdateDataWorker(); |
||||||
|
updateDateWorker.execute(); |
||||||
|
|
||||||
|
editPane.populate((CellDesensitizationBean) value, row); |
||||||
|
|
||||||
|
JPanel editPanel = editPane.getEditPanel(); |
||||||
|
editPanel.setBorder(new LineBorder(Color.LIGHT_GRAY)); |
||||||
|
|
||||||
|
return editPanel; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getCellEditorValue() { |
||||||
|
return editPane.getCellEditorValue(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,332 @@ |
|||||||
|
package com.fr.design.mainframe.cell.settingpane.desensitization.model; |
||||||
|
|
||||||
|
import com.fr.base.operator.org.OrganizationOperator; |
||||||
|
import com.fr.data.desensitize.rule.DesensitizationRuleManager; |
||||||
|
import com.fr.data.desensitize.rule.base.DesensitizationRule; |
||||||
|
import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; |
||||||
|
import com.fr.data.desensitize.rule.base.DesensitizationRuleStatus; |
||||||
|
import com.fr.design.beans.BasicBeanPane; |
||||||
|
import com.fr.design.data.datapane.preview.desensitization.view.rule.DesensitizationRulePane; |
||||||
|
import com.fr.design.dialog.BasicDialog; |
||||||
|
import com.fr.design.dialog.DialogActionAdapter; |
||||||
|
import com.fr.design.event.UIObserverListener; |
||||||
|
import com.fr.design.file.HistoryTemplateListCache; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.icombocheckbox.UIComboCheckBox; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.layout.VerticalFlowLayout; |
||||||
|
import com.fr.design.mainframe.JTemplate; |
||||||
|
import com.fr.design.mainframe.JTemplateActionListener; |
||||||
|
import com.fr.report.cell.desensitization.CellDesensitizationBean; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.third.org.apache.commons.collections4.map.HashedMap; |
||||||
|
import com.fr.workspace.WorkContext; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.SwingUtilities; |
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.FontMetrics; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.LinkedHashSet; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
import java.util.Optional; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.concurrent.ExecutionException; |
||||||
|
|
||||||
|
/** |
||||||
|
* 单元格脱敏规则设置面板 |
||||||
|
* |
||||||
|
* @author Leo.Qin |
||||||
|
* @version 11.0 |
||||||
|
* Created by Leo.Qin on 2023/1/5 |
||||||
|
*/ |
||||||
|
public class DesensitizationCellPane extends BasicBeanPane { |
||||||
|
private Component parent; |
||||||
|
private JPanel editPanel; |
||||||
|
private UILabel label; |
||||||
|
private UITextField emptyTextField; |
||||||
|
private UIButton ruleButton; |
||||||
|
private UITextField ruleTextField; |
||||||
|
private UIComboCheckBox rolesComboBox; |
||||||
|
private static final String APOSTROPHE = "..."; |
||||||
|
private DesensitizationRule rule; |
||||||
|
private static Map<String, String> roleMap; |
||||||
|
private static Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> latestRules; |
||||||
|
private CellDesensitizationTableModel model; |
||||||
|
private static final CellDesensitizationBean EMPTY_BEAN = CellDesensitizationBean.createEmptyBean(); |
||||||
|
|
||||||
|
|
||||||
|
DesensitizationCellPane(Component parent, CellDesensitizationTableModel model) { |
||||||
|
this.parent = parent; |
||||||
|
this.model = model; |
||||||
|
|
||||||
|
initComponent(); |
||||||
|
|
||||||
|
addListener(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initComponent() { |
||||||
|
editPanel = new JPanel(); |
||||||
|
editPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true)); |
||||||
|
|
||||||
|
label = new UILabel(); |
||||||
|
label.setEnabled(false); |
||||||
|
editPanel.add(label); |
||||||
|
|
||||||
|
ruleButton = new UIButton(APOSTROPHE); |
||||||
|
|
||||||
|
ruleTextField = new UITextField(); |
||||||
|
ruleTextField.setEnabled(true); |
||||||
|
ruleTextField.setEditable(false); |
||||||
|
ruleTextField.setPlaceholder(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Place_Holder")); |
||||||
|
|
||||||
|
roleMap = new HashedMap<>(); |
||||||
|
rolesComboBox = new RuleUIComboCheckBox(); |
||||||
|
rolesComboBox.setPlaceHolder(Toolkit.i18nText("Fine-Design_Report_Desensitization_Role_Place_Holder")); |
||||||
|
rolesComboBox.setEnabled(true); |
||||||
|
latestRules = new HashMap<>(); |
||||||
|
|
||||||
|
emptyTextField = new UITextField(); |
||||||
|
emptyTextField.setEnabled(false); |
||||||
|
emptyTextField.setOpaque(false); |
||||||
|
|
||||||
|
editPanel.add(initTableCellPanel()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化单元格中的panel |
||||||
|
*/ |
||||||
|
private JPanel initTableCellPanel() { |
||||||
|
double f = TableLayout.FILL; |
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
|
||||||
|
double[] rowSize = new double[]{f, f}; |
||||||
|
double[] columnSize = new double[]{p, f}; |
||||||
|
|
||||||
|
Component[][] components = new Component[][]{ |
||||||
|
new Component[]{ruleButton, ruleTextField}, |
||||||
|
new Component[]{emptyTextField, rolesComboBox} |
||||||
|
}; |
||||||
|
return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 0, 0); |
||||||
|
} |
||||||
|
|
||||||
|
private void addListener() { |
||||||
|
ruleButton.addActionListener(chooseRuleListener); |
||||||
|
|
||||||
|
rolesComboBox.registerChangeListener(uiObserverListener); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private final UIObserverListener uiObserverListener = new UIObserverListener() { |
||||||
|
@Override |
||||||
|
public void doChange() { |
||||||
|
CellDesensitizationBean selectBean = model.getSelectedValue(); |
||||||
|
Set<String> roleIds = generateRolesIdsBySelectedValues(); |
||||||
|
if (Objects.nonNull(selectBean) && !selectBean.getRoleIds().equals(roleIds)) { |
||||||
|
selectBean.setRoleIds(generateRolesIdsBySelectedValues()); |
||||||
|
model.fireTableDataChanged(); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
private final ActionListener chooseRuleListener = new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
|
||||||
|
CellDesensitizationBean selectBean = model.getSelectedValue(); |
||||||
|
DesensitizationRulePane rulePane = new DesensitizationRulePane(latestRules); |
||||||
|
BasicDialog ruleDialog = rulePane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void doOk() { |
||||||
|
rule = rulePane.updateBean(); |
||||||
|
if (Objects.nonNull(selectBean) && Objects.nonNull(rule) && !selectBean.getDesensitizationRule().equals(rule)) { |
||||||
|
selectBean.setDesensitizationRule(rule); |
||||||
|
|
||||||
|
model.fireTableDataChanged(); |
||||||
|
} |
||||||
|
rule = null; |
||||||
|
} |
||||||
|
}, BasicDialog.DEFAULT); |
||||||
|
|
||||||
|
ruleDialog.setVisible(true); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据当前的规则配置信息,生成选中的rolesMap用来展示 |
||||||
|
*/ |
||||||
|
public Map<Object, Boolean> generateRolesCheckBoxSelectedValues(CellDesensitizationBean bean) { |
||||||
|
Map<Object, Boolean> result = new HashMap<>(roleMap.size()); |
||||||
|
for (Map.Entry<String, String> roleEntry : roleMap.entrySet()) { |
||||||
|
String roleId = roleEntry.getKey(); |
||||||
|
String roleName = roleEntry.getValue(); |
||||||
|
result.put(roleName, bean.getRoleIds().contains(roleId)); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据当前的RoleName选择项,生成其对应的RoleId的set存入规则配置信息 |
||||||
|
*/ |
||||||
|
public Set<String> generateRolesIdsBySelectedValues() { |
||||||
|
Set<String> result = new LinkedHashSet<>(); |
||||||
|
Object[] selectedValues = rolesComboBox.getSelectedValues(); |
||||||
|
for (Object selectedValue : selectedValues) { |
||||||
|
String selectedRoleName = (String) selectedValue; |
||||||
|
if (roleMap.containsValue(selectedRoleName)) { |
||||||
|
Optional<Map.Entry<String, String>> matchedEntry = roleMap.entrySet().stream().filter(entry -> StringUtils.equals(entry.getValue(), selectedRoleName)).findFirst(); |
||||||
|
matchedEntry.ifPresent(stringStringEntry -> result.add(stringStringEntry.getKey())); |
||||||
|
} |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
public JPanel getEditPanel() { |
||||||
|
return editPanel; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 填充数据 |
||||||
|
*/ |
||||||
|
public void populate(CellDesensitizationBean value, int row) { |
||||||
|
|
||||||
|
refreshRoles(); |
||||||
|
|
||||||
|
refreshRuleText(value); |
||||||
|
// 非正常状态需要颜色修改为红色
|
||||||
|
refreshRuleState(value); |
||||||
|
|
||||||
|
Map<Object, Boolean> map = generateRolesCheckBoxSelectedValues(value); |
||||||
|
rolesComboBox.setSelectedValues(map); |
||||||
|
|
||||||
|
label.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Setting") + (row + 1)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 刷新规则文本 |
||||||
|
* |
||||||
|
* @param value |
||||||
|
*/ |
||||||
|
private void refreshRuleText(CellDesensitizationBean value) { |
||||||
|
ruleTextField.setText(StringUtils.EMPTY); |
||||||
|
DesensitizationRule desensitizationRule = value.getDesensitizationRule(); |
||||||
|
if (desensitizationRule != null) { |
||||||
|
String ruleName = desensitizationRule.getRuleName(); |
||||||
|
ruleTextField.setText(ruleName); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* combobox组件刷新用户组信息 |
||||||
|
*/ |
||||||
|
private void refreshRoles() { |
||||||
|
rolesComboBox.clearText(); |
||||||
|
rolesComboBox.refreshCombo(roleMap.values().toArray()); |
||||||
|
} |
||||||
|
|
||||||
|
private void refreshRuleState(CellDesensitizationBean value) { |
||||||
|
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(value.getDesensitizationRule(), latestRules); |
||||||
|
if (EMPTY_BEAN.equals(value)) { |
||||||
|
ruleTextField.setForeground(Color.GRAY); |
||||||
|
} else if (ruleStatus != DesensitizationRuleStatus.NORMAL) { |
||||||
|
ruleTextField.setForeground(Color.RED); |
||||||
|
} else { |
||||||
|
ruleTextField.setForeground(Color.BLACK); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Deprecated |
||||||
|
@Override |
||||||
|
public void populateBean(Object ob) { |
||||||
|
} |
||||||
|
|
||||||
|
@Deprecated |
||||||
|
@Override |
||||||
|
public Object updateBean() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Deprecated |
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public Object getCellEditorValue() { |
||||||
|
return ruleTextField.getText(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private class RuleUIComboCheckBox extends UIComboCheckBox { |
||||||
|
public RuleUIComboCheckBox() { |
||||||
|
super(DesensitizationCellPane.this.roleMap.values().toArray(), true); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void setLayoutAndAddComponents() { |
||||||
|
// 使用BorderLayout,否则默认使用的FlowLayout会让整个下拉选框使用最小Size,然后TableCell这边会出现空白
|
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
this.add(getEditor(), BorderLayout.CENTER); |
||||||
|
this.add(getArrowButton(), BorderLayout.EAST); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void setEditorToolTipText(JComponent editor, String text) { |
||||||
|
// 选项过多时,已选中的值会做省略显示处理,此处添加一个Tooltips,显示完整值
|
||||||
|
if (text != null) { |
||||||
|
editor.setToolTipText(text); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void setEditorPlaceHolder(UITextField editor) { |
||||||
|
editor.setPlaceholder(this.getPlaceHolder()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String omitEditorText(UITextField textEditor, String text) { |
||||||
|
char[] omitChars = OMIT_TEXT.toCharArray(); |
||||||
|
//获取字体的大小
|
||||||
|
FontMetrics fontMetrics = textEditor.getFontMetrics(textEditor.getFont()); |
||||||
|
//计算省略号的长度
|
||||||
|
int omitLength = fontMetrics.charsWidth(omitChars, 0, omitChars.length); |
||||||
|
String omitText = StringUtils.EMPTY; |
||||||
|
char[] chars = text.toCharArray(); |
||||||
|
|
||||||
|
for (int i = 1; i <= chars.length; i++) { |
||||||
|
//如果原文本+省略号长度超过文本框
|
||||||
|
int width = textEditor.getWidth(); |
||||||
|
if (width > 0 && fontMetrics.charsWidth(chars, 0, i) + omitLength > width) { |
||||||
|
//从第i-1的位置截断再拼上省略号
|
||||||
|
omitText = text.substring(0, i - 2) + OMIT_TEXT; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return omitText.equals(StringUtils.EMPTY) ? text : omitText; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新用户组和平台规则 |
||||||
|
*/ |
||||||
|
public static void updateData(Map<String, String> roleMap, Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> latestRules) { |
||||||
|
DesensitizationCellPane.roleMap = roleMap; |
||||||
|
DesensitizationCellPane.latestRules = latestRules; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
package com.fr.design.mainframe.cell.settingpane.desensitization.model; |
||||||
|
|
||||||
|
import com.fr.report.cell.desensitization.CellDesensitizationBean; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JTable; |
||||||
|
import javax.swing.border.LineBorder; |
||||||
|
import javax.swing.table.DefaultTableCellRenderer; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* 脱敏规则设置cellRenderer |
||||||
|
* |
||||||
|
* @author Leo.Qin |
||||||
|
* @version 11.0 |
||||||
|
* Created by Leo.Qin on 2023/1/4 |
||||||
|
*/ |
||||||
|
public class DesensitizationCellRender extends DefaultTableCellRenderer { |
||||||
|
|
||||||
|
private final DesensitizationCellPane editPane; |
||||||
|
|
||||||
|
|
||||||
|
DesensitizationCellRender(Component parent, CellDesensitizationTableModel model) { |
||||||
|
editPane = new DesensitizationCellPane(parent, model); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public Object getCellEditorValue() { |
||||||
|
return editPane.getCellEditorValue(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||||||
|
|
||||||
|
editPane.populate((CellDesensitizationBean) value, row); |
||||||
|
if (table.isCellSelected(row, column)) { |
||||||
|
// 设置选中框
|
||||||
|
editPane.getEditPanel().setBorder(new LineBorder(Color.LIGHT_GRAY)); |
||||||
|
} else { |
||||||
|
editPane.getEditPanel().setBorder(BorderFactory.createEmptyBorder()); |
||||||
|
} |
||||||
|
|
||||||
|
return editPane.getEditPanel(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
package com.fr.design.mainframe.cell.settingpane.desensitization.model; |
||||||
|
|
||||||
|
import com.fr.base.operator.org.OrganizationOperator; |
||||||
|
import com.fr.data.desensitize.rule.DesensitizationRuleManager; |
||||||
|
import com.fr.data.desensitize.rule.base.DesensitizationRule; |
||||||
|
import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; |
||||||
|
import com.fr.workspace.WorkContext; |
||||||
|
|
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.ExecutionException; |
||||||
|
|
||||||
|
/** |
||||||
|
* 刷新脱敏设置全局 roles 和 rules SwingWorker |
||||||
|
* |
||||||
|
* @author Leo.Qin |
||||||
|
* @version 11.0 |
||||||
|
* Created by Leo.Qin on 2023/1/5 |
||||||
|
*/ |
||||||
|
public class UpdateDataWorker extends SwingWorker<Map<String, Object>, Void> { |
||||||
|
|
||||||
|
private final String ROLE_KEY = "Roles"; |
||||||
|
private final String RULE_KEY = "Rules"; |
||||||
|
|
||||||
|
@Override |
||||||
|
protected Map<String, Object> doInBackground() { |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
Map<String, String> allRoles = WorkContext.getCurrent().get(OrganizationOperator.class).getAllRoles4Desensitization(); |
||||||
|
Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> allRules = DesensitizationRuleManager.getInstance().getAllRules(); |
||||||
|
|
||||||
|
result.put(ROLE_KEY, allRoles); |
||||||
|
result.put(RULE_KEY, allRules); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void done() { |
||||||
|
try { |
||||||
|
Map<String, Object> result = get(); |
||||||
|
DesensitizationCellPane.updateData((Map<String, String>) result.get(ROLE_KEY), (Map<DesensitizationRuleSource, Map<String, DesensitizationRule>>) result.get(RULE_KEY)); |
||||||
|
} catch (InterruptedException | ExecutionException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue