Browse Source

REPORT-89867 【降本增效】插件管理优化

feature/x
Destiny.Lin 2 years ago
parent
commit
055935a364
  1. 173
      designer-base/src/main/java/com/fr/design/extra/PluginBatchModifyDetailPane.java
  2. 45
      designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java
  3. 139
      designer-base/src/main/java/com/fr/design/extra/exe/callback/BatchModifyStatusCallback.java
  4. 13
      designer-base/src/main/java/com/fr/design/upm/UpmBridge.java

173
designer-base/src/main/java/com/fr/design/extra/PluginBatchModifyDetailPane.java

@ -0,0 +1,173 @@
package com.fr.design.extra;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* 插件批量处理弹窗面板
*
* @author Destiny.Lin
* @since 11.0
* Created on 2023/5/19
*/
public class PluginBatchModifyDetailPane {
private UILabel message = new UILabel();
private UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Report_OK"));
private UILabel uiLabel = new UILabel();
private UILabel directUiLabel = new UILabel();
private UILabel detailLabel = new UILabel();
private JPanel upPane;
private JPanel midPane;
private JPanel downPane;
private JPanel hiddenPanel;
private JTextArea jta;
private JDialog dialog;
public PluginBatchModifyDetailPane(Dialog parent) {
init(parent);
}
private void init(Dialog parent) {
message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0));
dialog = new JDialog(parent, Toolkit.i18nText("Fine-Design_Basic_Plugin_Manager"), true);
dialog.setSize(new Dimension(380, 150));
JPanel jp = new JPanel();
initUpPane();
initDownPane();
initMidPane();
initHiddenPanel();
initListener();
jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS));
jp.add(upPane);
jp.add(midPane);
jp.add(hiddenPanel);
jp.add(downPane);
hiddenPanel.setVisible(false);
dialog.add(jp);
dialog.setResizable(false);
dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(parent));
}
private void initDownPane() {
downPane = new JPanel();
downPane.setLayout(new FlowLayout(FlowLayout.RIGHT, 15, 9));
downPane.add(cancelButton);
}
private void initUpPane() {
upPane = new JPanel();
uiLabel = new UILabel(UIManager.getIcon("OptionPane.errorIcon"));
upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
upPane.add(uiLabel);
upPane.add(message);
}
private void initMidPane() {
midPane = new JPanel();
midPane.add(directUiLabel);
midPane.add(detailLabel);
midPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0));
detailLabel.setText(Toolkit.i18nText("Fine_Designer_Look_Detail"));
detailLabel.setForeground(Color.BLUE);
detailLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
directUiLabel.setIcon(UIManager.getIcon("OptionPane.narrow.right"));
}
private void initHiddenPanel() {
hiddenPanel = new JPanel();
hiddenPanel.setLayout(new BorderLayout(2, 0));
hiddenPanel.add(new JPanel(), BorderLayout.WEST);
hiddenPanel.add(new JPanel(), BorderLayout.EAST);
JPanel borderPanel = new JPanel();
borderPanel.setLayout(new BorderLayout());
jta = new JTextArea();
JScrollPane jsp = new JScrollPane(jta);
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jta.setEditable(false);
borderPanel.add(jsp, BorderLayout.CENTER);
hiddenPanel.add(borderPanel);
}
public void updateDetailArea(String message) {
jta.append(message + "\n");
}
private void initListener() {
detailLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (hiddenPanel.isVisible()) {
hiddenPanel.setVisible(false);
dialog.setSize(new Dimension(380, 150));
detailLabel.setText(Toolkit.i18nText("Fine_Designer_Look_Detail"));
directUiLabel.setIcon(UIManager.getIcon("OptionPane.narrow.right"));
} else {
dialog.setSize(new Dimension(380, 270));
hiddenPanel.setVisible(true);
detailLabel.setText(Toolkit.i18nText("Fine_Designer_Hide_Detail"));
directUiLabel.setIcon(UIManager.getIcon("OptionPane.narrow.down"));
}
}
});
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
hiddenPanel.removeAll();
dialog.dispose();
}
});
}
/**
* 更新标题启用插件还是禁用插件
* @param isActive 是否启用
*/
public void updateTitle(boolean isActive) {
if (isActive) {
dialog.setTitle(Toolkit.i18nText("Fine-Design_Basic_Plugin_Stop"));
} else {
dialog.setTitle(Toolkit.i18nText("Fine-Design_Basic_Plugin_Start"));
}
}
/**
* 更新展示信息
*
* @param failedCount 处理失败个数
* @param successCount 处理成功个数
*/
public void updateMessage(int failedCount, int successCount) {
message.setText(Toolkit.i18nText("Fine-Design_Basic_Plugin_Batch_Modify_Info", failedCount, successCount));
}
/**
* 显示面板
*/
public void show() {
dialog.setVisible(true);
}
}

45
designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java

@ -3,6 +3,7 @@ package com.fr.design.extra;
import com.fr.design.DesignerEnvManager;
import com.fr.design.bridge.exec.JSCallback;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.extra.exe.callback.BatchModifyStatusCallback;
import com.fr.design.extra.exe.callback.InstallFromDiskCallback;
import com.fr.design.extra.exe.callback.InstallOnlineCallback;
import com.fr.design.extra.exe.callback.ModifyStatusCallback;
@ -28,11 +29,13 @@ import com.fr.plugin.view.PluginView;
import com.fr.plugin.xml.PluginElementName;
import com.fr.plugin.xml.PluginXmlElement;
import com.fr.stable.StringUtils;
import com.teamdev.jxbrowser.chromium.JSArray;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import java.io.File;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
@ -92,15 +95,41 @@ public class PluginOperateUtils {
}
public static void setPluginActive(String pluginInfo, JSCallback jsCallback) {
/**
* 批量启用或禁用插件
*
* @param pluginIDs 要处理的插件信息
* @param jsCallback 回调函数
*/
public static void setPluginActive(JSArray pluginIDs, JSCallback jsCallback) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
List<String> pluginInfos = new ArrayList<>();
for (int i = 0, len = pluginIDs.length(); i < len; i++) {
String pluginInfo = pluginIDs.get(i).asString().getValue();
pluginInfos.add(pluginInfo);
}
BatchModifyStatusCallback modifyStatusCallback = new BatchModifyStatusCallback(jsCallback, pluginIDs.length());
for (String pluginInfo : pluginInfos) {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
dealWithPluginActive(pluginMarker, modifyStatusCallback);
}
}
});
}
private static void dealWithPluginActive(PluginMarker pluginMarker, BatchModifyStatusCallback modifyStatusCallback) {
PluginContext plugin = PluginManager.getContext(pluginMarker);
boolean isRunning = plugin.isRunning();
PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(isRunning, jsCallback);
modifyStatusCallback.setActive(isRunning);
changePluginActive(isRunning, pluginMarker, modifyStatusCallback, plugin);
}
private static void changePluginActive(boolean isRunning, PluginMarker pluginMarker, PluginTaskCallback modifyStatusCallback, PluginContext plugin) {
if (isRunning) {
PluginXmlElement forbidReminder = plugin.getXml().getElement(PluginElementName.ForbidReminder);
if (forbidReminder != null && forbidReminder.getContent() != null) {
@ -123,6 +152,18 @@ public class PluginOperateUtils {
PluginManager.getController().enablePersistently(pluginMarker, modifyStatusCallback);
}
}
public static void setPluginActive(String pluginInfo, JSCallback jsCallback) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
PluginContext plugin = PluginManager.getContext(pluginMarker);
boolean isRunning = plugin.isRunning();
PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(isRunning, jsCallback);
changePluginActive(isRunning, pluginMarker, modifyStatusCallback, plugin);
}
});
}

139
designer-base/src/main/java/com/fr/design/extra/exe/callback/BatchModifyStatusCallback.java

@ -0,0 +1,139 @@
package com.fr.design.extra.exe.callback;
import com.fr.design.bridge.exec.JSCallback;
import com.fr.design.bridge.exec.JSExecutor;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.extra.PluginBatchModifyDetailPane;
import com.fr.design.extra.PluginOperateUtils;
import com.fr.design.i18n.Toolkit;
import com.fr.design.plugin.DesignerPluginContext;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.context.PluginMarkerAdapter;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTask;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.stable.StringUtils;
import javax.swing.JOptionPane;
import java.util.HashMap;
import java.util.Map;
/**
* 批量处理Callback
*
* @author Destiny.Lin
* @since 11.0
* Created on 2023/5/18
*/
public class BatchModifyStatusCallback implements PluginTaskCallback {
private boolean isActive;
private JSCallback jsCallback = new JSCallback(JSExecutor.DEFAULT);
private Map<String, String> resultMap = new HashMap<>();
private int pluginCount = 0;
private int allPluginCount = 0;
private int successCount = 0;
private int failedCount = 0;
public BatchModifyStatusCallback(boolean isActive) {
this.isActive = isActive;
}
public BatchModifyStatusCallback(boolean isActive, JSCallback jsCallback) {
this.isActive = isActive;
this.jsCallback = jsCallback;
}
public BatchModifyStatusCallback(JSCallback jsCallback, int size) {
this.jsCallback = jsCallback;
allPluginCount = size;
}
@Override
public void done(PluginTaskResult result) {
String pluginInfo = PluginOperateUtils.getSuccessInfo(result);
if (result.isSuccess()) {
successCount++;
String modifyMessage = isActive ?
pluginInfo + Toolkit.i18nText("Fine-Design_Basic_Plugin_Has_Been_Disabled_Duplicate") :
pluginInfo + Toolkit.i18nText("Fine-Design_Plugin_Has_Been_Actived_Duplicate");
FineLoggerFactory.getLogger().info(modifyMessage);
updateMapAndCheckDone();
} else {
failedCount++;
resultMap.put(getPluginName(result), pluginInfo);
updateMapAndCheckDone();
}
}
/**
* 更新当前Map状态如果全部都更新完了就回调
*/
public void updateMapAndCheckDone() {
pluginCount++;
if (pluginCount == allPluginCount) {
jsCallback.execute("success");
showMessageDialog();
}
}
/**
* 获取插件名
*
* @param result 任务结果
* @return 插件名
*/
public String getPluginName(PluginTaskResult result) {
PluginTask pluginTask = result.getCurrentTask();
if (pluginTask != null) {
PluginMarker pluginMarker = pluginTask.getToMarker();
PluginContext pluginContext = PluginManager.getContext(pluginMarker.getPluginID());
if (pluginContext != null) {
return pluginContext.getName();
} else if (pluginMarker instanceof PluginMarkerAdapter) {
return ((PluginMarkerAdapter) pluginMarker).getPluginName();
}
return pluginMarker.getPluginID();
}
return StringUtils.EMPTY;
}
/**
* 展示信息面板
*/
public void showMessageDialog() {
if (failedCount == 0) {
if (isActive) {
FineJOptionPane.showMessageDialog(DesignerPluginContext.getPluginDialog(),
Toolkit.i18nText("Fine-Design_Basic_Plugin_Batch_Modify_Stop_Success"),
Toolkit.i18nText("Fine-Design_Basic_Plugin_Stop"),
JOptionPane.INFORMATION_MESSAGE);
} else {
FineJOptionPane.showMessageDialog(DesignerPluginContext.getPluginDialog(),
Toolkit.i18nText("Fine-Design_Basic_Plugin_Batch_Modify_Start_Success"),
Toolkit.i18nText("Fine-Design_Basic_Plugin_Start"),
JOptionPane.INFORMATION_MESSAGE);
}
} else {
PluginBatchModifyDetailPane detailPane = new PluginBatchModifyDetailPane(DesignerPluginContext.getPluginDialog());
for (String key : resultMap.keySet()) {
detailPane.updateDetailArea(resultMap.get(key));
}
detailPane.updateMessage(failedCount, successCount);
detailPane.updateTitle(isActive);
detailPane.show();
}
}
public void setActive(boolean active) {
isActive = active;
}
}

13
designer-base/src/main/java/com/fr/design/upm/UpmBridge.java

@ -40,6 +40,7 @@ import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.JSArray;
import com.teamdev.jxbrowser.chromium.JSFunction;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.chromium.JSValue;
import java.awt.Desktop;
import javax.swing.JFileChooser;
@ -291,6 +292,18 @@ public class UpmBridge {
PluginOperateUtils.setPluginActive(pluginID, jsCallback);
}
/**
* 批量修改选中的插件的活跃状态
*
* @param pluginIDs 要处理的插件ID
* @param callback 回调函数
*/
@JSBridge
public void setAllPluginActive(JSArray pluginIDs, final JSFunction callback) {
JSCallback jsCallback = new JSCallback(UpmBrowserExecutor.create(window, callback));
PluginOperateUtils.setPluginActive(pluginIDs, jsCallback);
}
/**
* 选择文件对话框
*

Loading…
Cancel
Save