diff --git a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java index fa1fe545ed..b3c090d549 100644 --- a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java @@ -378,12 +378,8 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp protected boolean isDsNameRepeaded(String name) { allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook()); - for (int i = 0; i < allDSNames.length; i++) { - if (ComparatorUtils.equals(name, allDSNames[i])) { - return true; - } - } - return false; + Set allDSNamesWithoutPermissions = DesignTableDataManager.getAllDSNamesWithoutPermissions(tc.getBook()); + return allDSNamesWithoutPermissions.contains(name); } protected KeyAdapter getTableTreeNodeListener(final UpdateAction editAction, final UpdateAction previewTableDataAction, final UpdateAction removeAction, final TableDataSourceOP op, final TableDataTree dataTree) { diff --git a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java index 2ce2a7d828..5134e88c8b 100644 --- a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java +++ b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java @@ -48,6 +48,7 @@ import java.text.Collator; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -295,6 +296,27 @@ public abstract class DesignTableDataManager { return list.toArray(new String[0]); } + /** + * 获取所有的数据集名称,无论模板是不是有数据集的权限 + */ + public static Set getAllDSNamesWithoutPermissions(TableDataSource source) { + Set names = new HashSet<>(); + Map resMap = new HashMap<>(); + // 模板数据集 + addTemplateData(resMap, source); + // 存储过程 + addStoreProcedureData(resMap); + for (Map.Entry entry : resMap.entrySet()) { + names.add(entry.getKey()); + } + //服务器数据集 + Map tableDatas = TableDataConfig.getInstance().getTableDatas(); + for (Map.Entry entry : tableDatas.entrySet()) { + names.add(entry.getKey()); + } + return names; + } + /** * 不根据过滤设置,返回当前模板数据集、服务器数据集、存储过程本身,是有顺序的 */ @@ -661,4 +683,14 @@ public abstract class DesignTableDataManager { public static void setThreadLocal(String value) { threadLocal.set(value); } -} \ No newline at end of file + + /** + * 根据数据集名称判断是否为服务器数据集或服务器存储过程 + * + * @param tableDataName 数据集名称 + * @return + */ + public static boolean isGlobalTableData(String tableDataName) { + return globalDsCache.containsKey(tableDataName); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java index 23c22144b5..f836757399 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java @@ -21,6 +21,9 @@ import com.fr.event.EventDispatcher; import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionOperator; import com.fr.general.NameObject; +import com.fr.license.database.BaseDataBaseTypePoint; +import com.fr.license.database.DBTypes; +import com.fr.license.exception.DataBaseNotSupportedException; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; @@ -29,17 +32,22 @@ import com.fr.stable.core.PropertyChangeAdapter; import com.fr.transaction.Configurations; import com.fr.transaction.WorkerFacade; import com.fr.workspace.WorkContext; +import com.fr.workspace.server.database.DataBaseTypeOperator; +import org.jetbrains.annotations.NotNull; +import javax.swing.SwingWorker; import java.awt.Window; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ExecutionException; /** * Connection List Pane. @@ -49,6 +57,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh private boolean isNamePermitted = true; private final HashMap renameMap = new HashMap<>(); private final Map populatedConnectionsSnapshot = new LinkedHashMap<>(); + private static List supportedDatabaseTypes = new ArrayList<>(); public ConnectionListPane() { renameMap.clear(); @@ -62,6 +71,30 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh rename(selectedName, getEditingName()); } }); + + getSupportedTypes(); + } + + /** + * 获取本地、远程环境lic中未受限制的数据库类型信息 + */ + private static void getSupportedTypes() { + SwingWorker, Void> getSupportedTypesWorker = new SwingWorker, Void>() { + @Override + protected List doInBackground() { + return WorkContext.getCurrent().get(DataBaseTypeOperator.class).getSupportedDatabaseTypes(); + } + + @Override + protected void done() { + try { + supportedDatabaseTypes = get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + }; + getSupportedTypesWorker.execute(); } @Override @@ -114,21 +147,31 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh /** * 创建菜单项 + *

+ * 方法中获取limitDatabaseType使用了远程rpc调用,可能会比较耗时 * * @return 菜单项 */ public NameableCreator[] createNameableCreators() { - NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( + NameObjectCreator jdbc = new NameObjectCreator( "JDBC", "/com/fr/design/images/data/source/jdbcTableData.png", JDBCDatabaseConnection.class, DatabaseConnectionPane.JDBC.class - ), new NameObjectCreator( + ); + NameObjectCreator jndi = new NameObjectCreator( "JNDI", "/com/fr/design/images/data/source/jdbcTableData.png", JNDIDatabaseConnection.class, DatabaseConnectionPane.JNDI.class - )}; + ); + NameableCreator[] creators; + if (WorkContext.getCurrent().get(DataBaseTypeOperator.class).limitDatabaseType()) { + // 不支持JNDI,屏蔽接口 + creators = new NameableCreator[]{jdbc}; + } else { + creators = new NameableCreator[]{jdbc, jndi}; + } Set pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); for (ConnectionProvider provider : pluginCreators) { NameObjectCreator creator = new NameObjectCreator( @@ -221,10 +264,56 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } }); + this.validateDatabaseType(addedOrUpdatedConnections); this.validateConnections(addedOrUpdatedConnections); this.alterConnections(removedConnNames, addedOrUpdatedConnections); } + /** + * 校验是否支持所有新增和修改数据连接的数据库类型 + */ + public void validateDatabaseType(@NotNull List addedOrUpdatedConnections) { + Set notSupportedConnections = new HashSet<>(); + if (!addedOrUpdatedConnections.isEmpty()) { + for (ConnectionBean bean : addedOrUpdatedConnections) { + Connection connection = bean.getConnection(); + // 仅校验jdbc连接,其他插件数据连接不进行校验 + if (connection instanceof JDBCDatabaseConnection) { + BaseDataBaseTypePoint dataBaseTypePoint = BaseDataBaseTypePoint.getDataBaseTypePoint(connection.getDriver(), connection.feature()); + + if (connectionIsNotSupported(connection, dataBaseTypePoint)) { + notSupportedConnections.addAll(dataBaseTypePoint.getDataBaseType()); + } + } + } + } + + if (!notSupportedConnections.isEmpty()) { + throw new DataBaseNotSupportedException(notSupportedConnections, supportedDatabaseTypes); + } + } + + /** + * 校验当前数据连接是否被限制 + */ + private static boolean connectionIsNotSupported(Connection connection, BaseDataBaseTypePoint dataBaseTypePoint) { + return !validateFRDemo(connection.getDriver(), connection.feature()) && + (dataBaseTypePoint != null && !supportedDatabaseTypes.containsAll(dataBaseTypePoint.getDatabaseType())); + } + + /** + * 校验当前是否为FRDemo,不对其进行限制 + */ + private static boolean validateFRDemo(String driver, String url) { + if (DBTypes.Sqlite.getDriver().equals(driver) && url.contains(DBTypes.Sqlite.getUrlKey())) { + // 产品:对sqlite类型只允许示例连接FRDemo + String databaseName = url.substring(url.lastIndexOf("/") + 1); + return StringUtils.equals("FRDemo.db", databaseName); + } + + return false; + } + private void validateConnections(List addedOrUpdatedConnections) throws Exception { diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java index 33925dcd36..eadf456e09 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java @@ -4,7 +4,6 @@ import com.fr.design.gui.frpane.LoadingBasicPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.file.ConnectionConfig; - import javax.swing.JPanel; import java.awt.BorderLayout; import java.util.HashMap; 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 027afdf5b2..ffac1388c6 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 @@ -33,6 +33,7 @@ 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.esd.query.StrategicTableData; import com.fr.function.TIME; import com.fr.general.FRFont; import com.fr.general.data.DataModel; @@ -162,10 +163,8 @@ public class PreviewTablePane extends BasicPane { JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); // 预览行数面板 northPane.add(initPreviewNumberPane(), BorderLayout.CENTER); - /// 迭代延期,暂时屏蔽下功能入口 // 脱敏预览设置面板 -// northPane.add(initDesensitizationPane(), BorderLayout.EAST); - initDesensitizationPane(); + northPane.add(initDesensitizationPane(), BorderLayout.EAST); return northPane; } @@ -225,6 +224,18 @@ public class PreviewTablePane extends BasicPane { * 点击脱敏配置后的操作 */ public void clickDesensitizationLabel() { + // 埋点记录 + recordDesensitization(); + // 判断数据集类型 + if (isGlobalTableData()) { + // 服务器数据集不允许在设计器端修改脱敏配置 + FineJOptionPane.showMessageDialog( + this, + Toolkit.i18nText("Fine-Design_Report_Cannot_Modify_Desensitization_Config_Of_ServerTableData"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + FineJOptionPane.WARNING_MESSAGE); + return; + } TableDataDesensitizationSettingPane settingPane = new TableDataDesensitizationSettingPane((DesensitizationTableData) tableData); settingPane.populateBean((DesensitizationTableData) tableData); BasicDialog dialog = settingPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(PreviewTablePane.this), new DialogActionAdapter() { @@ -250,15 +261,41 @@ public class PreviewTablePane extends BasicPane { } /** - * 设置脱敏设置的个数 + * 触发数据脱敏埋点记录 + * + * @return 数据脱敏字段数量 + */ + private int recordDesensitization() { + return getCurrentTableDataDesensitizationCount(); + } + + /** + * 当前tableData是否为服务器数据集或服务器存储过程 + * + * @return + */ + public boolean isGlobalTableData() { + return this.tableData instanceof StrategicTableData && + DesignTableDataManager.isGlobalTableData(((StrategicTableData) this.tableData).getDsName()); + } + + /** + * 根据TableData设置脱敏设置的个数 + */ + private void setDesensitizationCountByTableData() { + desensitizationPane.setDesensitizationCount(isDesensitizeOpened(), getCurrentTableDataDesensitizationCount()); + desensitizationPane.dealWithTableDataType(isGlobalTableData()); + } + + /** + * 获取当前数据集中设置脱敏规则的个数 * - * @param model + * @return */ - private void setDesensitizationCount(TableModel model) { - desensitizationPane.setDesensitizationCount(isDesensitizeOpened(), - model instanceof DesensitizedPreviewTableModel ? - ((DesensitizedPreviewTableModel) model).getDesensitizeColumnsCount() : - 0); + private int getCurrentTableDataDesensitizationCount() { + return this.tableData instanceof DesensitizationTableData ? + ((DesensitizationTableData) this.tableData).getDesensitizationConfig().getDesensitizationItems().size() : + 0; } /** @@ -723,7 +760,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..abd5a4d166 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 @@ -2,6 +2,8 @@ package com.fr.design.data.datapane.preview.desensitization; import com.fr.base.TableData; +import com.fr.data.TableDataSource; +import com.fr.data.desensitize.TableDataDesensitizeManager; import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.TableDataDesensitizationItem; import com.fr.data.desensitize.manage.DesensitizationManager; @@ -14,11 +16,14 @@ import com.fr.decision.webservice.v10.user.PositionService; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.datapane.preview.PreviewTableModel; import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel; +import com.fr.esd.query.StrategicTableData; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; @@ -77,10 +82,11 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage // 获取此数据集的所有脱敏信息 Collection desensitizationItems = ((DesensitizationTableData) tableData).getDesensitizationConfig().getDesensitizationItems(); if (DesentizationUtils.isCollectionNotEmpty(desensitizationItems)) { - // 先对脱敏配置项集合做过滤和排序处理 + // 更新规则 + desensitizationItems = TableDataDesensitizeManager.getInstance().dealWithlatestRules(desensitizationItems); + // 对脱敏配置项集合做过滤和排序处理 List items = desensitizationItems.stream() - .filter(item -> item.getRule().isEnable() && - matchColumnIndex(item, model) >= 0) + .filter(item -> isAvaliableItem4Preview(item, model)) .sorted(Comparator.comparingInt(item -> matchColumnIndex(item, model))) .collect(Collectors.toList()); // 然后转换成Map @@ -93,88 +99,29 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage } /** - * 通过TableData获取其列名 - * 实现逻辑有点绕,TableData本身并不能返回列名集合,只能先去获取当前模板所有数据集,然后匹配名称拿到TableDataWrapper再获取列名 + * 判断是否为有效的用于预览脱敏效果的DesensitizationItem * - * @param tableData + * @param item 脱敏配置项 + * @param model 数据集预览数据 * @return */ - public List getColumnNamesByTableData(TableData tableData) { - return DesignTableDataManager.getColumnNamesByTableData(tableData); + private boolean isAvaliableItem4Preview(TableDataDesensitizationItem item, PreviewTableModel model) { + return item.getRule().isEnable() && + matchColumnIndex(item, model) >= 0; } /** - * 这个api会返回 部门职位 + 自定义角色 的Map - * 其中 key为 "pid" + "_" + "id",value为 "ptext" + "text" + * 通过TableData获取其列名,理论上一定存在缓存值 * + * @param tableData * @return */ - public Map getAllRoles() { - Map rolesMap = new LinkedHashMap<>(); - // 处理部门职位相关的用户组 - addDepartmentAndPositionRoles2Map(rolesMap); - // 处理自定义角色相关的用户组 - addCustomRoles2Map(rolesMap); - return rolesMap; - } - - /** - * 获取所有的部门职位,按照 key为 "pid" + "_" + "id",value为 "ptext" + "text"的格式添加到参数Map中 - * - * @param rolesMap - */ - private void addDepartmentAndPositionRoles2Map(Map rolesMap) { - try { - List postBeans = PositionService.getInstance().getDepartmentPostNameList(); - for (DepartmentPostBean postBean : postBeans) { - String department = postBean.getpText(); - String position = postBean.getText(); - String departmentId = postBean.getpId(); - String positionId = postBean.getId(); - if (!ComparatorUtils.equals(DecisionServiceConstants.DECISION_DEP_ROOT, postBean.getId()) && StringUtils.isNotEmpty(position)) { - // 只添加部门和职位同时存在的 - rolesMap.put(mergeRoleId(departmentId, positionId), mergeRoleText(department, position)); - } - } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e, "[Desensitization] failed to add department and position roles to map for {}", e.getMessage()); - } - } - - /** - * 获取所有的自定义角色,按照 id - name添加到参数map里 - * - * @param rolesMap - */ - private void addCustomRoles2Map(Map rolesMap) { - try { - List allCustomRole = CustomRoleService.getInstance().getAllCustomRoleNameList(null); - allCustomRole.forEach(roleBean -> rolesMap.put(roleBean.getId(), roleBean.getText())); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e, "[Desensitization] failed to add custom role to map for {}", e.getMessage()); + public List getColumnNamesByTableData(TableData tableData) { + TableDataSource editingTableDataSource = DesignTableDataManager.getEditingTableDataSource(); + if (editingTableDataSource != null && tableData instanceof StrategicTableData) { + return Arrays.asList(DesignTableDataManager.getSelectedColumnNames(editingTableDataSource, ((StrategicTableData) tableData).getDsName())); } - } - - /** - * 合并部门 + 职位的名称 - * - * @param departmentName - * @param positionName - * @return - */ - public String mergeRoleText(String departmentName, String positionName) { - return departmentName + positionName; - } - - /** - * 合并部门 + 职位的id - * - * @param departmentId - * @param positionId - * @return - */ - public String mergeRoleId(String departmentId, String positionId) { - return departmentId + CONNECTOR + positionId; + return Collections.EMPTY_LIST; } /** diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java index 1bf150dd51..01c92e333f 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java @@ -112,9 +112,22 @@ public class PreviewTableDesensitizationPane extends JPanel { return previewToggle; } + /** + * 设置Label的值,主要是需要动态修改配置的脱敏规则的数量 + * + * @param desensitizeOpen + * @param count + */ public void setDesensitizationCount(boolean desensitizeOpen, int count) { desensitizationLabel.setText(desensitizeOpen ? DATA_DESENSITIZATION_CONFIG + LEFT_BRACKET + count + RIGHT_BRACKET + COUNT : DATA_DESENSITIZATION_CONFIG); } + + /** + * 服务器数据集时,Label需要置灰 + */ + public void dealWithTableDataType(boolean globalTableData) { + desensitizationLabel.setForeground(globalTableData ? UIConstants.DISABLED_ICON_COLOR : UIConstants.NORMAL_BLUE); + } } 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..11e30a2e9f 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,10 +23,12 @@ 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; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -46,7 +49,10 @@ public class DesensitizationRuleChoosePane extends JPanel { private DesensitizationRuleSource currentRuleSource; - public DesensitizationRuleChoosePane() { + private Map> latestRules; + + public DesensitizationRuleChoosePane(Map> latestRules) { + this.latestRules = latestRules; this.cardLayout = new CardLayout(); this.setLayout(cardLayout); serverRuleEditPane = new UITableEditorPane<>(new DesensitizationRuleChooseTableModel(this, true)); @@ -74,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(latestRules.get(DesensitizationRuleSource.SERVER).values().toArray(new DesensitizationRule[0])); + customRuleEditPane.populate(latestRules.get(DesensitizationRuleSource.CUSTOM).values().toArray(new DesensitizationRule[0])); } /** @@ -107,18 +113,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 +145,11 @@ public class DesensitizationRuleChoosePane extends JPanel { case 2: // 脱敏规则描述 return DesensitizationRule.getDescription(rule); + case 3: + // 脱敏规则状态 + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules); + // 非正常状态需要标记为异常 + return ruleStatus == DesensitizationRuleStatus.NORMAL ? StringUtils.EMPTY : Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal"); default: return StringUtils.EMPTY; } @@ -161,29 +177,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 UILabel ruleStatusLabel; - private UIRadioButton selectedButton; + DesensitizationRuleStatusPane() { + // 规则状态 + this.ruleStatusLabel = new UILabel(); + this.ruleStatusLabel.setForeground(Color.RED); + } - public RuleChoosePane() { - this.selectedButton = new UIRadioButton(); + /** + * 根据脱敏规则信息,刷新规则状态,主要用于与规则选择器的联动 + * + * @param rule + */ + public void refreshRuleStatus(DesensitizationRule rule) { + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules); + 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; } } @@ -237,18 +275,25 @@ public class DesensitizationRuleChoosePane extends JPanel { @Override public void actionPerformed(ActionEvent e) { - // 获取当前选中规则 - DesensitizationRule selectedValue = getSelectedValue(); + // 获取当前选中规则的副本 + DesensitizationRule selectedValue = null; + try { + selectedValue = (DesensitizationRule) getSelectedValue().clone(); + } catch (CloneNotSupportedException ex) { + throw new RuntimeException(ex); + } DesensitizationRuleEditPane editPane = new DesensitizationRuleEditPane(getCurrentExistRuleNames(selectedValue.getRuleName())); editPane.populateBean(selectedValue); + final DesensitizationRule finalRule = selectedValue; BasicDialog basicDialog = editPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() { @Override public void doOk() { DesensitizationRule rule = editPane.updateBean(); // 修改同步到RuleManager中 if (DesensitizationRule.valid(rule)) { - DesensitizationRuleManager.getInstance().updateRule(rule); + DesensitizationRuleManager.getInstance().updateRule(finalRule, rule); } + setSelectedValue(rule); fireTableDataChanged(); } @@ -298,7 +343,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/rule/DesensitizationRuleEditPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java index 7354dc0b11..5a0515a59e 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java @@ -2,6 +2,7 @@ package com.fr.design.data.datapane.preview.desensitization.view.rule; import com.fr.data.desensitize.rule.base.DesensitizationCondition; import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; import com.fr.data.desensitize.rule.base.DesensitizationRuleType; import com.fr.design.beans.BasicBeanPane; import com.fr.design.constants.UIConstants; @@ -158,15 +159,15 @@ public class DesensitizationRuleEditPane extends BasicBeanPane */ private DesensitizationRuleChoosePane ruleChoosePane; + /** + * 最新的所有规则 + */ + private Map> latestRules; + /** * 内容面板 */ private JPanel contentPane; - public DesensitizationRulePane() { + public DesensitizationRulePane(Map> latestRules) { this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.latestRules = latestRules; initPane(); } @@ -47,7 +54,7 @@ public class DesensitizationRulePane extends BasicBeanPane // 规则来源选择Pane ruleSourceChoosePane = new DesensitizationRuleSourceChoosePane(this); // 规则选择Pane - ruleChoosePane = new DesensitizationRuleChoosePane(); + ruleChoosePane = new DesensitizationRuleChoosePane(latestRules); 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 bbc91efa2a..52b7e5b19b 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,8 +2,10 @@ 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.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; +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.rule.DesensitizationRulePane; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; @@ -15,12 +17,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,12 +32,16 @@ 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.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -52,39 +60,46 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter columnNames; + private List columnNames = new ArrayList<>(); /** * key为用户组唯一标识(id拼接),value为用户组名称 */ - private Map roleMap; + private Map roleMap = new LinkedHashMap<>(); - private Component parent; - - private DesensitizationRuleChooser ruleChooser; + /** + * 当前最新的所有规则 + */ + private Map> latestRules = new LinkedHashMap<>(); - private DesensitizationRuleDescriptionPane descriptionPane; + private Component parent; - public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent) { + public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent, List columnNames, Map roleMap, Map> latestRules) { // table相关 super(new String[]{ Toolkit.i18nText("Fine-Design_Report_Desensitization_Column"), Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule"), - StringUtils.EMPTY, - Toolkit.i18nText("Fine-Design_Report_Desensitization_Effected_Roles") + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Description"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Effected_Roles"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"), }); - // 一些数据相关 - this.tableData = tableData; - // 获取当前数据集的所有列名 - this.columnNames = TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData); - // 获取当前所有用户组 - this.roleMap = TableDataPreviewDesensitizeManager.getInstance().getAllRoles(); this.parent = parent; + this.columnNames = columnNames; + this.roleMap = roleMap; + this.latestRules = latestRules; + + initTable(); + } + + /** + * 初始化Table + */ + private void initTable() { this.setColumnClass(new Class[]{ // 列名选择 ColumnNamesComboBox.class, @@ -93,62 +108,77 @@ 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 public UITableEditAction[] createAction() { - return new UITableEditAction[]{new AddDesensitizationAction(), new RemoveDesensitizationAction(parent)}; + return new UITableEditAction[]{ + new AddDesensitizationAction(), + new RemoveDesensitizationAction(parent), + new RefreshTableAction(), + }; } /** @@ -166,7 +196,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter items = getList(); + Iterator iterator = items.iterator(); + while (iterator.hasNext()) { + TableDataDesensitizationItem item = iterator.next(); + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule(), latestRules); + if (ruleStatus == DesensitizationRuleStatus.REMOVED) { + // 规则被移除,则删除整条脱敏Item + iterator.remove(); + } else { + // 规则被修改、禁用等,更新一下规则 + item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule(), latestRules)); + } + } + fireTableDataChanged(); + } + + @Override + public void checkEnabled() {} + } + + /** + * 规则表-列字段编号 + */ + private enum TableSequences { + + /** + * 数据集列名选择 + */ + ColumnName(0), + + /** + * 规则选择 + */ + DesensitizationRule(1), + + /** + * 规则描述 + */ + DesensitizationRuleDescription(2), + + /** + * 规则生效用户组 + */ + EffectedRoles(3), + + /** + * 规则状态 + */ + DesensitizationRuleStatus(4), + + /** + * 未知,用于无法匹配时的返回 + */ + Unknown(100); + + + private int num; + + TableSequences(int num) { + this.num = num; + } + + public int getNum() { + return num; + } + + /** + * 根据列序号匹配列字段 + * + * @param num + * @return + */ + public static TableSequences match(int num) { + for (TableSequences value : TableSequences.values()) { + if (value.getNum() == num) { + return value; + } + } + return Unknown; + } + } + + /** + * 是否需要对异常规则做标记,需要满足 + * 1. 规则非默认空规则 + * 2. 规则本身异常 + * + * @return + */ + private boolean needMarkRule(DesensitizationRule rule) { + return !rule.equals(DesensitizationRule.createDefaultEmptyRule()) && + DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules) != DesensitizationRuleStatus.NORMAL; + } + + /** + * 刷新当前页面的本地规则缓存,查询最新本地规则的逻辑也是使用了缓存,因此无需考虑耗时 + */ + private void refreshCustomRuleCache() { + Map customRules = DesensitizationRuleManager.getInstance().getRulesBySource(DesensitizationRuleSource.CUSTOM); + latestRules.put(DesensitizationRuleSource.CUSTOM, customRules); + } + } 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..6473a02d07 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 @@ -1,14 +1,28 @@ package com.fr.design.data.datapane.preview.desensitization.view.setting; +import com.fr.base.operator.org.OrganizationOperator; 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 com.fr.workspace.WorkContext; 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 +48,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 +64,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> latestRules = new LinkedHashMap<>(); + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + // 获取当前数据集的所有列名 + columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData)); + // 获取当前所有用户组 + roleMap.putAll(WorkContext.getCurrent().get(OrganizationOperator.class).getAllRoles4Desensitization()); + // 获取当前最新的所有规则 + latestRules.putAll(DesensitizationRuleManager.getInstance().getAllRules()); + return null; + } + + @Override + protected void done() { + contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + editorPane = new UITableEditorPane<>(new TableDataDesensitizationTableModel(tableData, parent, columnNames, roleMap, latestRules)); + 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 +132,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()); } } diff --git a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java index feb1e696fd..1bcfe3c622 100644 --- a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java +++ b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java @@ -28,6 +28,7 @@ import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.collections.CollectionUtils; import com.fr.stable.project.ProjectConstants; +import com.fr.workspace.WorkContext; import javax.swing.BorderFactory; import javax.swing.JDialog; @@ -229,7 +230,13 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi } //确定目标目录并检查权限 FileOperations selectedOperation = DesignerFrameFileDealerPane.getInstance().getSelectedOperation(); - if (!selectedOperation.access()) { + boolean rootAuthority = true; + if (selectedOperation.getFileNode() == null && selectedOperation instanceof TemplateTreePane) { + //没有选中文件节点时,默认粘贴到根目录下,所以直接检测根目录是否有权限 + ExpandMutableTreeNode root = (ExpandMutableTreeNode) ((TemplateTreePane) selectedOperation).getTemplateFileTree().getModel().getRoot(); + rootAuthority = root.hasFullAuthority(); + } + if (!rootAuthority && !selectedOperation.access()) { FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"), Toolkit.i18nText("Fine-Design_Basic_Alert"), diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java index 18abbb7e28..d985595f5f 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java @@ -307,10 +307,11 @@ public class TemplateTreePane extends JPanel implements FileOperations { if (reportletsTree.getSelectionCount() == 0) { //没选中文件刷新根目录 reportletsTree.refresh(); + return; } reportletsTree.refreshParent(Objects.requireNonNull(reportletsTree.getSelectionPath())); DesignerFrameFileDealerPane.getInstance().refreshRightToolBarBy(null); - FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_File_Tree_Refresh_Successfully") + "!"); + FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_File_Tree_Refresh_Successfully")); } diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java index 3eed2d799d..80e7e88bbf 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java @@ -37,6 +37,10 @@ public class UICheckListPopup extends UIPopupMenu { private Color mouseEnteredColor = UIConstants.CHECKBOX_HOVER_SELECTED; private int maxDisplayNumber = 8; private boolean supportSelectAll = true; + /** + * 每项数据都有可能因为宽度设置问题,而被省略显示,这个常量代表,是否要给每项数据添加一个值等于其原值的Tooltips + */ + private boolean labelNeedToolTips = false; public static final String COMMIT_EVENT = "commit"; private static final String SELECT_ALL = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Choose_All"); @@ -47,9 +51,14 @@ public class UICheckListPopup extends UIPopupMenu { } public UICheckListPopup(Object[] value, boolean supportSelectAll) { + this(value, supportSelectAll, false); + } + + public UICheckListPopup(Object[] values, boolean supportSelectAll, boolean labelNeedToolTips) { super(); - values = value; + this.values = values; this.supportSelectAll = supportSelectAll; + this.labelNeedToolTips = labelNeedToolTips; initComponent(); } @@ -62,6 +71,11 @@ public class UICheckListPopup extends UIPopupMenu { addCheckboxValues(); } + public UICheckListPopup setLabelNeedToolTips(boolean labelNeedToolTips) { + this.labelNeedToolTips = labelNeedToolTips; + return this; + } + private void initComponent() { checkboxPane = new JPanel(); checkboxPane.setLayout(new GridLayout(checkBoxList.size(), 1, 0, 0)); @@ -111,6 +125,10 @@ public class UICheckListPopup extends UIPopupMenu { checkPane.setBackground(Color.WHITE); checkPane.add(temp); checkPane.add(label); + if (labelNeedToolTips) { + // 设置每项Label的tooltips为其省略前的内容 + label.setToolTipText(checkValue.toString()); + } addMouseListener(temp, label); checkBoxList.add(temp); diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java index 4dcea229ce..ce0a9f869e 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java @@ -17,9 +17,6 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -32,6 +29,9 @@ import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * 设计器下拉复选框组件 @@ -52,7 +52,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam //选中的值之间显示的分隔符 private String valueSperator; private static final String DEFAULT_VALUE_SPERATOR = ","; - private static final String OMIT_TEXT = "..."; + protected static final String OMIT_TEXT = "..."; private UIObserverListener uiObserverListener; private GlobalNameListener globalNameListener = null; @@ -60,6 +60,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam private boolean showOmitText = true; private boolean supportSelectAll = true; + private String placeHolder = StringUtils.EMPTY; public UIComboCheckBox(Object[] value) { this(value, DEFAULT_VALUE_SPERATOR, true); @@ -112,14 +113,42 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam } private void initComponent() { - this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); this.popup = new UICheckListPopup(values, supportSelectAll); this.popup.addActionListener(new PopupAction()); this.editor = createEditor(); this.arrowButton = createArrowButton(); + setLayoutAndAddComponents(); + setText(); + } + + /** + * 设置布局管理器并且添加组件 + * 默认使用FlowLayout + */ + protected void setLayoutAndAddComponents() { + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); this.add(editor); this.add(arrowButton); - setText(); + } + + public UICheckListPopup getPopup() { + return popup; + } + + public UITextField getEditor() { + return editor; + } + + public String getPlaceHolder() { + return placeHolder; + } + + public void setPlaceHolder(String placeHolder) { + this.placeHolder = placeHolder; + } + + public UIButton getArrowButton() { + return arrowButton; } private UIButton createArrowButton() { @@ -171,6 +200,9 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { attributeChange(); + if (uiObserverListener != null) { + uiObserverListener.doChange(); + } } @Override @@ -270,6 +302,28 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam String text = builder.length() > 0 ? builder.substring(0, builder.length() - 1) : StringUtils.EMPTY; //计算加省略号后的文本 editor.setText(this.showOmitText ? omitEditorText(editor, text) : text); + // 添加placeHolder + setEditorPlaceHolder(editor); + // tooltips显示原值 + setEditorToolTipText(editor, text); + } + + /** + * 为为添加placeholder + * @param editor + */ + protected void setEditorPlaceHolder(UITextField editor) { + // 默认空实现 + } + + /** + * 为UITextField设置悬浮提示值 + * + * @param editor + * @param text + */ + protected void setEditorToolTipText(JComponent editor, String text) { + // 默认不做设置 } /** @@ -279,7 +333,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam * @param text * @return 省略后的文字 */ - private static String omitEditorText(UITextField textEditor, String text) { + protected String omitEditorText(UITextField textEditor, String text) { char[] omitChars = OMIT_TEXT.toCharArray(); //获取字体的大小 FontMetrics fontMetrics = textEditor.getFontMetrics(textEditor.getFont()); diff --git a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java index 07756a56b7..aca38b28d2 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java @@ -8,10 +8,12 @@ import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; - -import javax.swing.*; +import javax.swing.JPanel; +import javax.swing.JTable; import javax.swing.event.TableModelListener; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.Insets; import java.util.List; /** @@ -31,25 +33,25 @@ public class UITableEditorPane extends BasicPane { private String leftLabelName; private JPanel buttonPane; - public UITableEditorPane(UITableModelAdapter model) { - this.tableModel = model; - this.initComponent(model.createAction()); - } + public UITableEditorPane(UITableModelAdapter model) { + this.tableModel = model; + this.initComponent(model.createAction()); + } - public UITableEditorPane(UITableModelAdapter model, String s) { - leftLabelName = s; - this.tableModel = model; - this.initComponent(model.createAction()); - } + public UITableEditorPane(UITableModelAdapter model, String s) { + leftLabelName = s; + this.tableModel = model; + this.initComponent(model.createAction()); + } - private void initComponent(UITableEditAction[] action) { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - JPanel pane = new JPanel(new BorderLayout(4, 4)); - this.add(pane, BorderLayout.CENTER); + protected void initComponent(UITableEditAction[] action) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + JPanel pane = new JPanel(new BorderLayout(4, 4)); + this.add(pane, BorderLayout.CENTER); - UILabel l = new UILabel(leftLabelName); - editTable = tableModel.createTable(); - editTable.getTableHeader().setBackground(UIConstants.DEFAULT_BG_RULER); + UILabel l = new UILabel(leftLabelName); + editTable = tableModel.createTable(); + editTable.getTableHeader().setBackground(UIConstants.DEFAULT_BG_RULER); UIScrollPane scrollPane = new UIScrollPane(editTable); scrollPane.setBorder(new UIRoundedBorder(UIConstants.TITLED_BORDER_COLOR, 1, UIConstants.ARC)); @@ -62,11 +64,11 @@ public class UITableEditorPane extends BasicPane { } - public UITableModelAdapter getTableModel(){ + public UITableModelAdapter getTableModel() { return tableModel; } - private void initbuttonPane(UITableEditAction[] action) { + protected void initbuttonPane(UITableEditAction[] action) { buttonPane = new JPanel(); if (action != null) { @@ -146,6 +148,14 @@ public class UITableEditorPane extends BasicPane { return buttonPane; } + public JTable getEditTable() { + return editTable; + } + + public void setEditTable(JTable editTable) { + this.editTable = editTable; + } + /** * 停止编辑 */ @@ -157,7 +167,7 @@ public class UITableEditorPane extends BasicPane { /** * 设置表头是否可以改变大小 */ - public void setHeaderResizing(boolean resizingAllowed){ + public void setHeaderResizing(boolean resizingAllowed) { editTable.getTableHeader().setResizingAllowed(resizingAllowed); } diff --git a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java index 4506bb9a6c..87e21c75be 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java +++ b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java @@ -219,57 +219,69 @@ public abstract class UITableModelAdapter extends AbstractTableModel implemen protected class DeleteAction extends UITableEditAction { private Component component = null; + // 删除时界面显示的提示语,可自定义 + private String deleteTipText; public DeleteAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); - } - + this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); + this.setDeleteTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + "?"); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); + } + public DeleteAction(Component component){ - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); + this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); + this.setDeleteTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + "?"); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); this.component = component; } @Override public void actionPerformed(ActionEvent e) { - int[] selectedRow = table.getSelectedRows(); - if (ismultiSelected()) { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Multiple_Select_Warn_Text")); - return; - } - if (table.getCellEditor() != null) { - try { - table.getCellEditor().stopCellEditing(); - } catch (Exception ee) { + int[] selectedRow = table.getSelectedRows(); + if (ismultiSelected()) { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Multiple_Select_Warn_Text")); + return; + } + if (table.getCellEditor() != null) { + try { + table.getCellEditor().stopCellEditing(); + } catch (Exception ee) { FineLoggerFactory.getLogger().error(ee.getMessage(), ee); - } - } - if (getRowCount() < 1) { - return; - } - - if(component == null){ - component = DesignerContext.getDesignerFrame(); - } - int val = FineJOptionPane.showConfirmDialog(component, - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + "?", com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"), - JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); - if (val != JOptionPane.OK_OPTION) { - return; - } - for (int i = 0; i < selectedRow.length; i++) { - if (selectedRow[i] - i < 0) { - continue; - } - removeRow(selectedRow[i] - i); - } - fireTableDataChanged(); - int selection = selectedRow[0] > table.getRowCount() ? table.getRowCount() - 1 - : (selectedRow[0] > 1 ? selectedRow[0] - 1 : 0); - table.getSelectionModel().setSelectionInterval(selection, selection); - } + } + } + if (getRowCount() < 1) { + return; + } + + if (component == null) { + component = DesignerContext.getDesignerFrame(); + } + int val = FineJOptionPane.showConfirmDialog(component, getDeleteTipText() + , com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"), + JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); + if (val != JOptionPane.OK_OPTION) { + return; + } + for (int i = 0; i < selectedRow.length; i++) { + if (selectedRow[i] - i < 0) { + continue; + } + removeRow(selectedRow[i] - i); + } + fireTableDataChanged(); + int selection = selectedRow[0] > table.getRowCount() ? table.getRowCount() - 1 + : (selectedRow[0] > 1 ? selectedRow[0] - 1 : 0); + table.getSelectionModel().setSelectionInterval(selection, selection); + } + + public String getDeleteTipText() { + return deleteTipText; + } + + public void setDeleteTipText(String deleteTipText) { + this.deleteTipText = deleteTipText; + } - private boolean ismultiSelected(){ + private boolean ismultiSelected() { int[] selectedRow = table.getSelectedRows(); return (selectedRow.length == 1 && (selectedRow[0] > table.getRowCount() - 1 || selectedRow[0] < 0)) || selectedRow.length == 0; } diff --git a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java index ce8fdaa9d7..417533465d 100644 --- a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java +++ b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java @@ -607,6 +607,24 @@ public class FRGUIPaneFactory { return jp; } + /** + * 创建垂直流布局,水平填充面板 + * + * @param isAlignLeft 是否左对齐 + * @param align the alignment value + * @param hgap the horizontal gap between components + * @param vgap the vertical gap between components + * @param hfill 水平填充组件 + * @return JPanel对象 + */ + public static JPanel createVerticalFlowLayout_F_Pane(boolean isAlignLeft, int align, int hgap, int vgap, boolean hfill) { + JPanel jp = new JPanel(); + VerticalFlowLayout layout = new VerticalFlowLayout(align, hgap, vgap, hfill); + layout.setAlignLeft(isAlignLeft); + jp.setLayout(layout); + return jp; + } + /** * 创建边框面板L * diff --git a/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java b/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java index c857c7301b..9f91fee506 100644 --- a/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java +++ b/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java @@ -95,6 +95,15 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { */ protected int vgap; + + /** + * true: 水平填充组件 + * + * @see #isHfill() + * @see #setHfill(boolean) + */ + protected boolean hfill; + /** * Constructs a new FlowLayout with a centered alignment and a * default 5-unit horizontal and vertical gap. @@ -135,6 +144,14 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { setAlignment(align); } + public VerticalFlowLayout(int align, int hgap, int vgap, boolean fill) { + this.hgap = hgap; + this.vgap = vgap; + this.hfill = fill; + + setAlignment(align); + } + /** * Gets the alignment for this layout. * Possible values are FlowLayout.TOP, @@ -219,6 +236,31 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { * @param name the name of the component * @param comp the component to be added */ + + /** + * Gets the horizontal filling of components in the + * Container.The default is false. + * + * @return the horizontal filling of components in the + * Container + * @see #setHfill(boolean) + */ + public boolean isHfill() { + return hfill; + } + + /** + * Sets the horizontal filling of components in the + * Container.The default is false. + * + * @param hfill the horizontal filling of components in the + * Container + * @see #isHfill() + */ + public void setHfill(boolean hfill) { + this.hfill = hfill; + } + @Override public void addLayoutComponent(String name, Component comp) { } @@ -379,6 +421,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { Insets insets = target.getInsets(); int maxlen = getMaxLen4LayoutContainer(target, insets); + int maxwidth = target.getWidth() - (insets.left + insets.right); int nmembers = target.getComponentCount(); int x = getX4LayoutContainer(insets), y = getY4LayoutContainer(insets); int roww = 0, start = 0; @@ -390,6 +433,9 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = getPreferredSize(target, m); + if (hfill) { + d.width = maxwidth; + } m.setSize(d.width, d.height); rs = dealWithDim4LayoutContainer(target, insets, d, x, y, roww, start, maxlen, i, ltr); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index b59df2cf08..444ef577fb 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -329,7 +329,7 @@ public abstract class JTemplate> /** * 为另存的模板创建新的模板id */ - private void generateNewTemplateIdForSaveAs() { + protected void generateNewTemplateIdForSaveAs() { generateTemplateId(); } diff --git a/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java b/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java index 8a23e6fe0e..087a656ba6 100644 --- a/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java +++ b/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java @@ -18,6 +18,7 @@ import com.fr.event.Null; import com.fr.intelli.metrics.Compute; import com.fr.intelli.record.Focus; import com.fr.intelli.record.PerformancePoint; +import com.fr.jvm.assist.FineAssist; import com.fr.module.Activator; import com.fr.module.extension.Prepare; import com.fr.record.analyzer.AnalyzerConfiguration; @@ -57,7 +58,7 @@ public class DesignerAnalyzerActivator extends Activator implements Prepare { List backwardsConfigurations = findMutableBackwards(AnalyzerKey.KEY); if (!CollectionUtils.isEmpty(backwardsConfigurations)) { // 直接初始化,不添加默认值,防止和下面的冲突 - FineAnalyzer.initDirectly(basicFactory, backwardsConfigurations.toArray(new AnalyzerConfiguration[0])); + FineAnalyzer.initDirectly(FineAssist.findInstrumentation(), basicFactory, backwardsConfigurations.toArray(new AnalyzerConfiguration[0])); } // 等页面完全打开后,再进行 retransform, 别影响了启动速度 diff --git a/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java b/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java index b70bf44f97..a4ddfcd4e8 100644 --- a/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java +++ b/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java @@ -11,6 +11,7 @@ import com.fr.intelli.record.Measurable; import com.fr.intelli.record.MeasureObject; import com.fr.intelli.record.MeasureUnit; import com.fr.log.FineLoggerFactory; +import com.fr.log.message.AbstractMessage; import com.fr.measure.DBMeterFactory; import com.fr.stable.StringUtils; import com.fr.third.net.bytebuddy.asm.Advice; @@ -75,7 +76,7 @@ public class MonitorAdvice implements DesignerAnalyzerAdvice { List newArgs = new ArrayList<>(Arrays.asList(args)); newArgs.add(id); recordSQLDetail(id); - Object message = null; + AbstractMessage message = null; try { message = measurable.durableEntity(measureObject, newArgs.toArray()); } catch (Throwable throwable) { diff --git a/designer-base/src/main/resources/com/fr/design/standard/refresh/refresh_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/refresh/refresh_normal.svg new file mode 100644 index 0000000000..4e3fd9c147 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/refresh/refresh_normal.svg @@ -0,0 +1,7 @@ + + + icon_刷新_normal + + + + \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java new file mode 100644 index 0000000000..4382fc35f7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java @@ -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); +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java new file mode 100644 index 0000000000..55cf2f12c7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java @@ -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 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); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java new file mode 100644 index 0000000000..a190532769 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java @@ -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); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index f75e08d723..807325a3b4 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -46,12 +46,14 @@ public class SelectionModel { //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 private static final double OFFSET_RELATIVE = 0.80; - private static FormSelection clipboard = new FormSelection(); + private static FormSelectionClipboard formClipboard = FormSelectionClipboard.getInstance(); private FormDesigner designer; private FormSelection selection; private Rectangle hotspotBounds; private FormWidgetOptionProvider provider; + + public SelectionModel(FormDesigner designer) { this.designer = designer; selection = new FormSelection(); @@ -71,7 +73,7 @@ public class SelectionModel { * @return 是否为空 */ public static boolean isEmpty() { - return clipboard.isEmpty(); + return formClipboard.isEmpty(); } /** @@ -161,7 +163,7 @@ public class SelectionModel { if (hasSelectionComponent()) { FormSelection cutSelection = ClipboardFilter.cut(selection); if (cutSelection != null) { - cutSelection.cut2ClipBoard(clipboard); + DashboardClipboardManager.getInstance().cut2Clipboard(cutSelection); designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); setSelectedCreator(hasSelectedParaComponent() ? designer.getParaComponent() : designer.getRootComponent()); designer.repaint(); @@ -192,7 +194,7 @@ public class SelectionModel { if (!selection.isEmpty()) { FormSelection copySelection = ClipboardFilter.copy(selection); if (copySelection != null) { - copySelection.copy2ClipBoard(clipboard); + DashboardClipboardManager.getInstance().copy2Clipboard(copySelection); } } } @@ -203,7 +205,7 @@ public class SelectionModel { * @return 否 */ public boolean pasteFromClipBoard() { - FormSelection pasteSelection = ClipboardFilter.paste(clipboard); + FormSelection pasteSelection = ClipboardFilter.paste(formClipboard.getClipboard()); if (pasteSelection != null && !pasteSelection.isEmpty()) { if (!hasSelectedPasteSource()) { //未选 @@ -240,7 +242,7 @@ public class SelectionModel { //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 //当前选择的就是编辑器表层 FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), - clipboard, + formClipboard.getClipboard(), DELTA_X_Y, DELTA_X_Y); } @@ -248,7 +250,7 @@ public class SelectionModel { //cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到 //使用selection.getSelectedCreator()也应该是可以获取到的。 FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - clipboard, + formClipboard.getClipboard(), DELTA_X_Y, DELTA_X_Y); } @@ -266,7 +268,7 @@ public class SelectionModel { if (hasSelectedPasteSource()) { selectedPaste(); } else { - FormSelectionUtils.paste2Container(designer, container, clipboard, + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), rectangle.x + rectangle.width / 2, rectangle.y + DELTA_X_Y); } @@ -281,7 +283,7 @@ public class SelectionModel { selectedPaste(); } else { FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - clipboard, + formClipboard.getClipboard(), rectangle.x + rectangle.width / 2, rectangle.y + DELTA_X_Y); } @@ -314,13 +316,13 @@ public class SelectionModel { positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); } - FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), positionX, positionY); } else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { //绝对布局 Rectangle rec = selection.getSelctionBounds(); - FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); } else if (isExtraContainer(container)) { - provider.paste2Container(clipboard); + provider.paste2Container(formClipboard.getClipboard()); } } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java index 1c30b1a557..992ea9cfb5 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java @@ -68,7 +68,7 @@ public class LabelDefinePane extends AbstractDataModify