Destiny.Lin
1 year ago
5 changed files with 240 additions and 124 deletions
@ -0,0 +1,128 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
import com.fr.design.bridge.exec.JSCallback; |
||||
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.PluginMarker; |
||||
import com.fr.plugin.manage.control.PluginTask; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
import com.fr.plugin.manage.control.ProgressCallback; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.JOptionPane; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 带进度条的批量处理的callback |
||||
* <li> content与title是处理完成后弹出的面板的内容与标题,子类需要在done之前设定好对应的信息 |
||||
* <li> 进度条是以 当前完成任务数/总任务数 来计算的 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2023/6/6 |
||||
*/ |
||||
public abstract class AbstractBatchModifyStatusCallback implements ProgressCallback { |
||||
protected JSCallback jsCallback; |
||||
protected Map<String, String> resultMap = new HashMap<>(); |
||||
protected String content = StringUtils.EMPTY; |
||||
protected String title = StringUtils.EMPTY; |
||||
public int pluginCount = 0; |
||||
public int allPluginCount = 0; |
||||
public int successCount = 0; |
||||
public int failedCount = 0; |
||||
public static final int HUNDRED_PERCENT = 100; |
||||
public static final String PERCENT = "%"; |
||||
public static final String DEFAULT = "default"; |
||||
|
||||
public AbstractBatchModifyStatusCallback() { |
||||
} |
||||
|
||||
public AbstractBatchModifyStatusCallback(JSCallback jsCallback, int size) { |
||||
this.jsCallback = jsCallback; |
||||
this.allPluginCount = size; |
||||
} |
||||
|
||||
@Override |
||||
public void done(PluginTaskResult result) { |
||||
String pluginInfo = PluginOperateUtils.getSuccessInfo(result); |
||||
if (result.isSuccess()) { |
||||
successCount++; |
||||
String modifyMessage = updateMessage(pluginInfo); |
||||
FineLoggerFactory.getLogger().info(modifyMessage); |
||||
} else { |
||||
failedCount++; |
||||
resultMap.put(getPluginName(result), pluginInfo); |
||||
} |
||||
updateProgressAndCheckCompletion(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取插件名 |
||||
* |
||||
* @param result 任务结果 |
||||
* @return 插件名 |
||||
*/ |
||||
public String getPluginName(PluginTaskResult result) { |
||||
PluginTask pluginTask = result.getCurrentTask(); |
||||
if (pluginTask != null) { |
||||
PluginMarker pluginMarker = pluginTask.getToMarker(); |
||||
if (pluginMarker != null) { |
||||
return pluginMarker.getPluginID(); |
||||
} |
||||
} |
||||
return DEFAULT; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 更新当前Map状态,进度条,如果全部都更新完了就回调 |
||||
*/ |
||||
public void updateProgressAndCheckCompletion() { |
||||
pluginCount++; |
||||
updateProgress(StringUtils.EMPTY, (double) pluginCount / allPluginCount); |
||||
FineLoggerFactory.getLogger().error("(double) pluginCount / allPluginCount:{}", (double) pluginCount / allPluginCount); |
||||
if (pluginCount == allPluginCount) { |
||||
jsCallback.execute("success"); |
||||
showMessageDialog(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 展示信息面板 |
||||
*/ |
||||
public void showMessageDialog() { |
||||
if (failedCount == 0) { |
||||
FineJOptionPane.showMessageDialog(DesignerPluginContext.getPluginDialog(), |
||||
content, |
||||
title, |
||||
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(title); |
||||
detailPane.show(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void updateProgress(String description, double progress) { |
||||
jsCallback.execute(progress * HUNDRED_PERCENT + PERCENT); |
||||
} |
||||
|
||||
/** |
||||
* 更新处理成功返回的日志信息 |
||||
* |
||||
* @return 返回的日志信息 |
||||
*/ |
||||
abstract public String updateMessage(String pluginInfo); |
||||
} |
@ -0,0 +1,77 @@
|
||||
package com.fr.design.extra.exe.callback; |
||||
|
||||
|
||||
import com.fr.design.bridge.exec.JSCallback; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.plugin.manage.control.PluginTask; |
||||
import com.fr.plugin.manage.control.PluginTaskResult; |
||||
|
||||
|
||||
/** |
||||
* 批量更新的callback |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2023/6/6 |
||||
*/ |
||||
public class BatchUpdateOnlineCallback extends AbstractBatchModifyStatusCallback{ |
||||
public static final BatchUpdateOnlineCallback NONE = new BatchUpdateOnlineCallback(); |
||||
|
||||
/** |
||||
* 可自动处理前置任务的callback,用来处理实际更新逻辑 |
||||
*/ |
||||
private InnerUpdateCallback innerPreTaskCallback; |
||||
|
||||
public BatchUpdateOnlineCallback() { |
||||
} |
||||
|
||||
public BatchUpdateOnlineCallback(JSCallback jsCallback, int size) { |
||||
super(jsCallback, size); |
||||
this.title = Toolkit.i18nText("Fine-Design_Basic_Plugin_Update"); |
||||
this.content = Toolkit.i18nText("Fine-Design_Basic_Plugin_Update_Success"); |
||||
} |
||||
|
||||
/** |
||||
* 更新任务 |
||||
* |
||||
* @param pluginTask 任务 |
||||
* @param jsCallback callback |
||||
*/ |
||||
public void createInnerPreTaskCallback(PluginTask pluginTask, JSCallback jsCallback) { |
||||
innerPreTaskCallback = new InnerUpdateCallback(pluginTask, jsCallback); |
||||
} |
||||
|
||||
|
||||
|
||||
public InnerUpdateCallback getInnerPreTaskCallback() { |
||||
return innerPreTaskCallback; |
||||
} |
||||
|
||||
@Override |
||||
public String updateMessage(String pluginInfo) { |
||||
return pluginInfo + Toolkit.i18nText("Fine-Design_Basic_Plugin_Update_Success"); |
||||
} |
||||
|
||||
/** |
||||
* 可自动处理前置任务的callback,用来处理实际更新逻辑 |
||||
*/ |
||||
public class InnerUpdateCallback extends UpdateOnlineCallback { |
||||
|
||||
|
||||
public InnerUpdateCallback(PluginTask pluginTask, JSCallback jsCallback) { |
||||
super(pluginTask, jsCallback); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void updateProgress(String description, double aProgress) { |
||||
//不进行处理
|
||||
} |
||||
|
||||
@Override |
||||
public void allDone(PluginTaskResult result) { |
||||
BatchUpdateOnlineCallback.this.done(result); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue