From 76a26bb37f8efdc2970cd2f8794ddf7537984207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvan-=E6=AC=A7=E9=98=B3=E5=B8=86?= Date: Thu, 9 Feb 2023 15:55:39 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-80693=20=E6=95=B0=E6=8D=AE=E8=84=B1?= =?UTF-8?q?=E6=95=8F=E8=BF=9C=E7=A8=8B=E8=AE=BE=E8=AE=A1=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98=20=E3=80=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=8E=9F=E5=9B=A0=E3=80=91rt=20=E3=80=90=E6=94=B9?= =?UTF-8?q?=E5=8A=A8=E6=80=9D=E8=B7=AF=E3=80=91=E5=86=8D=E6=94=B9=E4=B8=80?= =?UTF-8?q?=E7=89=88=E8=BF=9C=E7=A8=8B=E4=B8=8B=E7=9A=84=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=201.=20=E4=B9=8B=E5=89=8D=E7=9A=84SwingWorke?= =?UTF-8?q?r=E6=8F=90=E5=89=8D=E5=88=B0=E7=88=B6=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=8F=AA=E6=9F=A5=E8=AF=A2=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=E6=8D=AE=E5=BA=93=EF=BC=8C=E6=AD=A4=E5=90=8E?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E4=B8=8E=E5=AD=90=E9=9D=A2=E6=9D=BF=E5=9D=87?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=202.=20=E5=A2=9E=E5=8A=A0Loading=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E9=81=BF=E5=85=8D=E5=8D=A1UI=E7=9A=84?= =?UTF-8?q?=E8=AF=AF=E4=BC=9A=203.=20=E4=BF=AE=E6=94=B9=E8=A7=84=E5=88=99?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=99=A8DesensitizationRuleManager=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E6=96=B9=E6=B3=95=EF=BC=8C=E5=80=92?= =?UTF-8?q?=E9=80=BC=E8=B0=83=E7=94=A8=E8=80=85=E4=BD=BF=E7=94=A8=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=80=A7=E7=9A=84=E6=9F=A5=E8=AF=A2=EF=BC=9B=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E7=9B=B8=E5=BA=94=E8=B0=83=E7=94=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E9=80=82=E9=85=8D=20=E3=80=90review=E5=BB=BA?= =?UTF-8?q?=E8=AE=AE=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rule/DesensitizationRuleChoosePane.java | 14 ++- .../view/rule/DesensitizationRulePane.java | 11 ++- .../TableDataDesensitizationTableModel.java | 76 +++++---------- .../TableDataDesensitizationTablePane.java | 97 +++++++++++++++++-- 4 files changed, 134 insertions(+), 64 deletions(-) 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 3b44c0b187..e1dc9d7226 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 @@ -28,6 +28,7 @@ import java.awt.Component; import java.awt.event.ActionEvent; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -48,7 +49,10 @@ public class DesensitizationRuleChoosePane extends JPanel { private DesensitizationRuleSource currentRuleSource; - public DesensitizationRuleChoosePane() { + private Map> lastedRules; + + public DesensitizationRuleChoosePane(Map> lastedRules) { + this.lastedRules = lastedRules; this.cardLayout = new CardLayout(); this.setLayout(cardLayout); serverRuleEditPane = new UITableEditorPane<>(new DesensitizationRuleChooseTableModel(this, true)); @@ -76,8 +80,8 @@ public class DesensitizationRuleChoosePane extends JPanel { * 展示当前规则 */ private void populateDesensitizationRules() { - serverRuleEditPane.populate(DesensitizationRuleManager.getInstance().getRules(DesensitizationRuleSource.SERVER)); - customRuleEditPane.populate(DesensitizationRuleManager.getInstance().getRules(DesensitizationRuleSource.CUSTOM)); + serverRuleEditPane.populate(lastedRules.get(DesensitizationRuleSource.SERVER).values().toArray(new DesensitizationRule[0])); + customRuleEditPane.populate(lastedRules.get(DesensitizationRuleSource.CUSTOM).values().toArray(new DesensitizationRule[0])); } /** @@ -143,7 +147,7 @@ public class DesensitizationRuleChoosePane extends JPanel { return DesensitizationRule.getDescription(rule); case 3: // 脱敏规则状态 - DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule); + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, lastedRules); // 非正常状态需要标记为异常 return ruleStatus == DesensitizationRuleStatus.NORMAL ? StringUtils.EMPTY : Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal"); default: @@ -192,7 +196,7 @@ public class DesensitizationRuleChoosePane extends JPanel { * @param rule */ public void refreshRuleStatus(DesensitizationRule rule) { - DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule); + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, lastedRules); if (ruleStatus == DesensitizationRuleStatus.NORMAL) { // 正常规则时,重置提示Label this.ruleStatusLabel.setText(StringUtils.EMPTY); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java index 715c408192..b26b288f0a 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java @@ -9,6 +9,7 @@ import com.fr.design.layout.FRGUIPaneFactory; import javax.swing.JPanel; import java.awt.BorderLayout; +import java.util.Map; /** * 脱敏规则展示页 @@ -29,13 +30,19 @@ public class DesensitizationRulePane extends BasicBeanPane */ private DesensitizationRuleChoosePane ruleChoosePane; + /** + * 最新的所有规则 + */ + private Map> lastedRules; + /** * 内容面板 */ private JPanel contentPane; - public DesensitizationRulePane() { + public DesensitizationRulePane(Map> lastedRules) { this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.lastedRules = lastedRules; initPane(); } @@ -47,7 +54,7 @@ public class DesensitizationRulePane extends BasicBeanPane // 规则来源选择Pane ruleSourceChoosePane = new DesensitizationRuleSourceChoosePane(this); // 规则选择Pane - ruleChoosePane = new DesensitizationRuleChoosePane(); + ruleChoosePane = new DesensitizationRuleChoosePane(lastedRules); contentPane.add(ruleSourceChoosePane, BorderLayout.NORTH); contentPane.add(ruleChoosePane, BorderLayout.CENTER); } 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 e70f5e2cea..595fa4b8a8 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 @@ -4,8 +4,8 @@ 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.DesensitizationRuleSource; 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; @@ -20,7 +20,6 @@ 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.log.FineLoggerFactory; import com.fr.stable.StringUtils; import org.jetbrains.annotations.Nullable; @@ -29,7 +28,6 @@ import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.table.TableCellEditor; @@ -72,11 +70,16 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter roleMap = new LinkedHashMap<>(); + private Map roleMap = new LinkedHashMap<>(); + + /** + * 当前最新的所有规则 + */ + private Map> lastedRules = new LinkedHashMap<>(); private Component parent; - public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent) { + public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent, List columnNames, Map roleMap, Map> lastedRules) { // table相关 super(new String[]{ Toolkit.i18nText("Fine-Design_Report_Desensitization_Column"), @@ -86,6 +89,17 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter() { - - @Override - protected Void doInBackground() throws Exception { - // 获取当前数据集的所有列名 - columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData)); - // 获取当前所有用户组 - roleMap.putAll(TableDataPreviewDesensitizeManager.getInstance().getAllRoles()); - return null; - } - - @Override - protected void done() { - try { - // 更新列名选择框和生效用户组选择框 - columnNamesComboBox.refresh(); - effectedRolesChooser.refresh(); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e, "[Desensitization] get column names or all roles failed for {}", e.getMessage()); - } - } - }.execute(); - } @Override @@ -231,14 +220,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter iterator = items.iterator(); while (iterator.hasNext()) { TableDataDesensitizationItem item = iterator.next(); - DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule()); + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule(), lastedRules); if (ruleStatus == DesensitizationRuleStatus.REMOVED) { // 规则被移除,则删除整条脱敏Item iterator.remove(); } else { // 规则被修改、禁用等,更新一下规则 - item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule())); + item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule(), lastedRules)); } } fireTableDataChanged(); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java index e6395fe8b5..9ef6a7a2ff 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java @@ -2,13 +2,25 @@ 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.DesensitizationRuleSource; +import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; +import com.fr.design.data.tabledata.tabledatapane.loading.TipsPane; import com.fr.design.gui.itableeditorpane.UITableEditorPane; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.log.FineLoggerFactory; import javax.swing.JPanel; +import javax.swing.SwingWorker; import java.awt.BorderLayout; +import java.awt.CardLayout; import java.awt.Component; +import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * 脱敏字段设置页面中的Table @@ -34,6 +46,15 @@ public class TableDataDesensitizationTablePane extends JPanel { */ private UITableEditorPane editorPane; + private static final String LOADING_PANE = "loading"; + private static final String CONTENT_PANE = "content"; + + private CardLayout card; + + private JPanel loadingPane; + + private JPanel contentPane; + public TableDataDesensitizationTablePane(DesensitizationTableData tableData, Component parent) { this.tableData = tableData; this.parent = parent; @@ -41,10 +62,65 @@ public class TableDataDesensitizationTablePane extends JPanel { } private void initComponent() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.editorPane = new UITableEditorPane<>(new TableDataDesensitizationTableModel(tableData, parent)); - this.editorPane.setHeaderResizing(false); - this.add(editorPane, BorderLayout.CENTER); + + card = new CardLayout(); + this.setLayout(card); + // 初始化Loading面板 + loadingPane = new TipsPane(true); + this.add(LOADING_PANE, loadingPane); + switchTo(LOADING_PANE); + + // 在SwingWorker中初始化Content面板并切换 + initContent(); + } + + /** + * 初始化内容面板 + * 考虑到远程设计下的性能,需要限制查询数据库的次数,所以这里查一次,之后子面板内复用 + */ + private void initContent() { + final List columnNames = new ArrayList<>(); + final Map roleMap = new LinkedHashMap<>(); + final Map> lastedRules = new LinkedHashMap<>(); + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + // 获取当前数据集的所有列名 + columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData)); + // 获取当前所有用户组 + roleMap.putAll(TableDataPreviewDesensitizeManager.getInstance().getAllRoles()); + // 获取当前最新的所有规则 + lastedRules.putAll(DesensitizationRuleManager.getInstance().getAllRules()); + return null; + } + + @Override + protected void done() { + contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + editorPane = new UITableEditorPane<>(new TableDataDesensitizationTableModel(tableData, parent, columnNames, roleMap, lastedRules)); + editorPane.setHeaderResizing(false); + editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0])); + contentPane.add(editorPane, BorderLayout.CENTER); + add(CONTENT_PANE, contentPane); + switchTo(CONTENT_PANE); + } + }.execute(); + } + + /** + * 切换面板 + * + * @param panelName + */ + public void switchTo(String panelName) { + try { + if (panelName != null) { + card.show(this, panelName); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } } /** @@ -54,13 +130,22 @@ public class TableDataDesensitizationTablePane extends JPanel { */ public void populateDesensitizationSetting(DesensitizationTableData tableData) { this.tableData = tableData; - editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0])); + if (editorPane != null) { + // editorPane的初始化在SwingWorker中完成,这里做个判空 + editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0])); + } } /** * 获取当前对TableData的配置脱敏规则信息 */ public List updateDesensitizationSetting() { - return editorPane.update(); + + return editorPane == null ? + new ArrayList<>() : + editorPane.update() + .stream() + .filter(item -> TableDataDesensitizationItem.valid(item)) + .collect(Collectors.toList()); } }