Browse Source

Merge pull request 'REPORT-43833 【10.0.14】远程设计数据连接/服务器数据集增加锁定' (#6) from yvan/finekit:master into master

Reviewed-on: #6
pull/9/head
richie 4 years ago
parent
commit
22c28b7090
  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.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<String> items() {
nameList = new ArrayList<>();
Iterator<String> 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();

Loading…
Cancel
Save