Browse Source

Merge pull request #4391 in DESIGN/design from feature/10.0 to feature/x

* commit 'ac67f3a096d451b56ff44061329aec31fe76651e':
  REPORT-51962【10.0.17】错误信息优化之模板缺失插件异常提示优化
research/11.0
superman 4 years ago
parent
commit
d975306490
  1. 7
      designer-base/src/main/java/com/fr/design/bridge/exec/JSExecutor.java
  2. 328
      designer-base/src/main/java/com/fr/design/dialog/UIExpandDialog.java
  3. 20
      designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java
  4. 13
      designer-base/src/main/java/com/fr/design/extra/exe/callback/ModifyStatusCallback.java
  5. 85
      designer-realize/src/main/java/com/fr/design/mainframe/app/AbstractWorkBookApp.java

7
designer-base/src/main/java/com/fr/design/bridge/exec/JSExecutor.java

@ -7,5 +7,12 @@ public interface JSExecutor {
String CALLBACK_FUNCTION_NAME = "action";
JSExecutor DEFAULT = new JSExecutor() {
@Override
public void executor(String newValue) {
// do nothing
}
};
void executor(String newValue);
}

328
designer-base/src/main/java/com/fr/design/dialog/UIExpandDialog.java

@ -0,0 +1,328 @@
package com.fr.design.dialog;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.design.i18n.Toolkit;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* 可展开对话框
*
* <pre>
* UIExpandDialog.Builder()
* .owner(jf)
* .title("title")
* .messageType(UIExpandDialog.WARNING_MESSAGE)
* .message("message text")
* .detail("detail")
* .expand(false)
* .modal(false)
* .dialogActionListener(new DialogActionAdapter(){
* public void doOk() {
* System.out.println("OK");
* }
* }).build().setVisible(true);
* </pre>
*
* @author vito
* @version 10.0
* Created by vito on 2021/5/19
*/
public class UIExpandDialog extends UIDialog {
public static final int MARGIN = 10;
public static final int TEXT_AREA_ROW = 5;
public static final int GAP = 5;
public static final int ERROR_MESSAGE = 0;
public static final int INFORMATION_MESSAGE = 1;
public static final int WARNING_MESSAGE = 2;
public static final int QUESTION_MESSAGE = 3;
public static final String HTML_TAG_1 = "<html>";
public static final String HTML_TAG_2 = "</html>";
private final JPanel foldBar = new JPanel();
private final JPanel expandableContentPane = new JPanel();
private final UILabel narrow = new UILabel();
private final UILabel narrowHit = new UILabel();
private final UIButton buttonOK;
private final UIButton buttonCancel;
private JLabel msg;
private final UITextArea textArea = new UITextArea();
public UIExpandDialog(Frame owner, String title, boolean isModal,
int messageType, String message, String detail,
String okText, String cancelText, boolean isExpand) {
super(owner);
buttonOK = new UIButton(okText);
buttonCancel = new UIButton(cancelText);
setTitle(title);
setModal(isModal);
initComponents(messageType, message, detail, isModal, isExpand, null);
}
public UIExpandDialog(Builder builder) {
super(builder.owner);
buttonOK = new UIButton(builder.okText);
buttonCancel = new UIButton(builder.cancelText);
setTitle(builder.title);
setModal(builder.modal);
initComponents(builder.messageType, builder.message, builder.detail,
builder.modal, builder.expand, builder.dialogActionListener);
}
public void initComponents(int messageType, String message, String detail,
boolean isModal, boolean isExpand, DialogActionListener l) {
setLayout(new BorderLayout(GAP, GAP));
setResizable(false);
setModal(isModal);
getRootPane().setDefaultButton(buttonOK);
// 标题面板
UILabel icon = new UILabel(getIconForType(messageType));
msg = new JLabel(HTML_TAG_1 + message + HTML_TAG_2);
msg.setPreferredSize(new Dimension(300, 50));
JPanel mainMsg = new JPanel();
mainMsg.setLayout(new FlowLayout(FlowLayout.LEFT, MARGIN, MARGIN));
mainMsg.setPreferredSize(new Dimension(380, 60));
mainMsg.add(icon);
mainMsg.add(msg);
add(mainMsg, BorderLayout.NORTH);
// 内容面板
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BorderLayout(GAP, GAP));
foldBar.setLayout(new FlowLayout(FlowLayout.LEFT, MARGIN, 0));
foldBar.add(narrow);
foldBar.add(narrowHit);
contentPanel.add(foldBar, BorderLayout.NORTH);
textArea.setEditable(false);
textArea.setRows(TEXT_AREA_ROW);
textArea.setMargin(new Insets(GAP, GAP, GAP, GAP));
textArea.setEditable(false);
textArea.setText(detail);
UIScrollPane scrollPane = new UIScrollPane(textArea);
expandableContentPane.setLayout(new BorderLayout());
expandableContentPane.setBorder(BorderFactory.createEmptyBorder(0, MARGIN, 0, MARGIN));
expandableContentPane.add(scrollPane, BorderLayout.CENTER);
changeExpand(isExpand);
contentPanel.add(expandableContentPane, BorderLayout.CENTER);
add(contentPanel, BorderLayout.CENTER);
// 操作面板
JPanel actionPanel = new JPanel();
actionPanel.setLayout(new FlowLayout(FlowLayout.CENTER, MARGIN, MARGIN));
actionPanel.add(buttonCancel);
actionPanel.add(buttonOK);
add(actionPanel, BorderLayout.SOUTH);
initListener();
if (l != null) {
addDialogActionListener(l);
}
pack();
if (getOwner() != null) {
GUICoreUtils.setWindowCenter(getOwner(), this);
}
}
private void changeExpand(boolean isExpand) {
if (isExpand) {
expandableContentPane.setVisible(true);
narrow.setIcon(UIManager.getIcon("OptionPane.narrow.down"));
narrowHit.setText(Toolkit.i18nText("Fine_Designer_Hide_Detail"));
} else {
expandableContentPane.setVisible(false);
narrow.setIcon(UIManager.getIcon("OptionPane.narrow.right"));
narrowHit.setText(Toolkit.i18nText("Fine_Designer_Look_Detail"));
}
}
private void initListener() {
foldBar.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
changeExpand(!expandableContentPane.isShowing());
pack();
}
@Override
public void mouseEntered(MouseEvent e) {
foldBar.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseExited(MouseEvent e) {
foldBar.setCursor(Cursor.getDefaultCursor());
}
});
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doOK();
}
});
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doCancel();
}
});
}
protected Icon getIconForType(int messageType) {
if (messageType < 0 || messageType > 3)
return null;
String propertyName;
switch (messageType) {
case 0:
propertyName = "OptionPane.errorIcon";
break;
case 1:
default:
propertyName = "OptionPane.informationIcon";
break;
case 2:
propertyName = "OptionPane.warningIcon";
break;
case 3:
propertyName = "OptionPane.questionIcon";
break;
}
return UIManager.getIcon(propertyName);
}
/**
* 设置对话框主消息
*
* @param message 消息内容
*/
public void setMessage(String message) {
msg.setText(HTML_TAG_1 + message + HTML_TAG_2);
}
/**
* 设置对话框消息详情
*
* @param detail 消息详情
*/
public void setDetail(String detail) {
textArea.setText(detail);
}
/**
* 设置详情面板展开关闭
*
* @param expand 展开或关闭
*/
public void setExpand(boolean expand) {
changeExpand(expand);
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
}
public static Builder Builder() {
return new UIExpandDialog.Builder();
}
public static final class Builder {
public int messageType = ERROR_MESSAGE;
public String title;
public String message;
public String detail;
public String okText = Toolkit.i18nText("Fine-Design_Report_OK");
public String cancelText = Toolkit.i18nText("Fine-Design_Basic_Cancel");
public boolean modal = true;
public boolean expand = true;
public Frame owner = null;
public DialogActionListener dialogActionListener = null;
private Builder() {
}
public UIExpandDialog build() {
return new UIExpandDialog(this);
}
public Builder owner(Frame owner) {
this.owner = owner;
return this;
}
public Builder messageType(int messageType) {
this.messageType = messageType;
return this;
}
public Builder title(String title) {
this.title = title;
return this;
}
public Builder message(String message) {
this.message = message;
return this;
}
public Builder detail(String detail) {
this.detail = detail;
return this;
}
public Builder okText(String okText) {
this.okText = okText;
return this;
}
public Builder cancelText(String cancelText) {
this.cancelText = cancelText;
return this;
}
public Builder modal(boolean modal) {
this.modal = modal;
return this;
}
public Builder expand(boolean expand) {
this.expand = expand;
return this;
}
public Builder dialogActionListener(DialogActionListener dialogActionListener) {
this.dialogActionListener = dialogActionListener;
return this;
}
}
@Override
public void checkValid() throws Exception {
}
}

20
designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java

@ -1,6 +1,7 @@
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.PluginOperateUtils;
import com.fr.design.i18n.Toolkit;
@ -17,17 +18,22 @@ import com.fr.plugin.manage.control.PluginTaskResult;
* Created by ibm on 2017/5/26.
*/
public class InstallOnlineCallback extends AbstractDealPreTaskCallback {
protected JSCallback jsCallback;
protected JSCallback jsCallback = new JSCallback(JSExecutor.DEFAULT);
private static int HUNDRED_PERCENT = 100;
public InstallOnlineCallback(PluginTask pluginTask, JSCallback jsCallback){
public InstallOnlineCallback(PluginTask pluginTask) {
super(pluginTask);
}
public InstallOnlineCallback(PluginTask pluginTask, JSCallback jsCallback) {
super(pluginTask);
this.jsCallback = jsCallback;
}
@Override
public void updateProgress(String description, double aProgress) {
jsCallback.execute(String.valueOf(aProgress * HUNDRED_PERCENT + "%"));
jsCallback.execute(aProgress * HUNDRED_PERCENT + "%");
}
@ -37,10 +43,10 @@ public class InstallOnlineCallback extends AbstractDealPreTaskCallback {
if (result.isSuccess()) {
String switchedInfo = PluginOperateUtils.getSwitchedInfo(result);
jsCallback.execute("success");
String successInfo = pluginInfo + Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success") + switchedInfo;
String successInfo = pluginInfo + Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success") + switchedInfo;
FineLoggerFactory.getLogger().info(successInfo);
FineJOptionPane.showMessageDialog(null, successInfo);
} else if(result.errorCode() == PluginErrorCode.HasLowerPluginWhenInstall){
} else if (result.errorCode() == PluginErrorCode.HasLowerPluginWhenInstall) {
int rv = FineJOptionPane.showConfirmDialog(
null,
Toolkit.i18nText("Fine-Design_Basic_Plugin_Has_Install_Lower"),
@ -51,8 +57,7 @@ public class InstallOnlineCallback extends AbstractDealPreTaskCallback {
if (rv == FineJOptionPane.OK_OPTION) {
PluginMarker pluginMarker = result.getCurrentTask().getMarker();
PluginOperateUtils.updatePluginOnline(pluginMarker, jsCallback);
}
else {
} else {
jsCallback.execute("success");
}
} else {
@ -63,5 +68,4 @@ public class InstallOnlineCallback extends AbstractDealPreTaskCallback {
}
}

13
designer-base/src/main/java/com/fr/design/extra/exe/callback/ModifyStatusCallback.java

@ -1,6 +1,7 @@
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.PluginOperateUtils;
import com.fr.design.i18n.Toolkit;
@ -15,14 +16,20 @@ import javax.swing.JOptionPane;
/**
* Created by ibm on 2017/5/27.
*/
public class ModifyStatusCallback implements PluginTaskCallback{
public class ModifyStatusCallback implements PluginTaskCallback {
private boolean isActive;
private JSCallback jsCallback;
private JSCallback jsCallback = new JSCallback(JSExecutor.DEFAULT);
;
public ModifyStatusCallback (boolean isActive, JSCallback jsCallback){
public ModifyStatusCallback(boolean isActive) {
this.isActive = isActive;
}
public ModifyStatusCallback(boolean isActive, JSCallback jsCallback) {
this.isActive = isActive;
this.jsCallback = jsCallback;
}
@Override
public void done(PluginTaskResult result) {
String pluginInfo = PluginOperateUtils.getSuccessInfo(result);

85
designer-realize/src/main/java/com/fr/design/mainframe/app/AbstractWorkBookApp.java

@ -1,29 +1,45 @@
package com.fr.design.mainframe.app;
import com.fr.base.Parameter;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.UIExpandDialog;
import com.fr.design.extra.exe.callback.InstallOnlineCallback;
import com.fr.design.extra.exe.callback.ModifyStatusCallback;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.App;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.worker.open.OpenResult;
import com.fr.design.worker.open.OpenWorker;
import com.fr.file.FILE;
import com.fr.io.TemplateIOErrorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.main.impl.WorkBook;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.context.PluginMarkerAdapter;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginControllerHelper;
import com.fr.plugin.manage.control.PluginTask;
import com.fr.report.worksheet.WorkSheet;
import com.fr.third.guava.collect.Multimap;
import com.fr.workspace.WorkContext;
import java.util.Collection;
import java.util.concurrent.Callable;
/**
* Created by juhaoyu on 2018/6/27.
*/
abstract class AbstractWorkBookApp implements App<WorkBook> {
@Override
public int currentAPILevel() {
return CURRENT_LEVEL;
}
@Override
public JTemplate<WorkBook, ?> openTemplate(FILE tplFile) {
JWorkBook emptyTemplate = new JWorkBook(new WorkBook(new WorkSheet()), tplFile);
@ -32,6 +48,7 @@ abstract class AbstractWorkBookApp implements App<WorkBook> {
@Override
public OpenResult<WorkBook, Parameter[]> call() {
WorkBook workBook = asIOFile(tplFile);
dealWithTemplateIOError(tplFile.getPath());
return new OpenResult<>(workBook, workBook.getParameters());
}
}, emptyTemplate);
@ -50,20 +67,68 @@ abstract class AbstractWorkBookApp implements App<WorkBook> {
}
return emptyTemplate;
}
private void dealWithTemplateIOError(String path) {
// 试图获取多行读取错误提示并缓存待处理列表
String detail = TemplateIOErrorUtils.dealWithErrorDetailMultiLineAndCache(path);
if (detail.length() > 0) {
if (WorkContext.getCurrent().isLocal()) {
UIExpandDialog.Builder()
.owner(DesignerContext.getDesignerFrame())
.title(Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"))
.message(Toolkit.i18nText("Fine-Design_Template_Plugin_Error_Message_Local"))
.detail(detail)
.okText(Toolkit.i18nText("Fine-Design_Template_Plugin_Error_OK_Btn"))
.cancelText(Toolkit.i18nText("Fine-Design_Template_Plugin_Error_Cancel_Btn"))
.dialogActionListener(new DialogActionAdapter() {
public void doOk() {
installAndEnablePlugin(path);
}
@Override
public void doCancel() {
TemplateIOErrorUtils.invalidatePlugins(path);
}
}).build().setVisible(true);
} else {
UIExpandDialog.Builder().owner(DesignerContext.getDesignerFrame())
.title(Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"))
.message(Toolkit.i18nText("Fine-Design_Template_Plugin_Error_Message_Remote"))
.detail(detail)
.build()
.setVisible(true);
}
}
}
public void installAndEnablePlugin(String key) {
Multimap<String, PluginMarkerAdapter> stringPluginMarkerAdapterMultimap = TemplateIOErrorUtils.popPluginInfoMap(key);
Collection<PluginMarkerAdapter> disablePlugins = stringPluginMarkerAdapterMultimap.get(TemplateIOErrorUtils.DISABLE_PLUGIN);
for (PluginMarkerAdapter disablePlugin : disablePlugins) {
PluginManager.getController().enable(disablePlugin, new ModifyStatusCallback(false));
}
Collection<PluginMarkerAdapter> uninstallPlugins = stringPluginMarkerAdapterMultimap.get(TemplateIOErrorUtils.NOT_INSTALLED_PLUGIN);
for (PluginMarker uninstallPlugin : uninstallPlugins) {
PluginTask pluginTask = PluginTask.installTask(uninstallPlugin);
PluginControllerHelper.installOnline(uninstallPlugin, new InstallOnlineCallback(pluginTask));
}
}
@Override
public String mark4Provider() {
return getClass().getName();
}
@Override
public void process() {
}
@Override
public void undo() {
}
}
Loading…
Cancel
Save