Browse Source

REPORT-75091 - 数据脱敏(报表)

【问题原因】处理新增代码行数太多的问题
【改动思路】将新增的UI面板拆出来
【review建议】
feature/x
Yvan-欧阳帆 2 years ago
parent
commit
b3836e0a39
  1. 115
      designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java
  2. 120
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java

115
designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java

@ -12,10 +12,10 @@ import com.fr.data.impl.EmbeddedTableData;
import com.fr.data.impl.NameDataModel; import com.fr.data.impl.NameDataModel;
import com.fr.data.operator.DataOperator; import com.fr.data.operator.DataOperator;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.constants.UIConstants;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager;
import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel; import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel;
import com.fr.design.data.datapane.preview.desensitization.view.PreviewTableDesensitizationPane;
import com.fr.design.data.datapane.preview.desensitization.view.setting.TableDataDesensitizationSettingPane; import com.fr.design.data.datapane.preview.desensitization.view.setting.TableDataDesensitizationSettingPane;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
@ -23,19 +23,15 @@ import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.ibutton.UIToggleButton;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.iprogressbar.AutoProgressBar; import com.fr.design.gui.iprogressbar.AutoProgressBar;
import com.fr.design.gui.itable.SortableJTable; import com.fr.design.gui.itable.SortableJTable;
import com.fr.design.gui.itable.TableSorter; import com.fr.design.gui.itable.TableSorter;
import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.gui.itextfield.UINumberField;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.menu.SeparatorDef;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.ui.util.UIUtil; import com.fr.design.ui.util.UIUtil;
import com.fr.function.TIME; import com.fr.function.TIME;
import com.fr.general.FRFont; import com.fr.general.FRFont;
@ -61,8 +57,6 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -77,11 +71,6 @@ import java.util.concurrent.CancellationException;
*/ */
public class PreviewTablePane extends BasicPane { public class PreviewTablePane extends BasicPane {
private static final String DATA_DESENSITIZATION_CONFIG = Toolkit.i18nText("Fine-Design_Report_Desensitization_Config");
private static final String LEFT_BRACKET = "(";
private static final String RIGHT_BRACKET = ")";
private static final String COUNT = Toolkit.i18nText("Fine-Design_Report_Desensitization_Count");
private TableData tableData; private TableData tableData;
private DataModel dataModel; private DataModel dataModel;
private UINumberField maxPreviewNumberField; private UINumberField maxPreviewNumberField;
@ -97,7 +86,7 @@ public class PreviewTablePane extends BasicPane {
private static PreviewTablePane THIS; private static PreviewTablePane THIS;
private EmbeddedTableData previewTableData; private EmbeddedTableData previewTableData;
private UILabel desensitizationLabel; private PreviewTableDesensitizationPane desensitizationPane;
/** /**
* 用于refreshLabel的鼠标监听 * 用于refreshLabel的鼠标监听
@ -201,12 +190,9 @@ public class PreviewTablePane extends BasicPane {
maxPreviewNumberField.setColumns(4); maxPreviewNumberField.setColumns(4);
maxPreviewNumberField.setInteger(true); maxPreviewNumberField.setInteger(true);
maxPreviewNumberField.setValue(DesignerEnvManager.getEnvManager().getMaxNumberOrPreviewRow()); maxPreviewNumberField.setValue(DesignerEnvManager.getEnvManager().getMaxNumberOrPreviewRow());
maxPreviewNumberField.addActionListener(new ActionListener() { maxPreviewNumberField.addActionListener(event -> {
@Override DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager();
public void actionPerformed(ActionEvent evt) { designerEnvManager.setMaxNumberOrPreviewRow((int) ((UINumberField) event.getSource()).getValue());
DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager();
designerEnvManager.setMaxNumberOrPreviewRow((int) ((UINumberField) evt.getSource()).getValue());
}
}); });
// 刷新按钮 // 刷新按钮
initRefreshLabel(); initRefreshLabel();
@ -229,63 +215,36 @@ public class PreviewTablePane extends BasicPane {
* @return * @return
*/ */
private JComponent initDesensitizationPane() { private JComponent initDesensitizationPane() {
JPanel desensitizationPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); desensitizationPane = new PreviewTableDesensitizationPane(this);
// 初始化Label return desensitizationPane;
desensitizationLabel = new UILabel(DATA_DESENSITIZATION_CONFIG); }
desensitizationLabel.setForeground(UIConstants.NORMAL_BLUE);
desensitizationLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
TableDataDesensitizationSettingPane settingPane = new TableDataDesensitizationSettingPane((DesensitizationTableData) tableData);
settingPane.populateBean((DesensitizationTableData) tableData);
BasicDialog dialog = settingPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(PreviewTablePane.this), new DialogActionAdapter() {
@Override
public void doOk() {
// 保存脱敏规则配置
settingPane.updateBean();
// 改变模板保存状态
JTemplate<?, ?> editingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (Objects.nonNull(editingTemplate)) {
editingTemplate.fireTargetModified(true);
}
}
@Override
public void doCancel() {
} /**
}, BasicDialog.DEFAULT); * 点击脱敏配置后的操作
dialog.setVisible(true); */
// 关闭预览页面 public void clickDesensitizationLabel() {
PreviewTablePane.this.dialog.setVisible(false); TableDataDesensitizationSettingPane settingPane = new TableDataDesensitizationSettingPane((DesensitizationTableData) tableData);
settingPane.populateBean((DesensitizationTableData) tableData);
BasicDialog dialog = settingPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(PreviewTablePane.this), new DialogActionAdapter() {
@Override
public void doOk() {
// 保存脱敏规则配置
settingPane.updateBean();
// 改变模板保存状态
JTemplate<?, ?> editingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (Objects.nonNull(editingTemplate)) {
editingTemplate.fireTargetModified(true);
}
} }
});
// 初始化分隔符
ToolBarDef toolbarDef = new ToolBarDef();
toolbarDef.addShortCut(SeparatorDef.DEFAULT);
UIToolbar toolBar = ToolBarDef.createJToolBar();
toolBar.setBorderPainted(false);
toolbarDef.updateToolBar(toolBar);
// 初始化预览按钮
UIToggleButton previewToggle = new UIToggleButton(new Icon[]{IconUtils.readIcon("/com/fr/design/images/m_file/preview"), IconUtils.readIcon("/com/fr/design/images/m_file/preview")}, true);
previewToggle.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Preview"));
previewToggle.setSelected(false);
previewToggle.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void doCancel() {
// 切换TableModel的脱敏状态
togglePreviewTableModelDesensitizeStatus();
// 刷新页面,展示
refreshTable();
}
});
desensitizationPane.add(desensitizationLabel); }
desensitizationPane.add(toolBar); }, BasicDialog.DEFAULT);
desensitizationPane.add(previewToggle); dialog.setVisible(true);
return desensitizationPane; // 关闭预览页面
PreviewTablePane.this.dialog.setVisible(false);
} }
/** /**
@ -294,12 +253,10 @@ public class PreviewTablePane extends BasicPane {
* @param model * @param model
*/ */
private void setDesensitizationCount(TableModel model) { private void setDesensitizationCount(TableModel model) {
if (isDesensitizeOpened()) { desensitizationPane.setDesensitizationCount(isDesensitizeOpened(),
int count = model instanceof DesensitizedPreviewTableModel ? ((DesensitizedPreviewTableModel) model).getDesensitizeColumnsCount() : 0; model instanceof DesensitizedPreviewTableModel ?
desensitizationLabel.setText(DATA_DESENSITIZATION_CONFIG + LEFT_BRACKET + count + RIGHT_BRACKET + COUNT); ((DesensitizedPreviewTableModel) model).getDesensitizeColumnsCount() :
} else { 0);
desensitizationLabel.setText(DATA_DESENSITIZATION_CONFIG);
}
} }
/** /**
@ -728,7 +685,7 @@ public class PreviewTablePane extends BasicPane {
/** /**
* 切换TableModel的展示状态 * 切换TableModel的展示状态
*/ */
private void togglePreviewTableModelDesensitizeStatus() { public void togglePreviewTableModelDesensitizeStatus() {
if (!isDesensitizeOpened()) { if (!isDesensitizeOpened()) {
// 未启用数据脱敏时,不需要切换 // 未启用数据脱敏时,不需要切换
return; return;
@ -743,7 +700,7 @@ public class PreviewTablePane extends BasicPane {
/** /**
* 刷新一下预览页面用于切换脱敏和非脱敏时的显示 * 刷新一下预览页面用于切换脱敏和非脱敏时的显示
*/ */
private void refreshTable() { public void refreshTable() {
TableModel originTableModel = getCurrentTableModel(); TableModel originTableModel = getCurrentTableModel();
setPreviewTableModel(originTableModel); setPreviewTableModel(originTableModel);
} }

120
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java

@ -0,0 +1,120 @@
package com.fr.design.data.datapane.preview.desensitization.view;
import com.fr.base.svg.IconUtils;
import com.fr.design.constants.UIConstants;
import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.gui.ibutton.UIToggleButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.i18n.Toolkit;
import com.fr.design.menu.SeparatorDef;
import com.fr.design.menu.ToolBarDef;
import javax.swing.Icon;
import javax.swing.JPanel;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* 数据集预览-脱敏配置面板主要展示当前脱敏开启状态当前脱敏设定数量等
*
* @author Yvan
* @version 11.0
* Created by Yvan on 2022/11/14
*/
public class PreviewTableDesensitizationPane extends JPanel {
private static final String DATA_DESENSITIZATION_CONFIG = Toolkit.i18nText("Fine-Design_Report_Desensitization_Config");
private static final String LEFT_BRACKET = "(";
private static final String RIGHT_BRACKET = ")";
private static final String COUNT = Toolkit.i18nText("Fine-Design_Report_Desensitization_Count");
/**
* 预览面板
*/
private PreviewTablePane previewTablePane;
/**
* "数据脱敏设置"-标签
*/
private UILabel desensitizationLabel;
/**
* 脱敏效果预览按钮
*/
private UIToggleButton previewToggle;
public PreviewTableDesensitizationPane(PreviewTablePane previewTablePane) {
this.previewTablePane = previewTablePane;
initComponents();
}
/**
* 初始化面板
*/
private void initComponents() {
this.setLayout(new FlowLayout(FlowLayout.LEFT));
this.add(initDesensitizationLabel());
this.add(initToolBar());
this.add(initPreviewButton());
}
/**
* 初始化Label
*
* @return
*/
private Component initDesensitizationLabel() {
// 初始化Label
desensitizationLabel = new UILabel(DATA_DESENSITIZATION_CONFIG);
desensitizationLabel.setForeground(UIConstants.NORMAL_BLUE);
desensitizationLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
previewTablePane.clickDesensitizationLabel();
}
});
return desensitizationLabel;
}
/**
* 初始化分隔符
*
* @return
*/
private UIToolbar initToolBar() {
ToolBarDef toolbarDef = new ToolBarDef();
toolbarDef.addShortCut(SeparatorDef.DEFAULT);
UIToolbar toolBar = ToolBarDef.createJToolBar();
toolBar.setBorderPainted(false);
toolbarDef.updateToolBar(toolBar);
return toolBar;
}
/**
* 初始化脱敏效果预览按钮
*
* @return
*/
private UIToggleButton initPreviewButton() {
previewToggle = new UIToggleButton(new Icon[]{IconUtils.readIcon("/com/fr/design/images/m_file/preview"), IconUtils.readIcon("/com/fr/design/images/m_file/preview")}, true);
previewToggle.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Preview"));
previewToggle.setSelected(false);
previewToggle.addActionListener(e -> {
// 切换TableModel的脱敏状态
previewTablePane.togglePreviewTableModelDesensitizeStatus();
// 刷新预览页面,展示
previewTablePane.refreshTable();
});
return previewToggle;
}
public void setDesensitizationCount(boolean desensitizeOpen, int count) {
desensitizationLabel.setText(desensitizeOpen ?
DATA_DESENSITIZATION_CONFIG + LEFT_BRACKET + count + RIGHT_BRACKET + COUNT :
DATA_DESENSITIZATION_CONFIG);
}
}
Loading…
Cancel
Save