|
|
|
@ -3,17 +3,23 @@
|
|
|
|
|
*/ |
|
|
|
|
package com.fr.design.data.datapane.preview; |
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
import com.fr.base.TableData; |
|
|
|
|
import com.fr.base.svg.IconUtils; |
|
|
|
|
import com.fr.data.TableDataSource; |
|
|
|
|
import com.fr.data.desensitize.base.DesensitizationTableData; |
|
|
|
|
import com.fr.data.impl.DBTableData; |
|
|
|
|
import com.fr.data.impl.EmbeddedTableData; |
|
|
|
|
import com.fr.data.impl.NameDataModel; |
|
|
|
|
import com.fr.data.operator.DataOperator; |
|
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
|
import com.fr.design.data.DesignTableDataManager; |
|
|
|
|
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.view.PreviewTableDesensitizationPane; |
|
|
|
|
import com.fr.design.data.datapane.preview.desensitization.view.setting.TableDataDesensitizationSettingPane; |
|
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
|
import com.fr.design.dialog.BasicPane; |
|
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
|
import com.fr.design.file.HistoryTemplateListCache; |
|
|
|
|
import com.fr.design.gui.frpane.UITabbedPane; |
|
|
|
@ -25,6 +31,7 @@ import com.fr.design.gui.itextfield.UINumberField;
|
|
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
|
import com.fr.design.ui.util.UIUtil; |
|
|
|
|
import com.fr.function.TIME; |
|
|
|
|
import com.fr.general.FRFont; |
|
|
|
@ -39,6 +46,7 @@ import javax.swing.JOptionPane;
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JScrollPane; |
|
|
|
|
import javax.swing.JTable; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
import javax.swing.UIManager; |
|
|
|
|
import javax.swing.table.DefaultTableCellRenderer; |
|
|
|
@ -49,20 +57,20 @@ import java.awt.Color;
|
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Font; |
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
import java.sql.Timestamp; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.concurrent.CancellationException; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* august: PreviewTablePane一共提供5个共有的静态方法,用来预览。 |
|
|
|
|
*/ |
|
|
|
|
public class PreviewTablePane extends BasicPane { |
|
|
|
|
|
|
|
|
|
private TableData tableData; |
|
|
|
|
private DataModel dataModel; |
|
|
|
|
private UINumberField maxPreviewNumberField; |
|
|
|
@ -78,6 +86,54 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
private static PreviewTablePane THIS; |
|
|
|
|
private EmbeddedTableData previewTableData; |
|
|
|
|
|
|
|
|
|
private PreviewTableDesensitizationPane desensitizationPane; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 用于refreshLabel的鼠标监听 |
|
|
|
|
*/ |
|
|
|
|
private final MouseAdapter refreshLabelMouseAdapter = new MouseAdapter() { |
|
|
|
|
boolean mouseEntered = false; |
|
|
|
|
boolean buttonPressed = false; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseEntered(MouseEvent e) { // 当鼠标进入时候调用.
|
|
|
|
|
mouseEntered = true; |
|
|
|
|
if (!buttonPressed) { |
|
|
|
|
refreshLabel.setBackground(java.awt.Color.WHITE); |
|
|
|
|
refreshLabel.setOpaque(true); |
|
|
|
|
refreshLabel.setBorder(BorderFactory.createLineBorder(java.awt.Color.GRAY)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
|
mouseEntered = false; |
|
|
|
|
refreshLabel.setOpaque(false); |
|
|
|
|
refreshLabel.setBorder(BorderFactory.createEmptyBorder()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
buttonPressed = true; |
|
|
|
|
refreshLabel.setBackground(java.awt.Color.lightGray); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
buttonPressed = false; |
|
|
|
|
if (mouseEntered) { |
|
|
|
|
refreshLabel.setBackground(java.awt.Color.WHITE); |
|
|
|
|
try { |
|
|
|
|
populate(tableData); |
|
|
|
|
if (dataModel != null) { |
|
|
|
|
setRowsLimitTableModel(); |
|
|
|
|
} |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
public static final PreviewTablePane getInstance() { |
|
|
|
|
if (THIS == null) { |
|
|
|
|
THIS = new PreviewTablePane(); |
|
|
|
@ -87,91 +143,143 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
|
|
|
|
|
private PreviewTablePane() { |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
// northPane
|
|
|
|
|
this.add(initNorthPane(), BorderLayout.NORTH); |
|
|
|
|
// centerPane
|
|
|
|
|
this.add(initCenterPane(), BorderLayout.CENTER); |
|
|
|
|
// dialog
|
|
|
|
|
initDialog(); |
|
|
|
|
// progressBar
|
|
|
|
|
initProgressBar(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// elalke:预览行数
|
|
|
|
|
JPanel previewNumberPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
this.add(previewNumberPanel, BorderLayout.NORTH); |
|
|
|
|
/** |
|
|
|
|
* 初始化northPane |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private JComponent initNorthPane() { |
|
|
|
|
JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
// 预览行数面板
|
|
|
|
|
northPane.add(initPreviewNumberPane(), BorderLayout.CENTER); |
|
|
|
|
// 脱敏预览设置面板
|
|
|
|
|
northPane.add(initDesensitizationPane(), BorderLayout.EAST); |
|
|
|
|
return northPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化预览行数面板 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private JComponent initPreviewNumberPane() { |
|
|
|
|
JPanel previewNumberPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
// 当前行数
|
|
|
|
|
JPanel currentPreviewPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
previewNumberPanel.add(currentPreviewPanel); |
|
|
|
|
currentPreviewPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Current_Preview_Rows") + ":")); |
|
|
|
|
|
|
|
|
|
currentRowsField = new UINumberField(); |
|
|
|
|
currentPreviewPanel.add(currentRowsField); |
|
|
|
|
currentRowsField.setEditable(false); |
|
|
|
|
currentRowsField.setColumns(4); |
|
|
|
|
currentRowsField.setInteger(true); |
|
|
|
|
|
|
|
|
|
// 最大行数
|
|
|
|
|
JPanel maxPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
previewNumberPanel.add(maxPanel); |
|
|
|
|
maxPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Datasource_Maximum_Number_of_Preview_Rows") + ":")); |
|
|
|
|
|
|
|
|
|
maxPreviewNumberField = new UINumberField(); |
|
|
|
|
maxPanel.add(maxPreviewNumberField); |
|
|
|
|
maxPreviewNumberField.setColumns(4); |
|
|
|
|
maxPreviewNumberField.setInteger(true); |
|
|
|
|
|
|
|
|
|
DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); |
|
|
|
|
maxPreviewNumberField.setValue(designerEnvManager.getMaxNumberOrPreviewRow()); |
|
|
|
|
|
|
|
|
|
maxPreviewNumberField.addActionListener(new ActionListener() { |
|
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
|
|
DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); |
|
|
|
|
designerEnvManager.setMaxNumberOrPreviewRow((int) ((UINumberField) evt.getSource()).getValue()); |
|
|
|
|
} |
|
|
|
|
maxPreviewNumberField.setValue(DesignerEnvManager.getEnvManager().getMaxNumberOrPreviewRow()); |
|
|
|
|
maxPreviewNumberField.addActionListener(event -> { |
|
|
|
|
DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); |
|
|
|
|
designerEnvManager.setMaxNumberOrPreviewRow((int) ((UINumberField) event.getSource()).getValue()); |
|
|
|
|
}); |
|
|
|
|
// 刷新按钮
|
|
|
|
|
initRefreshLabel(); |
|
|
|
|
|
|
|
|
|
Icon refreshImage = BaseUtils.readIcon("/com/fr/design/images/control/refresh.png"); |
|
|
|
|
refreshLabel = new UILabel(refreshImage); |
|
|
|
|
previewNumberPanel.add(currentPreviewPanel); |
|
|
|
|
previewNumberPanel.add(maxPanel); |
|
|
|
|
previewNumberPanel.add(refreshLabel); |
|
|
|
|
refreshLabel.addMouseListener(new MouseAdapter() { |
|
|
|
|
boolean mouseEntered = false; |
|
|
|
|
boolean buttonPressed = false; |
|
|
|
|
|
|
|
|
|
public void mouseEntered(MouseEvent e) { // 当鼠标进入时候调用.
|
|
|
|
|
mouseEntered = true; |
|
|
|
|
if (!buttonPressed) { |
|
|
|
|
refreshLabel.setBackground(java.awt.Color.WHITE); |
|
|
|
|
refreshLabel.setOpaque(true); |
|
|
|
|
refreshLabel.setBorder(BorderFactory.createLineBorder(java.awt.Color.GRAY)); |
|
|
|
|
return previewNumberPanel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initRefreshLabel() { |
|
|
|
|
Icon refreshImage = IconUtils.readIcon("/com/fr/design/images/control/refresh"); |
|
|
|
|
refreshLabel = new UILabel(refreshImage); |
|
|
|
|
refreshLabel.addMouseListener(refreshLabelMouseAdapter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化脱敏设置面板 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private JComponent initDesensitizationPane() { |
|
|
|
|
desensitizationPane = new PreviewTableDesensitizationPane(this); |
|
|
|
|
return desensitizationPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 点击脱敏配置后的操作 |
|
|
|
|
*/ |
|
|
|
|
public void clickDesensitizationLabel() { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void mouseExited(MouseEvent e) { |
|
|
|
|
mouseEntered = false; |
|
|
|
|
refreshLabel.setOpaque(false); |
|
|
|
|
refreshLabel.setBorder(BorderFactory.createEmptyBorder()); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public void doCancel() { |
|
|
|
|
|
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
buttonPressed = true; |
|
|
|
|
refreshLabel.setBackground(java.awt.Color.lightGray); |
|
|
|
|
} |
|
|
|
|
}, BasicDialog.DEFAULT); |
|
|
|
|
dialog.setVisible(true); |
|
|
|
|
// 关闭预览页面
|
|
|
|
|
PreviewTablePane.this.dialog.setVisible(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
buttonPressed = false; |
|
|
|
|
if (mouseEntered) { |
|
|
|
|
refreshLabel.setBackground(java.awt.Color.WHITE); |
|
|
|
|
try { |
|
|
|
|
populate(tableData); |
|
|
|
|
if (dataModel != null) { |
|
|
|
|
setRowsLimitTableModel(); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e1) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
/** |
|
|
|
|
* 设置脱敏设置的个数 |
|
|
|
|
* |
|
|
|
|
* @param model |
|
|
|
|
*/ |
|
|
|
|
private void setDesensitizationCount(TableModel model) { |
|
|
|
|
desensitizationPane.setDesensitizationCount(isDesensitizeOpened(), |
|
|
|
|
model instanceof DesensitizedPreviewTableModel ? |
|
|
|
|
((DesensitizedPreviewTableModel) model).getDesensitizeColumnsCount() : |
|
|
|
|
0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化centerPane |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private JComponent initCenterPane() { |
|
|
|
|
preveiwTable = new CopyableJTable(new TableSorter()); |
|
|
|
|
preveiwTable.setRowSelectionAllowed(false); |
|
|
|
|
preveiwTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
|
|
|
|
return new JScrollPane(preveiwTable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.add(new JScrollPane(preveiwTable), BorderLayout.CENTER); |
|
|
|
|
private void initDialog() { |
|
|
|
|
if (this.dialog == null) { |
|
|
|
|
this.dialog = this.showWindow(new JFrame()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initProgressBar() { |
|
|
|
|
progressBar = new AutoProgressBar(this, Toolkit.i18nText("Fine-Design_Basic_Loading_Data"), "", 0, 100) { |
|
|
|
|
@Override |
|
|
|
|
public void doMonitorCanceled() { |
|
|
|
|
if (getWorker() != null) { |
|
|
|
|
getWorker().cancel(true); |
|
|
|
@ -182,7 +290,7 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public AutoProgressBar getProgressBar() { |
|
|
|
|
return this.progressBar; |
|
|
|
|
return PreviewTablePane.progressBar; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -223,9 +331,10 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* elake:为预览表的columnIndex列着色. |
|
|
|
|
* @param columnIndex |
|
|
|
|
* @param c |
|
|
|
|
* 为预览表的columnIndex列着色. |
|
|
|
|
* |
|
|
|
|
* @param columnIndex 列索引值 |
|
|
|
|
* @param c 颜色 |
|
|
|
|
*/ |
|
|
|
|
private void setPreviewTableColumnColor(final int columnIndex, final Color c) { |
|
|
|
|
addLoadedListener(new LoadedEventListener() { |
|
|
|
@ -233,6 +342,7 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
public void fireLoaded() { |
|
|
|
|
TableColumn column = preveiwTable.getColumnModel().getColumn(columnIndex); |
|
|
|
|
DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer() { |
|
|
|
|
@Override |
|
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
|
|
|
|
JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
|
|
|
|
comp.setBackground(c); |
|
|
|
@ -253,7 +363,7 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
getInstance().preveiwTable = new SortableJTable(new TableSorter()); |
|
|
|
|
getInstance().preveiwTable.setRowSelectionAllowed(false); |
|
|
|
|
getInstance().preveiwTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
|
|
|
|
getInstance().progressBar.close(); |
|
|
|
|
PreviewTablePane.progressBar.close(); |
|
|
|
|
getInstance().repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -335,6 +445,7 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
|
|
|
|
|
private void previewTableDataSQL() throws Exception { |
|
|
|
|
connectionBar = new AutoProgressBar(this, Toolkit.i18nText("Fine-Design_Basic_Utils_Now_Create_Connection"), "", 0, 100) { |
|
|
|
|
@Override |
|
|
|
|
public void doMonitorCanceled() { |
|
|
|
|
getWorker().cancel(true); |
|
|
|
|
getDialog().setVisible(false); |
|
|
|
@ -349,42 +460,49 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
private void setPreviewTableColumnValue(final Graphics g) { |
|
|
|
|
for (int i = 0; i < preveiwTable.getColumnModel().getColumnCount(); i++) { |
|
|
|
|
TableColumn column = preveiwTable.getColumnModel().getColumn(i); |
|
|
|
|
DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer() { |
|
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
|
|
|
|
JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
|
|
|
|
Font f = table.getFont(); |
|
|
|
|
|
|
|
|
|
//默认在系统不支持 无法显示时 如自造的字 ,字体设置为空.
|
|
|
|
|
Font defaultShowFont = FRFont.getInstance("", f.getStyle(), f.getSize()); |
|
|
|
|
if (value instanceof String) { |
|
|
|
|
String str = (String) value; |
|
|
|
|
for (int j = 0; j < str.length(); j++) { |
|
|
|
|
char c = str.charAt(j); |
|
|
|
|
if (!f.canDisplay(c)) { |
|
|
|
|
table.setFont(defaultShowFont); |
|
|
|
|
} |
|
|
|
|
DefaultTableCellRenderer cellRenderer = getDefaultTableCellRenderer(); |
|
|
|
|
column.setCellRenderer(cellRenderer); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 默认表格格子渲染器 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private DefaultTableCellRenderer getDefaultTableCellRenderer() { |
|
|
|
|
return new DefaultTableCellRenderer() { |
|
|
|
|
@Override |
|
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
|
|
|
|
JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
|
|
|
|
Font f = table.getFont(); |
|
|
|
|
|
|
|
|
|
//默认在系统不支持 无法显示时 如自造的字 ,字体设置为空.
|
|
|
|
|
Font defaultShowFont = FRFont.getInstance("", f.getStyle(), f.getSize()); |
|
|
|
|
if (value instanceof String) { |
|
|
|
|
String str = (String) value; |
|
|
|
|
for (int j = 0; j < str.length(); j++) { |
|
|
|
|
char c = str.charAt(j); |
|
|
|
|
if (!f.canDisplay(c)) { |
|
|
|
|
table.setFont(defaultShowFont); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return comp; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
column.setCellRenderer(cellRenderer); |
|
|
|
|
} |
|
|
|
|
return comp; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setWorker() { |
|
|
|
|
|
|
|
|
|
worker = new SwingWorker<PreviewTableModel, Void>() { |
|
|
|
|
protected PreviewTableModel doInBackground() throws Exception { |
|
|
|
|
worker = new SwingWorker<TableModel, Void>() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected TableModel doInBackground() throws Exception { |
|
|
|
|
connectionBar.start(); |
|
|
|
|
try { |
|
|
|
|
if (tableData instanceof DBTableData) { |
|
|
|
|
boolean status = DataOperator.getInstance().testConnection(((DBTableData) tableData).getDatabase()); |
|
|
|
|
if (!status) { |
|
|
|
|
throw new Exception(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
testDBTableDataConnection(tableData); |
|
|
|
|
} finally { |
|
|
|
|
// 将close操作放到EDT线程中
|
|
|
|
|
UIUtil.invokeLaterIfNeeded(() -> connectionBar.close()); |
|
|
|
@ -394,22 +512,20 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
// parameterInputDialog
|
|
|
|
|
// update之后的parameters,转成一个parameterMap,用于预览TableData
|
|
|
|
|
PreviewTableModel previewModel = new PreviewTableModel(previewTableData.createDataModel(null), (int) maxPreviewNumberField.getValue()); |
|
|
|
|
for (int i = 0; i < previewTableData.getColumnCount(); i++) { |
|
|
|
|
Class<?> cls = previewTableData.getColumnClass(i); |
|
|
|
|
if (cls == Date.class || cls == TIME.class || cls == Timestamp.class) { |
|
|
|
|
previewModel.dateIndexs.add(i); |
|
|
|
|
} |
|
|
|
|
if (TableDataPreviewDesensitizeManager.getInstance().needDesensitize(tableData)) { |
|
|
|
|
// 数据集预览脱敏
|
|
|
|
|
previewModel = TableDataPreviewDesensitizeManager.getInstance().desensitizeTableModel(tableData, previewModel); |
|
|
|
|
} |
|
|
|
|
dealWithPreviewTableModelColumnClass(previewModel, previewTableData); |
|
|
|
|
return previewModel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void done() { |
|
|
|
|
try { |
|
|
|
|
PreviewTableModel model = get(); |
|
|
|
|
setModel(model); |
|
|
|
|
setCurrentRows(model.getRowCount()); |
|
|
|
|
TableModel model = get(); |
|
|
|
|
setPreviewTableModel(model); |
|
|
|
|
setPreviewTableColumnValue(getParent().getGraphics()); |
|
|
|
|
fireLoadedListener(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
if (!(e instanceof CancellationException)) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
@ -424,6 +540,36 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 检查DBTableData连接 |
|
|
|
|
* |
|
|
|
|
* @param tableData |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
private void testDBTableDataConnection(TableData tableData) throws Exception { |
|
|
|
|
if (tableData instanceof DBTableData) { |
|
|
|
|
boolean status = DataOperator.getInstance().testConnection(((DBTableData) tableData).getDatabase()); |
|
|
|
|
if (!status) { |
|
|
|
|
throw new Exception(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 处理预览Model的列类型 |
|
|
|
|
* |
|
|
|
|
* @param previewModel |
|
|
|
|
* @param previewTableData |
|
|
|
|
*/ |
|
|
|
|
private void dealWithPreviewTableModelColumnClass(PreviewTableModel previewModel, EmbeddedTableData previewTableData) { |
|
|
|
|
for (int i = 0; i < previewTableData.getColumnCount(); i++) { |
|
|
|
|
Class<?> cls = previewTableData.getColumnClass(i); |
|
|
|
|
if (cls == Date.class || cls == TIME.class || cls == Timestamp.class) { |
|
|
|
|
previewModel.dateIndexs.add(i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 直接预览存储过程的一个返回数据集,没有实际值和显示值 |
|
|
|
|
* |
|
|
|
@ -454,7 +600,7 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
/** |
|
|
|
|
* 直接预览数据集的结果集 |
|
|
|
|
* |
|
|
|
|
* @param dataModel 结果集 |
|
|
|
|
* @param dataModel 结果集 |
|
|
|
|
* @param keyIndex |
|
|
|
|
* @param valueIndex |
|
|
|
|
*/ |
|
|
|
@ -532,9 +678,62 @@ public class PreviewTablePane extends BasicPane {
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
previewModel = new PreviewTableModel((int) maxPreviewNumberField.getValue()); |
|
|
|
|
} |
|
|
|
|
setModel(previewModel); |
|
|
|
|
setCurrentRows(previewModel.getRowCount()); |
|
|
|
|
setPreviewTableModel(previewModel); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 切换TableModel的展示状态 |
|
|
|
|
*/ |
|
|
|
|
public void togglePreviewTableModelDesensitizeStatus() { |
|
|
|
|
if (!isDesensitizeOpened()) { |
|
|
|
|
// 未启用数据脱敏时,不需要切换
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
TableSorter tableSorter = (TableSorter) preveiwTable.getModel(); |
|
|
|
|
TableModel originTableModel = tableSorter.getTableModel(); |
|
|
|
|
if (originTableModel instanceof DesensitizedPreviewTableModel) { |
|
|
|
|
((DesensitizedPreviewTableModel) originTableModel).toggleNeedDesensite(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 刷新一下预览页面,用于切换脱敏和非脱敏时的显示 |
|
|
|
|
*/ |
|
|
|
|
public void refreshTable() { |
|
|
|
|
TableModel originTableModel = getCurrentTableModel(); |
|
|
|
|
setPreviewTableModel(originTableModel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当前的TableModel,已经除掉了TableSorter的包装 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private TableModel getCurrentTableModel() { |
|
|
|
|
TableSorter tableSorter = (TableSorter) preveiwTable.getModel(); |
|
|
|
|
return tableSorter.getTableModel(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置预览TableModel |
|
|
|
|
* |
|
|
|
|
* @param previewTableModel |
|
|
|
|
*/ |
|
|
|
|
private void setPreviewTableModel(TableModel previewTableModel) { |
|
|
|
|
setDesensitizationCount(previewTableModel); |
|
|
|
|
setModel(previewTableModel); |
|
|
|
|
setCurrentRows(previewTableModel.getRowCount()); |
|
|
|
|
fireLoadedListener(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 数据脱敏是否启用 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private boolean isDesensitizeOpened() { |
|
|
|
|
return tableData instanceof DesensitizationTableData && |
|
|
|
|
((DesensitizationTableData) tableData).getDesensitizationConfig().isDesensitizeOpened(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|