From a1900cf1bac9407cd22aed9fa9da40be099b8ab1 Mon Sep 17 00:00:00 2001 From: Yvan Date: Wed, 27 Jan 2021 15:40:06 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-43833=20=E3=80=9010.0.14=E3=80=91?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E8=AE=BE=E8=AE=A1=E6=95=B0=E6=8D=AE=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5/=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=A2=9E=E5=8A=A0=E9=94=81=E5=AE=9A=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86ConnectionComboBoxPanel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/work/ConnectionComboBoxPanel.java | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java b/src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java index 047e38c..37770be 100644 --- a/src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java +++ b/src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java @@ -8,6 +8,7 @@ import com.fanruan.api.design.macro.DataSourceConstants; import com.fanruan.api.generic.Runner; import com.fanruan.api.util.AssistKit; import com.fanruan.api.util.StringKit; +import com.fr.base.svg.IconUtils; import com.fr.data.impl.Connection; import com.fr.design.DesignerEnvManager; import com.fr.design.data.datapane.connect.ConnectionListPane; @@ -15,14 +16,23 @@ import com.fr.design.data.datapane.connect.ConnectionShowPane; import com.fr.design.data.datapane.connect.ItemEditableComboBoxPanel; 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.file.ConnectionConfig; +import com.fr.report.LockItem; import com.fr.stable.NameReference; +import com.fr.stable.StringUtils; import com.fr.transaction.WorkerCallBack; import com.fr.workspace.WorkContext; import com.fr.workspace.server.connection.DBConnectAuth; import org.jetbrains.annotations.Nullable; -import javax.swing.*; +import javax.swing.SwingUtilities; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; @@ -54,6 +64,24 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { refreshItems(); } + @Override + protected UIButton initEditButton(UIButton editButton, Dimension buttonSize) { + editButton = new UILockButton( + EditLockUtils.CONNECTION_LOCKED_ICON, + IconUtils.readIcon("/com/fr/design/images/m_web/connection"), + EditLockUtils.CONNECTION_LOCKED_TOOLTIPS, + StringUtils.EMPTY + ); + editButton.setPreferredSize(buttonSize); + editButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + editItems(); + } + }); + ConnectionLockChangeChecker.getInstance().addEditLockChangeListener((UILockButton) editButton); + return editButton; + } + protected Iterator items() { nameList = new ArrayList<>(); Iterator nameIt = ConnectionKit.getConnections().keySet().iterator(); @@ -92,6 +120,14 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { protected void editItems() { + // 尝试为数据连接加锁 + boolean actionLock = EditLockUtils.lock(LockItem.CONNECTION); + if (!actionLock) { + // 锁定失败,代表已经被其他用户锁定,跳出弹窗提示 + EditLockUtils.showLockMessage(); + return; + } + // 锁定成功,执行后续操作 final ConnectionListPane connectionListPane = new ConnectionListPane(); final ConnectionConfig connectionConfig = ConnectionConfig.getInstance(); ConnectionConfig cloned = connectionConfig.mirror(); @@ -119,6 +155,8 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { @Override public void afterCommit() { DesignKit.getDesignerBean("databasename").refreshBeanElement(); + // 关闭定义数据连接页面,为其解锁 + EditLockUtils.unlock(LockItem.CONNECTION); } @Override @@ -127,6 +165,13 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { } }); } + + @Override + public void doCancel() { + super.doCancel(); + // 关闭定义数据连接页面,为其解锁 + EditLockUtils.unlock(LockItem.CONNECTION); + } }); connectionListDialog.setVisible(true); refreshItems(); @@ -176,4 +221,4 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { } return -1; } -} \ No newline at end of file +}