Browse Source

REPORT-43833 【10.0.14】远程设计数据连接/服务器数据集增加锁定

更新了ConnectionComboBoxPanel
Yvan 4 years ago
parent
commit
a1900cf1ba
  1. 47
      src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java

47
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.generic.Runner;
import com.fanruan.api.util.AssistKit; import com.fanruan.api.util.AssistKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
import com.fr.base.svg.IconUtils;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.data.datapane.connect.ConnectionListPane; 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.data.datapane.connect.ItemEditableComboBoxPanel;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter; 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.file.ConnectionConfig;
import com.fr.report.LockItem;
import com.fr.stable.NameReference; import com.fr.stable.NameReference;
import com.fr.stable.StringUtils;
import com.fr.transaction.WorkerCallBack; import com.fr.transaction.WorkerCallBack;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.server.connection.DBConnectAuth; import com.fr.workspace.server.connection.DBConnectAuth;
import org.jetbrains.annotations.Nullable; 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.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.util.ArrayList; import java.util.ArrayList;
@ -54,6 +64,24 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
refreshItems(); 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<String> items() { protected Iterator<String> items() {
nameList = new ArrayList<>(); nameList = new ArrayList<>();
Iterator<String> nameIt = ConnectionKit.getConnections().keySet().iterator(); Iterator<String> nameIt = ConnectionKit.getConnections().keySet().iterator();
@ -92,6 +120,14 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
protected void editItems() { protected void editItems() {
// 尝试为数据连接加锁
boolean actionLock = EditLockUtils.lock(LockItem.CONNECTION);
if (!actionLock) {
// 锁定失败,代表已经被其他用户锁定,跳出弹窗提示
EditLockUtils.showLockMessage();
return;
}
// 锁定成功,执行后续操作
final ConnectionListPane connectionListPane = new ConnectionListPane(); final ConnectionListPane connectionListPane = new ConnectionListPane();
final ConnectionConfig connectionConfig = ConnectionConfig.getInstance(); final ConnectionConfig connectionConfig = ConnectionConfig.getInstance();
ConnectionConfig cloned = connectionConfig.mirror(); ConnectionConfig cloned = connectionConfig.mirror();
@ -119,6 +155,8 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
@Override @Override
public void afterCommit() { public void afterCommit() {
DesignKit.getDesignerBean("databasename").refreshBeanElement(); DesignKit.getDesignerBean("databasename").refreshBeanElement();
// 关闭定义数据连接页面,为其解锁
EditLockUtils.unlock(LockItem.CONNECTION);
} }
@Override @Override
@ -127,6 +165,13 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
} }
}); });
} }
@Override
public void doCancel() {
super.doCancel();
// 关闭定义数据连接页面,为其解锁
EditLockUtils.unlock(LockItem.CONNECTION);
}
}); });
connectionListDialog.setVisible(true); connectionListDialog.setVisible(true);
refreshItems(); refreshItems();

Loading…
Cancel
Save