Destiny.Lin
1 year ago
4 changed files with 387 additions and 21 deletions
@ -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); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue