From 8f8f92959af47676c17d00637ce32fa6005c8a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvan-=E6=AC=A7=E9=98=B3=E5=B8=86?= Date: Wed, 11 Jan 2023 10:44:35 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-83316=20&&=20REPORT-83320=20&&=20REPORT-?= =?UTF-8?q?83488=20&&=20REPORT-83493=20=E6=95=B0=E6=8D=AE=E8=84=B1?= =?UTF-8?q?=E6=95=8F=E4=B8=80=E6=9C=9F=E8=BF=AD=E4=BB=A3bug=20=E3=80=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0=E3=80=91=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E9=83=BD=E6=98=AFUI=E9=97=AE=E9=A2=98=20=E3=80=90=E6=94=B9?= =?UTF-8?q?=E5=8A=A8=E6=80=9D=E8=B7=AF=E3=80=91=E8=B7=9F=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E6=B2=9F=E9=80=9A=E5=90=8E=EF=BC=8C=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E3=80=90review=E5=BB=BA=E8=AE=AE=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datapane/preview/PreviewTablePane.java | 13 +- .../TableDataPreviewDesensitizeManager.java | 16 +- .../view/common/ChooseMark.java | 42 +++ .../rule/DesensitizationRuleChoosePane.java | 66 ++++- .../TableDataDesensitizationTableModel.java | 273 +++++++++++++----- .../gui/icombocheckbox/UICheckListPopup.java | 20 +- .../gui/icombocheckbox/UIComboCheckBox.java | 36 ++- 7 files changed, 377 insertions(+), 89 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/ChooseMark.java diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java index f65d4a9cfa..7b9a7a3d20 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java @@ -164,7 +164,6 @@ public class PreviewTablePane extends BasicPane { northPane.add(initPreviewNumberPane(), BorderLayout.CENTER); // 脱敏预览设置面板 northPane.add(initDesensitizationPane(), BorderLayout.EAST); - initDesensitizationPane(); return northPane; } @@ -260,6 +259,16 @@ public class PreviewTablePane extends BasicPane { 0); } + /** + * 根据TableData设置脱敏设置的个数 + */ + private void setDesensitizationCountByTableData() { + desensitizationPane.setDesensitizationCount(isDesensitizeOpened(), + this.tableData instanceof DesensitizationTableData ? + ((DesensitizationTableData) this.tableData).getDesensitizationConfig().getDesensitizationItems().size() : + 0); + } + /** * 初始化centerPane * @@ -722,7 +731,7 @@ public class PreviewTablePane extends BasicPane { * @param previewTableModel */ private void setPreviewTableModel(TableModel previewTableModel) { - setDesensitizationCount(previewTableModel); + setDesensitizationCountByTableData(); setModel(previewTableModel); setCurrentRows(previewTableModel.getRowCount()); fireLoadedListener(); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java index 3d3c59331f..3d8fc8d02b 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java @@ -5,6 +5,7 @@ import com.fr.base.TableData; import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.TableDataDesensitizationItem; import com.fr.data.desensitize.manage.DesensitizationManager; +import com.fr.data.desensitize.rule.DesensitizationRuleManager; import com.fr.data.desensitize.util.DesentizationUtils; import com.fr.decision.webservice.bean.user.DepartmentPostBean; import com.fr.decision.webservice.bean.user.RoleBean; @@ -77,7 +78,9 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage // 获取此数据集的所有脱敏信息 Collection desensitizationItems = ((DesensitizationTableData) tableData).getDesensitizationConfig().getDesensitizationItems(); if (DesentizationUtils.isCollectionNotEmpty(desensitizationItems)) { - // 先对脱敏配置项集合做过滤和排序处理 + // 更新规则 + dealWithLastedRules(desensitizationItems); + // 对脱敏配置项集合做过滤和排序处理 List items = desensitizationItems.stream() .filter(item -> item.getRule().isEnable() && matchColumnIndex(item, model) >= 0) @@ -92,9 +95,18 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage return new DesensitizedPreviewTableModel(model, desensitizationItemMap); } + /** + * 在预览计算前,将Item中的规则替换为最新规则(防止平台规则被临时修改) + */ + private void dealWithLastedRules(Collection desensitizationItems) { + desensitizationItems.forEach(item -> { + // 获取最新的规则 + item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule())); + }); + } + /** * 通过TableData获取其列名 - * 实现逻辑有点绕,TableData本身并不能返回列名集合,只能先去获取当前模板所有数据集,然后匹配名称拿到TableDataWrapper再获取列名 * * @param tableData * @return diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/ChooseMark.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/ChooseMark.java new file mode 100644 index 0000000000..099e9a960a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/ChooseMark.java @@ -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; + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java index fd627e8cc4..3b44c0b187 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java @@ -4,9 +4,10 @@ import com.fr.base.svg.IconUtils; 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.data.datapane.preview.desensitization.view.common.ChooseMark; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itableeditorpane.UITableEditAction; import com.fr.design.gui.itableeditorpane.UITableEditorPane; @@ -22,6 +23,7 @@ import javax.swing.SwingUtilities; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import java.awt.CardLayout; +import java.awt.Color; import java.awt.Component; import java.awt.event.ActionEvent; import java.util.LinkedHashSet; @@ -107,18 +109,23 @@ public class DesensitizationRuleChoosePane extends JPanel { super(new String[]{ StringUtils.EMPTY, Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Name"), - Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Description") + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Description"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"), }); this.parent = parent; this.debugActionOnly = debugActionOnly; this.setColumnClass(new Class[]{ - RuleChoosePane.class, + ChooseMark.class, UILabel.class, - UILabel.class + UILabel.class, + DesensitizationRuleStatusPane.class }); - this.setDefaultEditor(RuleChoosePane.class, new RuleChoosePane()); - this.setDefaultRenderer(RuleChoosePane.class, new RuleChoosePane()); + this.setDefaultEditor(ChooseMark.class, new ChooseMark()); + this.setDefaultRenderer(ChooseMark.class, new ChooseMark()); + this.setDefaultEditor(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); + this.setDefaultRenderer(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); this.createTable().getColumnModel().getColumn(0).setMaxWidth(20); + this.createTable().getColumnModel().getColumn(3).setMaxWidth(60); } @Override @@ -134,6 +141,11 @@ public class DesensitizationRuleChoosePane extends JPanel { case 2: // 脱敏规则描述 return DesensitizationRule.getDescription(rule); + case 3: + // 脱敏规则状态 + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule); + // 非正常状态需要标记为异常 + return ruleStatus == DesensitizationRuleStatus.NORMAL ? StringUtils.EMPTY : Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal"); default: return StringUtils.EMPTY; } @@ -161,29 +173,51 @@ public class DesensitizationRuleChoosePane extends JPanel { .collect(Collectors.toSet()); } - private class RuleChoosePane extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { + /** + * 规则状态展示页面 + */ + private class DesensitizationRuleStatusPane extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { - private UIRadioButton selectedButton; + private UILabel ruleStatusLabel; - public RuleChoosePane() { - this.selectedButton = new UIRadioButton(); + DesensitizationRuleStatusPane() { + // 规则状态 + this.ruleStatusLabel = new UILabel(); + this.ruleStatusLabel.setForeground(Color.RED); + } + + /** + * 根据脱敏规则信息,刷新规则状态,主要用于与规则选择器的联动 + * + * @param rule + */ + public void refreshRuleStatus(DesensitizationRule rule) { + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule); + if (ruleStatus == DesensitizationRuleStatus.NORMAL) { + // 正常规则时,重置提示Label + this.ruleStatusLabel.setText(StringUtils.EMPTY); + this.ruleStatusLabel.setToolTipText(null); + } else { + this.ruleStatusLabel.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal")); + this.ruleStatusLabel.setToolTipText(ruleStatus.getDescription()); + } } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - selectedButton.setSelected(isSelected); - return selectedButton; + refreshRuleStatus(getList().get(row)); + return ruleStatusLabel; } @Override public Object getCellEditorValue() { - return selectedButton.isSelected(); + return ruleStatusLabel; } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - selectedButton.setSelected(isSelected); - return selectedButton; + refreshRuleStatus(getList().get(row)); + return ruleStatusLabel; } } @@ -298,7 +332,7 @@ public class DesensitizationRuleChoosePane extends JPanel { @Override public void checkEnabled() { - setEnabled(table.getSelectedRow() != -1); + setEnabled(table.getSelectedRow() != -1 && getList().get(table.getSelectedRow()).isEnable()); } @Override diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java index bbc91efa2a..4d6cfa8ff6 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java @@ -2,11 +2,14 @@ package com.fr.design.data.datapane.preview.desensitization.view.setting; import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.TableDataDesensitizationItem; +import com.fr.data.desensitize.rule.DesensitizationRuleManager; import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.data.desensitize.rule.base.DesensitizationRuleStatus; import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; 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.dialog.FineJOptionPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombocheckbox.UIComboCheckBox; @@ -15,12 +18,14 @@ import com.fr.design.gui.itableeditorpane.UITableEditAction; import com.fr.design.gui.itableeditorpane.UITableModelAdapter; 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.stable.StringUtils; import org.jetbrains.annotations.Nullable; import javax.swing.AbstractCellEditor; +import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.SwingUtilities; @@ -28,10 +33,11 @@ import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; +import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashSet; @@ -52,6 +58,8 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter matchRoleNamesByIds(Collection roleIds) { - List result = new ArrayList<>(); + private String matchRoleNamesByIds(Collection roleIds) { + StringBuilder builder = new StringBuilder(); for (String roleId : roleIds) { if (roleMap != null && roleMap.containsKey(roleId)) { - result.add(roleMap.get(roleId)); + builder.append(roleMap.get(roleId)); + builder.append(COMMA); } } - return result; + return builder.length() <= 1 ? StringUtils.EMPTY : builder.substring(0, builder.length() - 1); } @Override public boolean isCellEditable(int row, int col) { - return true; + TableSequences match = TableSequences.match(col); + return match != TableSequences.DesensitizationRuleStatus; } @Override @@ -166,7 +183,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter 0 ? builder.substring(0, builder.length() - 1) : StringUtils.EMPTY; //计算加省略号后的文本 editor.setText(this.showOmitText ? omitEditorText(editor, text) : text); + // tooltips显示原值 + setEditorToolTipText(editor, text); + } + + /** + * 为UITextField设置悬浮提示值 + * + * @param editor + * @param text + */ + protected void setEditorToolTipText(JComponent editor, String text) { + // 默认不做设置 } /**