From 055935a364628583e8613a0067849a3e71ba815d Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Fri, 19 May 2023 16:33:25 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-89867=20=E3=80=90=E9=99=8D=E6=9C=AC?= =?UTF-8?q?=E5=A2=9E=E6=95=88=E3=80=91=E6=8F=92=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extra/PluginBatchModifyDetailPane.java | 173 ++++++++++++++++++ .../fr/design/extra/PluginOperateUtils.java | 83 ++++++--- .../callback/BatchModifyStatusCallback.java | 139 ++++++++++++++ .../java/com/fr/design/upm/UpmBridge.java | 13 ++ 4 files changed, 387 insertions(+), 21 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/extra/PluginBatchModifyDetailPane.java create mode 100644 designer-base/src/main/java/com/fr/design/extra/exe/callback/BatchModifyStatusCallback.java diff --git a/designer-base/src/main/java/com/fr/design/extra/PluginBatchModifyDetailPane.java b/designer-base/src/main/java/com/fr/design/extra/PluginBatchModifyDetailPane.java new file mode 100644 index 0000000000..41f5400387 --- /dev/null +++ b/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); + } +} diff --git a/designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java b/designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java index 379daab28e..b6b86f11ff 100644 --- a/designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java +++ b/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,6 +95,64 @@ public class PluginOperateUtils { } + /** + * 批量启用或禁用插件 + * + * @param pluginIDs 要处理的插件信息 + * @param jsCallback 回调函数 + */ + public static void setPluginActive(JSArray pluginIDs, JSCallback jsCallback) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + List 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(); + 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) { + // 禁用前提示 + int rv = FineJOptionPane.showConfirmDialog( + null, + forbidReminder.getContent(), + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE + ); + if (rv == JOptionPane.OK_OPTION) { + PluginManager.getController().forbidPersistently(pluginMarker, modifyStatusCallback); + } + } else { + // 正常禁用 + PluginManager.getController().forbidPersistently(pluginMarker, modifyStatusCallback); + } + } else { + PluginManager.getController().enablePersistently(pluginMarker, modifyStatusCallback); + } + } + public static void setPluginActive(String pluginInfo, JSCallback jsCallback) { SwingUtilities.invokeLater(new Runnable() { @@ -101,27 +162,7 @@ public class PluginOperateUtils { PluginContext plugin = PluginManager.getContext(pluginMarker); boolean isRunning = plugin.isRunning(); PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(isRunning, jsCallback); - if (isRunning) { - PluginXmlElement forbidReminder = plugin.getXml().getElement(PluginElementName.ForbidReminder); - if (forbidReminder != null && forbidReminder.getContent() != null) { - // 禁用前提示 - int rv = FineJOptionPane.showConfirmDialog( - null, - forbidReminder.getContent(), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.WARNING_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - PluginManager.getController().forbidPersistently(pluginMarker, modifyStatusCallback); - } - } else { - // 正常禁用 - PluginManager.getController().forbidPersistently(pluginMarker, modifyStatusCallback); - } - } else { - PluginManager.getController().enablePersistently(pluginMarker, modifyStatusCallback); - } + changePluginActive(isRunning, pluginMarker, modifyStatusCallback, plugin); } }); } diff --git a/designer-base/src/main/java/com/fr/design/extra/exe/callback/BatchModifyStatusCallback.java b/designer-base/src/main/java/com/fr/design/extra/exe/callback/BatchModifyStatusCallback.java new file mode 100644 index 0000000000..a815a8e369 --- /dev/null +++ b/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 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; + } + + +} diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java b/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java index 01369116d7..11079561ab 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java +++ b/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); + } + /** * 选择文件对话框 *