插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

50 lines
1.6 KiB

package com.fanruan.api.design.work.compat;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.ui.component.UILockButton;
import com.fr.base.svg.IconUtils;
import com.fr.design.editlock.ConnectionLockChangeChecker;
import com.fr.design.editlock.EditLockUtils;
import com.fr.report.LockItem;
import java.awt.*;
import java.awt.event.ActionListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2021/3/18
* 用于兼容没有数据连接lock的版本
*/
public class ConnectionLockHelper {
public static UIButton generateLockButton(Dimension buttonSize, ActionListener listener) {
UILockButton editButton = new UILockButton(
EditLockUtils.CONNECTION_LOCKED_ICON,
IconUtils.readIcon("/com/fr/design/images/m_web/connection"),
EditLockUtils.CONNECTION_LOCKED_TOOLTIPS,
null
);
editButton.setPreferredSize(buttonSize);
editButton.addActionListener(listener);
ConnectionLockChangeChecker.getInstance().addEditLockChangeListener(editButton);
return editButton;
}
public static boolean doLock(Component component) {
// 尝试为数据连接加锁
boolean actionLock = EditLockUtils.lock(LockItem.CONNECTION);
if (!actionLock) {
// 锁定失败,代表已经被其他用户锁定,跳出弹窗提示
EditLockUtils.showLockMessage(component);
return true;
}
return false;
}
public static void unlock() {
// 关闭定义数据连接页面,为其解锁
EditLockUtils.unlock(LockItem.CONNECTION);
}
}