From feaf3a37bfb81a1e85aad9073652d1e931bb70c1 Mon Sep 17 00:00:00 2001 From: hades Date: Thu, 9 Sep 2021 16:25:14 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-8990=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E9=85=8D=E7=BD=AE=E4=BF=9D=E5=AD=98=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/server/GlobalTableDataAction.java | 31 ++------- .../data/datapane/TableDataPaneListPane.java | 28 ++++++-- .../connect/ConnectionComboBoxPanel.java | 50 +------------- .../ConnectionListDialogActionAdapter.java | 48 ++++++++++++++ .../datapane/connect/ConnectionListPane.java | 66 ++++++++++++++++--- .../design/os/impl/DatabaseDialogAction.java | 61 +---------------- 6 files changed, 136 insertions(+), 148 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListDialogActionAdapter.java diff --git a/designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java b/designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java index bc1445718a..fdfdc31b5b 100644 --- a/designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java @@ -25,9 +25,6 @@ import com.fr.esd.event.DsNameTarget; import com.fr.esd.event.StrategyEventsNotifier; import com.fr.file.TableDataConfig; -import com.fr.transaction.CallBackAdaptor; -import com.fr.transaction.Configurations; -import com.fr.transaction.WorkerFacade; import com.fr.report.LockItem; import javax.swing.KeyStroke; @@ -106,33 +103,17 @@ public class GlobalTableDataAction extends UpdateAction implements ResponseDataS globalTableDataDialog.setDoOKSucceed(false); return; } + globalTableDataPane.update(tableDataConfig); DesignTableDataManager.clearGlobalDs(); // 保存时 移除服务器数据集列名缓存 for (String name : tableDataConfig.getTableDatas().keySet()) { DesignTableDataManager.removeSelectedColumnNames(name); } - - Configurations.modify(new WorkerFacade(TableDataConfig.class) { - @Override - public void run() { - globalTableDataPane.update(tableDataConfig); - } - }.addCallBack(new CallBackAdaptor() { - @Override - public boolean beforeCommit() { - //如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面 - return doWithDatasourceManager(tableDataConfig, globalTableDataPane, globalTableDataDialog); - } - - @Override - public void afterCommit() { - // 刷新共有数据集 - TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); - fireDSChanged(globalTableDataPane.getDsChangedNameMap()); - // 关闭服务器数据集页面,为其解锁 - EditLockUtils.unlock(LockItem.SERVER_TABLE_DATA); - } - })); + // 刷新共有数据集 + TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); + fireDSChanged(globalTableDataPane.getDsChangedNameMap()); + // 关闭服务器数据集页面,为其解锁 + EditLockUtils.unlock(LockItem.SERVER_TABLE_DATA); } @Override diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java index 8972821b43..32bd070d95 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java @@ -1,6 +1,8 @@ package com.fr.design.data.datapane; import com.fr.base.TableData; +import com.fr.base.TableDataBean; +import com.fr.config.RemoteConfigEvent; import com.fr.data.TableDataSource; import com.fr.data.api.StoreProcedureAssist; import com.fr.data.impl.storeproc.StoreProcedure; @@ -12,22 +14,26 @@ import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.i18n.Toolkit; +import com.fr.event.EventDispatcher; import com.fr.file.ProcedureConfig; import com.fr.file.TableDataConfig; +import com.fr.file.TableDataOperator; import com.fr.general.ComparatorUtils; import com.fr.general.NameObject; +import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; +import com.fr.third.org.apache.commons.collections4.MapUtils; +import com.fr.workspace.WorkContext; import javax.swing.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -231,15 +237,25 @@ public class TableDataPaneListPane extends JListControlPane implements TableData @Override public void update(TableDataConfig tableDataConfig) { - tableDataConfig.removeAllTableData(); - ProcedureConfig.getInstance().removeAllProcedure(); Nameable[] tableDataArray = this.update(); - Map tableDataMap = new LinkedHashMap(); + List tableDataBeans = new ArrayList<>(); + Map map = MapUtils.invertMap(getDsNameChangedMap()); for (int i = 0; i < tableDataArray.length; i++) { NameObject nameObject = (NameObject) tableDataArray[i]; - tableDataMap.put(nameObject.getName(), (TableData) nameObject.getObject()); + String oldName = map.get(nameObject.getName()); + if (oldName == null) { + oldName = StringUtils.EMPTY; + } + tableDataBeans.add(new TableDataBean(nameObject.getName(), oldName, (TableData) nameObject.getObject())); + } + try { + WorkContext.getCurrent().get(TableDataOperator.class).saveTableData(tableDataBeans); + if (!WorkContext.getCurrent().isLocal()) { + EventDispatcher.fire(RemoteConfigEvent.EDIT, TableDataConfig.class.getSimpleName()); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } - tableDataConfig.setTableDatas(tableDataMap); } @Override diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java index 1ce37b4c51..310558f168 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java @@ -5,20 +5,13 @@ import com.fr.data.impl.AbstractDatabaseConnection; import com.fr.data.impl.Connection; import com.fr.data.impl.NameDatabaseConnection; import com.fr.design.DesignerEnvManager; -import com.fr.design.actions.server.ConnectionListAction; -import com.fr.design.dialog.BasicDialog; -import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.editlock.ConnectionLockChangeChecker; import com.fr.design.editlock.EditLockUtils; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UILockButton; -import com.fr.design.mainframe.DesignerContext; import com.fr.file.ConnectionConfig; import com.fr.general.ComparatorUtils; import com.fr.stable.StringUtils; -import com.fr.transaction.CallBackAdaptor; -import com.fr.transaction.Configurations; -import com.fr.transaction.WorkerFacade; import com.fr.workspace.WorkContext; import com.fr.workspace.server.connection.DBConnectAuth; import com.fr.report.LockItem; @@ -132,48 +125,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { return; } // 锁定成功,执行后续操作 - final ConnectionListPane connectionListPane = new ConnectionListPane(); - final ConnectionConfig connectionConfig = ConnectionConfig.getInstance(); - ConnectionConfig cloned = connectionConfig.mirror(); - connectionListPane.populate(cloned); - final BasicDialog connectionListDialog = connectionListPane.showLargeWindow( - SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), null); - connectionListDialog.addDialogActionListener(new DialogActionAdapter() { - public void doOk() { - if (!connectionListPane.isNamePermitted()) { - connectionListDialog.setDoOKSucceed(false); - return; - } - Configurations.modify(new WorkerFacade(ConnectionConfig.class) { - @Override - public void run() { - connectionListPane.update(connectionConfig); - } - }.addCallBack(new CallBackAdaptor() { - @Override - public boolean beforeCommit() { - //如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面 - return ConnectionListAction.doWithDatasourceManager(connectionConfig, connectionListPane, connectionListDialog); - } - - @Override - public void afterCommit() { - DesignerContext.getDesignerBean("databasename").refreshBeanElement(); - // 关闭定义数据连接页面,为其解锁 - EditLockUtils.unlock(LockItem.CONNECTION); - } - })); - - } - - @Override - public void doCancel() { - // 关闭定义数据连接页面,为其解锁 - super.doCancel(); - EditLockUtils.unlock(LockItem.CONNECTION); - } - }); - connectionListDialog.setVisible(true); + ConnectionListPane.showDialog(SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this)); refreshItems(); } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListDialogActionAdapter.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListDialogActionAdapter.java new file mode 100644 index 0000000000..2428c9a005 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListDialogActionAdapter.java @@ -0,0 +1,48 @@ +package com.fr.design.data.datapane.connect; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.editlock.EditLockUtils; +import com.fr.design.mainframe.DesignerContext; +import com.fr.file.ConnectionConfig; +import com.fr.report.LockItem; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/9/8 + */ +public class ConnectionListDialogActionAdapter extends DialogActionAdapter { + + private final ConnectionManagerPane connectionManagerPane; + private final BasicDialog connectionListDialog; + private final ConnectionConfig connectionConfig; + + public ConnectionListDialogActionAdapter(ConnectionManagerPane connectionManagerPane, + BasicDialog connectionListDialog, + ConnectionConfig connectionConfig) { + this.connectionManagerPane = connectionManagerPane; + this.connectionListDialog = connectionListDialog; + this.connectionConfig = connectionConfig; + } + + @Override + public void doOk() { + if (!connectionManagerPane.isNamePermitted()) { + connectionListDialog.setDoOKSucceed(false); + return; + } + connectionManagerPane.update(connectionConfig); + DesignerContext.getDesignerBean("databasename").refreshBeanElement(); + // 关闭定义数据连接页面,为其解锁 + EditLockUtils.unlock(LockItem.CONNECTION); + + } + + @Override + public void doCancel() { + // 关闭定义数据连接页面,为其解锁 + super.doCancel(); + EditLockUtils.unlock(LockItem.CONNECTION); + } +} 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 1e3f96a986..018aa8f4c8 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 @@ -1,23 +1,32 @@ package com.fr.design.data.datapane.connect; +import com.fr.config.RemoteConfigEvent; import com.fr.data.impl.Connection; +import com.fr.data.impl.ConnectionBean; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JNDIDatabaseConnection; import com.fr.design.ExtraDesignClassManager; +import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.fun.ConnectionProvider; import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.NameObjectCreator; import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.i18n.Toolkit; +import com.fr.event.EventDispatcher; import com.fr.file.ConnectionConfig; import com.fr.general.ComparatorUtils; import com.fr.general.NameObject; +import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; +import com.fr.third.org.apache.commons.collections4.MapUtils; +import com.fr.workspace.WorkContext; +import com.fr.file.ConnectionOperator; +import java.awt.Window; import javax.swing.*; import java.util.ArrayList; import java.util.Arrays; @@ -67,8 +76,19 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh protected void rename(String oldName, String newName) { - renameMap.remove(selectedName); - renameMap.put(selectedName, newName); + //如果a改成了b,b又被改成了c,就认为是a改成了c + for (Map.Entry entry : renameMap.entrySet()) { + if (StringUtils.equals(oldName, entry.getValue())) { + oldName = entry.getKey(); + break; + } + } + if (StringUtils.equals(oldName, newName)) { + //a -> b;b -> a,说明没改 + renameMap.remove(oldName); + } else { + renameMap.put(oldName, newName); + } } /** @@ -149,14 +169,42 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh public void update(ConnectionConfig connectionConfig) { // Nameable[]居然不能强转成NameObject[],一定要这么写... Nameable[] res = this.update(); - NameObject[] res_array = new NameObject[res.length]; - java.util.Arrays.asList(res).toArray(res_array); + List connectionBeans = new ArrayList<>(); + Map map = MapUtils.invertMap(getRenameMap()); + for (int i = 0; i < res.length; i++) { + NameObject nameObject = (NameObject) res[i]; + String oldName = map.get(nameObject.getName()); + if (oldName == null) { + oldName = StringUtils.EMPTY; + } + connectionBeans.add(new ConnectionBean(nameObject.getName(), oldName, (Connection) nameObject.getObject())); + } + try { + WorkContext.getCurrent().get(ConnectionOperator.class).saveConnection(connectionBeans); + if (!WorkContext.getCurrent().isLocal()) { + EventDispatcher.fire(RemoteConfigEvent.EDIT, ConnectionConfig.class.getSimpleName()); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } - connectionConfig.removeAllConnection(); + public static void showDialog(Window parent) { + final ConnectionConfig connectionConfig = ConnectionConfig.getInstance(); + final ConnectionManagerPane connectionManagerPane = new ConnectionManagerPane() { + @Override + public void complete() { + ConnectionConfig cloned = connectionConfig.mirror(); + populate(cloned); + } - for (int i = 0; i < res_array.length; i++) { - NameObject nameObject = res_array[i]; - connectionConfig.addConnection(nameObject.getName(), (Connection) nameObject.getObject()); - } + @Override + protected void renameConnection(String oldName, String newName) { + connectionConfig.renameConnection(oldName, newName); + } + }; + final BasicDialog connectionListDialog = connectionManagerPane.showLargeWindow(parent, null); + connectionListDialog.addDialogActionListener(new ConnectionListDialogActionAdapter(connectionManagerPane, connectionListDialog, connectionConfig)); + connectionListDialog.setVisible(true); } } diff --git a/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java b/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java index 057b561fa0..115b9617ce 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java @@ -1,18 +1,8 @@ package com.fr.design.os.impl; -import com.fr.design.data.datapane.connect.ConnectionManagerPane; -import com.fr.design.dialog.BasicDialog; -import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.editlock.EditLockUtils; +import com.fr.design.data.datapane.connect.ConnectionListPane; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.DesignerFrame; -import com.fr.file.ConnectionConfig; import com.fr.stable.os.support.OSBasedAction; -import com.fr.transaction.CallBackAdaptor; -import com.fr.transaction.Configurations; -import com.fr.transaction.WorkerFacade; -import com.fr.report.LockItem; -import static com.fr.design.actions.server.ConnectionListAction.doWithDatasourceManager; /** * 数据连接窗口 @@ -33,54 +23,7 @@ public class DatabaseDialogAction implements OSBasedAction { } private void openDesignDatabaseManager() { - DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); - final ConnectionConfig datasourceManager = ConnectionConfig.getInstance(); - final ConnectionManagerPane databaseManagerPane = new ConnectionManagerPane() { - public void complete() { - ConnectionConfig connectionConfig = datasourceManager.mirror(); - populate(connectionConfig); - } - - protected void renameConnection(String oldName, String newName) { - datasourceManager.renameConnection(oldName, newName); - } - }; - final BasicDialog databaseListDialog = databaseManagerPane.showLargeWindow(designerFrame, null); - databaseListDialog.addDialogActionListener(new DialogActionAdapter() { - public void doOk() { - if (!databaseManagerPane.isNamePermitted()) { - databaseListDialog.setDoOKSucceed(false); - return; - } - Configurations.modify(new WorkerFacade(ConnectionConfig.class) { - @Override - public void run() { - databaseManagerPane.update(datasourceManager); - } - }.addCallBack(new CallBackAdaptor() { - @Override - public boolean beforeCommit() { - //如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面 - return doWithDatasourceManager(datasourceManager, databaseManagerPane, databaseListDialog); - } - - @Override - public void afterCommit() { - DesignerContext.getDesignerBean("databasename").refreshBeanElement(); - // 定义数据连接弹窗关闭后,解锁 - EditLockUtils.unlock(LockItem.CONNECTION); - } - })); - } - - @Override - public void doCancel() { - super.doCancel(); - // 定义数据连接弹窗关闭后,解锁 - EditLockUtils.unlock(LockItem.CONNECTION); - } - }); - databaseListDialog.setVisible(true); + ConnectionListPane.showDialog(DesignerContext.getDesignerFrame()); }