From 0b02d73eb8a4f352ee1e6ae7b916877e79b482ff Mon Sep 17 00:00:00 2001 From: Harrison Date: Sun, 29 May 2022 15:45:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20REPORT-70565=20=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=EF=BC=88jar?= =?UTF-8?q?=E5=8C=85=E5=BC=82=E5=B8=B8=E3=80=81finedb=E3=80=81=E6=9D=80?= =?UTF-8?q?=E6=AF=92=E8=BD=AF=E4=BB=B6=EF=BC=89=201-=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E8=AE=BE=E5=AE=9A=EF=BC=8C=E9=92=88=E5=AF=B9=E6=9F=90=E4=B8=80?= =?UTF-8?q?=E9=A1=B9=E7=9A=84=E6=9F=90=E4=B8=80=E4=B8=AA=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=A3=80=E6=B5=8B=202-=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97=EF=BC=8C=E5=9C=A8=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E7=BB=9F=E4=B8=80=E8=BE=93=E5=87=BA=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E9=81=97=E5=BF=98=203-=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=80=E4=B8=8B=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F=204-?= =?UTF-8?q?=E8=A1=A5=E5=85=85=20UI=20=E9=83=A8=E5=88=86=20-=20=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=B1=95=E7=A4=BA=205-=E8=A1=A5=E5=85=85=20UI=20?= =?UTF-8?q?=E9=83=A8=E5=88=86=20-=20=E6=A3=80=E6=B5=8B=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/env/detect/EnvDetectorCenter.java | 172 +++++++++++ .../detect/base/CatchExceptionDetector.java | 2 +- .../fr/env/detect/base/DetectorBridge.java | 27 +- .../fr/env/detect/base/DetectorManager.java | 4 +- .../com/fr/env/detect/base/DetectorUtil.java | 85 +++++- .../detect/base/ExceptionDetectorConfig.java | 23 +- .../fr/env/detect/bean/DetectorResult.java | 4 + .../fr/env/detect/bean/ExceptionSolution.java | 5 + .../com/fr/env/detect/bean/ExceptionTips.java | 5 + .../detect/exception/DetectorException.java | 26 -- .../exception/intelli/package-info.java | 4 - .../env/detect/impl/JarConflictDetector.java | 4 +- .../detect/impl/JarInconsistentDetector.java | 141 ++++----- .../fr/env/detect/impl/JarLackDetector.java | 8 +- ...ertor.java => ClassConflictConvertor.java} | 30 +- .../impl/converter/FineDbDirtyConverter.java | 27 +- .../impl/converter/FineDbLockedConverter.java | 2 +- .../converter/FineDbPermissionConverter.java | 3 +- .../fr/env/detect/ui/DetectorErrorDialog.java | 135 +++++++++ .../fr/env/detect/ui/EnvDetectorDialog.java | 273 ++++++------------ .../com/fr/env/detect/ui/EnvDetectorItem.java | 38 +++ .../fr/env/detect/ui/EnvDetectorModel.java | 59 ++++ 22 files changed, 762 insertions(+), 315 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java delete mode 100644 designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java delete mode 100644 designer-base/src/main/java/com/fr/env/detect/exception/intelli/package-info.java rename designer-base/src/main/java/com/fr/env/detect/impl/converter/{ClassConfictConvertor.java => ClassConflictConvertor.java} (81%) create mode 100644 designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java create mode 100644 designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java diff --git a/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java b/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java new file mode 100644 index 0000000000..5a524e5b56 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java @@ -0,0 +1,172 @@ +package com.fr.env.detect; + +import com.fr.design.components.notification.NotificationDialog; +import com.fr.design.components.notification.NotificationDialogProperties; +import com.fr.design.components.notification.NotificationModel; +import com.fr.design.constants.DesignerLaunchStatus; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.ui.util.UIUtil; +import com.fr.env.detect.base.DetectorBridge; +import com.fr.env.detect.base.DetectorUtil; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorStatus; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.event.Null; +import com.fr.start.server.EmbedServerEvent; +import com.fr.update.delay.DelayHelper; +import com.fr.workspace.Workspace; +import com.fr.workspace.WorkspaceEvent; + +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * created by Harrison on 2022/05/27 + **/ +public class EnvDetectorCenter { + + public static EnvDetectorCenter getInstance() { + return EnvDetectorCenterHolder.INSTANCE; + } + + private static class EnvDetectorCenterHolder { + private static final EnvDetectorCenter INSTANCE = new EnvDetectorCenter(); + } + + private final AtomicReference PROCESS = new AtomicReference<>(); + + public void init() { + + // 默认是启动 + PROCESS.set(DetectorProcess.DESIGN_LAUNCH); + start(); + + // 添加启动完成监听 + EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, new Listener() { + @Override + public void on(Event event, Null param) { + if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { + stop(); + } + } + }); + + // 切换工作目录 + EventDispatcher.listen(WorkspaceEvent.BeforeSwitch, new Listener() { + @Override + public void on(Event event, Workspace param) { + PROCESS.set(DetectorProcess.ENV_SWITCH); + start(); + } + }); + EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener() { + @Override + public void on(Event event, Workspace param) { + if (isSameProcess(DetectorProcess.ENV_SWITCH)) { + stop(); + } + } + }); + + // 打开内置服务器 + EventDispatcher.listen(EmbedServerEvent.BeforeStart, new Listener() { + @Override + public void on(Event event, Null param) { + PROCESS.set(DetectorProcess.SERVER_LAUNCH); + start(); + } + }); + EventDispatcher.listen(EmbedServerEvent.AfterStart, new Listener() { + @Override + public void on(Event event, Null param) { + if (isSameProcess(DetectorProcess.SERVER_LAUNCH)) { + stop(); + } + } + }); + + } + + /** + * 当前的流程符合预期 + * 什么情况下不符合? + * design.start -> server.start -> design.end -> server.end + * 这个时候 design.end 就不会触发,等待服务器启动后才触发 + * + * @param process 检测流程 + * @return 是 / 否 + */ + private boolean isSameProcess(DetectorProcess process) { + + return PROCESS.compareAndSet(process, null); + } + + public void start() { + + DetectorBridge.getInstance().start(); + } + + public void stop() { + + Stream resultStream = DetectorBridge.getInstance().detect(); + + // 展示效果 + NotificationDialogProperties properties = new NotificationDialogProperties(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); + List notificationModels = resultStream + .filter(Objects::nonNull) + .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) + .map(DetectorUtil::convert2Notification) + .collect(Collectors.toList()); + + // 一分钟后执行 + DelayHelper.delayCall(EnvDetectorCenter.class.getName(), () -> { + UIUtil.invokeLaterIfNeeded(() -> { + NotificationDialog dialog = new NotificationDialog(properties, notificationModels); + dialog.open(); + }); + }, 1, TimeUnit.MINUTES); + + // 结束 + DetectorBridge.getInstance().stop(); + } + + /** + * 使用预期外的错误进行展示 + * + * @param throwable 异常 + * @return + */ + public List terminate(Throwable throwable) { + + Stream resultStream = DetectorBridge.getInstance().detect(throwable); + List results = resultStream + .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) + .collect(Collectors.toList()); + return results; + } + + private enum DetectorProcess { + + /** + * 设计器启动 + */ + DESIGN_LAUNCH, + + /** + * 服务器启动 + */ + SERVER_LAUNCH, + + /** + * 环境切换 + */ + ENV_SWITCH + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java b/designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java index 3eeac6e461..0dbce9c003 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java @@ -50,6 +50,6 @@ public abstract class CatchExceptionDetector extends AbstractExceptionDetector { return result; } } - return null; + return DetectorResult.normal(type()); } } diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java index 031df59a2c..534fa7abff 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java @@ -13,7 +13,6 @@ import com.fr.env.detect.thowable.ThrowableStore; import com.fr.value.NotNullLazyValue; import org.jetbrains.annotations.NotNull; -import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; @@ -54,7 +53,7 @@ public class DetectorBridge { public void start() { - if (ExceptionDetectorConfig.getInstance().isOpen()) { + if (!hasStarted.get() && ExceptionDetectorConfig.getInstance().isOpen()) { // 开始注册异常处理 ThrowableLogAppender.getInstance().enable(); hasStarted.set(true); @@ -76,11 +75,33 @@ public class DetectorBridge { * @param type 检测类型 * @return 检测结果 */ - public Optional detect(DetectorType type) { + @NotNull + public DetectorResult detect(DetectorType type) { return detectorManager.getValue().detect(type); } + /** + * 针对某一项 \ 某一个异常进行检测 + * + * @param type 类型 + * @param throwable 异常 + * @return 结果 + */ + @NotNull + public DetectorResult detect(DetectorType type, Throwable throwable) { + + // 先清理一下 + ThrowableStore.getInstance().reset(); + + ThrowableStore.getInstance().add(throwable); + DetectorResult result = detect(type); + ThrowableStore.getInstance().reset(); + + return result; + + } + /** * 异常检测 * 对异常统一检测 diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java index 76c2d2dd18..ced5021297 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java @@ -34,7 +34,7 @@ class DetectorManager { return results; } - public Optional detect(DetectorType type) { + public DetectorResult detect(DetectorType type) { Optional result = detectors.stream() .filter((detector -> type == detector.type())) @@ -44,6 +44,6 @@ class DetectorManager { // 记录日志 result.ifPresent(DetectorResult::log); - return result; + return result.orElse(DetectorResult.normal(type)); } } diff --git a/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java b/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java index 33aa0e98fe..12c51d19b0 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/DetectorUtil.java @@ -1,7 +1,28 @@ package com.fr.env.detect.base; +import com.fr.base.function.ThrowableRunnable; +import com.fr.design.components.notification.NotificationAction; +import com.fr.design.components.notification.NotificationMessage; +import com.fr.design.components.notification.NotificationModel; +import com.fr.design.components.notification.NotificationType; +import com.fr.design.dialog.link.MessageWithLink; +import com.fr.design.gui.ilable.UILabel; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.ExceptionSolution; +import com.fr.env.detect.bean.ExceptionTips; +import com.fr.env.detect.bean.Message; +import com.fr.env.detect.bean.SolutionAction; import com.fr.general.build.BuildInfo; import com.fr.stable.StringUtils; +import org.jetbrains.annotations.NotNull; + +import javax.swing.JComponent; +import java.awt.Desktop; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; /** * created by Harrison on 2022/05/25 @@ -12,5 +33,67 @@ public class DetectorUtil { return StringUtils.contains(info.getJar(), "fine-report-designer"); } - + + public static NotificationModel convert2Notification(DetectorResult result) { + + List messages = new ArrayList<>(); + + Function> convert2NotificationMsg = message -> { + + NotificationMessage notificationMessage = null; + if (message != null) { + Message.Type type = message.getType(); + switch (type) { + case SIMPLE: + notificationMessage = (new NotificationMessage.SimpleMessage(message.get())); + break; + case LINK: + Message.Link linkMsg = (Message.Link) message; + notificationMessage = new NotificationMessage.LinkMessage(linkMsg.getText(), linkMsg.getLink()); + break; + default: + break; + } + } + return Optional.ofNullable(notificationMessage); + }; + + ExceptionTips tips = result.getTips(); + convert2NotificationMsg + .apply(tips.getMessage()) + .ifPresent(messages::add); + + ExceptionSolution solution = result.getSolution(); + convert2NotificationMsg.apply(solution.getMessage()) + .ifPresent(messages::add); + + NotificationAction notificationAction = null; + SolutionAction solutionAction = solution.getAction(); + if (solutionAction != null) { + notificationAction = new NotificationAction() { + @Override + public String name() { + return solutionAction.name(); + } + + @Override + public void run(Object... args) { + solutionAction.run(); + } + }; + } + + return new NotificationModel(NotificationType.WARNING, notificationAction, messages); + } + + public static JComponent convert2Component(@NotNull Message message) { + + if (message.getType() == Message.Type.LINK) { + Message.Link linkMsg = (Message.Link) message; + return new MessageWithLink(linkMsg.getText(), ThrowableRunnable.toRunnable(() -> { + Desktop.getDesktop().browse(URI.create(linkMsg.getLink())); + })); + } + return new UILabel(message.get()); + } } diff --git a/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java b/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java index 489d5e3113..724e5e8d36 100644 --- a/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java +++ b/designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java @@ -1,21 +1,34 @@ package com.fr.env.detect.base; +import com.fr.config.ConfigContext; +import com.fr.config.DefaultConfiguration; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; + /** * created by Harrison on 2022/05/13 **/ -public class ExceptionDetectorConfig { +public class ExceptionDetectorConfig extends DefaultConfiguration { + private static volatile ExceptionDetectorConfig instance = null; public static ExceptionDetectorConfig getInstance() { - return ExceptionDetectorConfigHolder.INSTANCE; + + if (instance == null) { + instance = ConfigContext.getConfigInstance(ExceptionDetectorConfig.class); + } + return instance; } - private static class ExceptionDetectorConfigHolder { - private static final ExceptionDetectorConfig INSTANCE = new ExceptionDetectorConfig(); + private final Conf open = Holders.simple(true); + + public void setOpen(boolean open) { + + this.open.set(open); } public boolean isOpen() { - return true; + return open.get(); } } diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java index aadccd0911..2b45ecbc1e 100644 --- a/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java +++ b/designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java @@ -1,5 +1,7 @@ package com.fr.env.detect.bean; +import org.jetbrains.annotations.Nullable; + /** * 检测结果 * @@ -51,10 +53,12 @@ public class DetectorResult { return type; } + @Nullable public ExceptionTips getTips() { return tips; } + @Nullable public ExceptionSolution getSolution() { return solution; } diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java index 796d78c8dd..b4f549f679 100644 --- a/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java +++ b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java @@ -12,6 +12,11 @@ public class ExceptionSolution { @Nullable private SolutionAction action; + public static ExceptionSolution create(String text, String link, SolutionAction action) { + + return new ExceptionSolution(new Message.Link(text, link), action); + } + public ExceptionSolution(Message message, @Nullable SolutionAction action) { this.message = message; this.action = action; diff --git a/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java index 970bca989d..b7ab6c63fa 100644 --- a/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java +++ b/designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java @@ -9,6 +9,11 @@ public class ExceptionTips { private Message message; + public static ExceptionTips create(String text) { + + return new ExceptionTips(new Message.Simple(text)); + } + public ExceptionTips(Message message) { this.message = message; } diff --git a/designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java b/designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java deleted file mode 100644 index 14adcab292..0000000000 --- a/designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.fr.env.detect.exception; - -/** - * created by Harrison on 2022/05/25 - **/ -public class DetectorException extends RuntimeException { - - public DetectorException() { - } - - public DetectorException(String message) { - super(message); - } - - public DetectorException(String message, Throwable cause) { - super(message, cause); - } - - public DetectorException(Throwable cause) { - super(cause); - } - - public DetectorException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/designer-base/src/main/java/com/fr/env/detect/exception/intelli/package-info.java b/designer-base/src/main/java/com/fr/env/detect/exception/intelli/package-info.java deleted file mode 100644 index f11ad3f7eb..0000000000 --- a/designer-base/src/main/java/com/fr/env/detect/exception/intelli/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 国际化相关的异常 - */ -package com.fr.env.detect.exception.intelli; \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java index 39a3bc4e0b..2eb38d94ef 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarConflictDetector.java @@ -2,7 +2,7 @@ package com.fr.env.detect.impl; import com.fr.env.detect.base.CatchExceptionDetector; import com.fr.env.detect.bean.DetectorType; -import com.fr.env.detect.impl.converter.ClassConfictConvertor; +import com.fr.env.detect.impl.converter.ClassConflictConvertor; /** * created by Harrison on 2022/05/26 @@ -10,6 +10,6 @@ import com.fr.env.detect.impl.converter.ClassConfictConvertor; public class JarConflictDetector extends CatchExceptionDetector { public JarConflictDetector() { - super(DetectorType.JAR_CONFLICT, new ClassConfictConvertor()); + super(DetectorType.JAR_CONFLICT, new ClassConflictConvertor()); } } diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java index dfb880a9e1..6012be3d36 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java @@ -19,6 +19,7 @@ import com.fr.third.guava.collect.MapDifference; import com.fr.third.guava.collect.Maps; import com.fr.third.org.apache.commons.lang3.StringUtils; import com.fr.workspace.WorkContext; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.List; @@ -50,76 +51,86 @@ public class JarInconsistentDetector extends AbstractExceptionDetector { public DetectorResult detect() { if (WorkContext.getCurrent().isLocal()) { - - // 本地的获取方式 - BuildInfoOperator operator = new BuildInfoOperatorImpl(); - List buildInfos = operator.getBuildInfos(); - - // 获取设计器的 build - Optional designerBuild = buildInfos.stream() - .filter(DetectorUtil::isDesignerJar) - .map(BuildInfo::getGroupBuild) - .filter(StringUtils::isNotEmpty) - .findFirst(); - - // 如果 build - if (!designerBuild.isPresent()) { - return DetectorResult.normal(type()); - } - - // 获取所有的不一致的 build - List inConsistentInfos = buildInfos.stream() - .filter((e) -> !StringUtils.equals(designerBuild.get(), e.getGroupBuild())) - .collect(Collectors.toList()); - - // 没有直接返回 - if (Collections.isEmpty(inConsistentInfos)) { - return DetectorResult.normal(type()); - } - - // 有的话 - List inConsistentJars = inConsistentInfos.stream() - .map(BuildInfo::getJar) - .collect(Collectors.toList()); - String message = StringUtils.join(",", inConsistentJars); - String tipsMessage = Toolkit.i18nText("Fine_Design_Basic_Detect_Local") + Toolkit.i18nText(type().getTipsLocale()) + "\n" + message; - - return DetectorResult.exception(type(), - new ExceptionTips(new Message.Simple(tipsMessage)), - new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null), - ExceptionLog.create(type().getLogLocale() + message)); + return detectLocal(); } else { - - // 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包 - BuildInfoOperator buildInfoOperator = WorkContext.getCurrent().get(BuildInfoOperator.class); - List buildInfos = buildInfoOperator.getBuildInfos(); - - // 远程情况 - List localInfos = BuildInfoManager.getInstance().getInfos(); - Map localMap = groupBy(localInfos); - - List remoteInfos = buildInfos; - Map remoteMap = groupBy(remoteInfos); - - MapDifference difference = Maps.difference(localMap, remoteMap); - Map diffInCommon = difference.entriesInCommon(); - - if (diffInCommon.isEmpty()) { - return DetectorResult.normal(type()); - } - - Set inConsistentJars = diffInCommon.keySet(); - - String message = StringUtils.join(",", inConsistentJars); - Message.Simple tipsMessage = new Message.Simple(Toolkit.i18nText("Fine_Design_Basic_Detect_Server") + Toolkit.i18nText(type().getTipsLocale()) + "\n" + message); + return detectLocalAndRemote(); + } + } - return DetectorResult.exception(type(), - new ExceptionTips(tipsMessage), - new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null), - ExceptionLog.create(type().getLogLocale() + message)); + @NotNull + private DetectorResult detectLocalAndRemote() { + + // 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包 + BuildInfoOperator buildInfoOperator = WorkContext.getCurrent().get(BuildInfoOperator.class); + List buildInfos = buildInfoOperator.getBuildInfos(); + + // 远程情况 + List localInfos = BuildInfoManager.getInstance().getInfos(); + Map localMap = groupBy(localInfos); + + List remoteInfos = buildInfos; + Map remoteMap = groupBy(remoteInfos); + + MapDifference difference = Maps.difference(localMap, remoteMap); + Map diffInCommon = difference.entriesInCommon(); + + if (diffInCommon.isEmpty()) { + return DetectorResult.normal(type()); } + + Set inConsistentJars = diffInCommon.keySet(); + + String message = StringUtils.join(",", inConsistentJars); + Message.Simple tipsMessage = new Message.Simple(Toolkit.i18nText("Fine_Design_Basic_Detect_Server") + Toolkit.i18nText(type().getTipsLocale()) + "\n" + message); + + return DetectorResult.exception(type(), + new ExceptionTips(tipsMessage), + new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale(),DetectorConstants.JAR_HELP_LINK) + , DetectorConstants.JAR_HELP_LINK), null), + ExceptionLog.create(type().getLogLocale() + message)); + } + @NotNull + private DetectorResult detectLocal() { + + // 本地的获取方式 + BuildInfoOperator operator = new BuildInfoOperatorImpl(); + List buildInfos = operator.getBuildInfos(); + + // 获取设计器的 build + Optional designerBuild = buildInfos.stream() + .filter(DetectorUtil::isDesignerJar) + .map(BuildInfo::getGroupBuild) + .filter(StringUtils::isNotEmpty) + .findFirst(); + + // 如果 build + if (!designerBuild.isPresent()) { + return DetectorResult.normal(type()); + } + + // 获取所有的不一致的 build + List inConsistentInfos = buildInfos.stream() + .filter((e) -> !StringUtils.equals(designerBuild.get(), e.getGroupBuild())) + .collect(Collectors.toList()); + + // 没有直接返回 + if (Collections.isEmpty(inConsistentInfos)) { + return DetectorResult.normal(type()); + } + + // 有的话 + List inConsistentJars = inConsistentInfos.stream() + .map(BuildInfo::getJar) + .collect(Collectors.toList()); + String message = StringUtils.join(",", inConsistentJars); + String tipsMessage = Toolkit.i18nText("Fine_Design_Basic_Detect_Local") + Toolkit.i18nText(type().getTipsLocale()) + "\n" + message; + + return DetectorResult.exception(type(), + new ExceptionTips(new Message.Simple(tipsMessage)), + new ExceptionSolution(new Message.Link(Toolkit.i18nText(type().getSolutionLocale()), DetectorConstants.JAR_HELP_LINK), null), + ExceptionLog.create(type().getLogLocale() + message)); } private Map groupBy(List localInfos) { diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java b/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java index 654029da7c..2175b8bb1e 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java @@ -15,14 +15,11 @@ import com.fr.general.build.BuildInfo; import com.fr.general.build.BuildInfoOperator; import com.fr.general.build.impl.BuildInfoOperatorImpl; import com.fr.locale.InterProviderFactory; -import com.fr.stable.CommonUtils; -import com.fr.stable.StableUtils; import com.fr.third.guava.collect.Lists; import com.fr.third.org.apache.commons.lang3.StringUtils; import com.fr.workspace.WorkContext; import org.jetbrains.annotations.NotNull; -import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -81,9 +78,8 @@ public class JarLackDetector extends AbstractExceptionDetector { private Message tipsMessage(List infos) { - String installHome = StableUtils.getInstallHome(); - String homeLibPath = installHome + File.pathSeparator + "lib"; - String webLibPath = CommonUtils.join(new String[]{installHome, "webapps", "webroot", "WEB-INF", "lib"}, File.pathSeparator); + String webLibPath = "%FR_HOME%\\webapps\\webroot\\WEB-INF\\lib:"; + String homeLibPath = "%FR_HOME%\\lib:"; Map> libMap = groupByPath(infos, homeLibPath, webLibPath); diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConfictConvertor.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java similarity index 81% rename from designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConfictConvertor.java rename to designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java index f2c8c5b758..4fa33f3018 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConfictConvertor.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java @@ -1,6 +1,13 @@ package com.fr.env.detect.impl.converter; +import com.fr.common.util.Strings; +import com.fr.design.i18n.Toolkit; +import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; +import com.fr.env.detect.bean.ExceptionLog; +import com.fr.env.detect.bean.ExceptionSolution; +import com.fr.env.detect.bean.ExceptionTips; import com.fr.env.detect.thowable.ThrowableConverter; import com.fr.stable.resource.ResourceLoader; @@ -24,13 +31,16 @@ import java.util.regex.Pattern; * * created by Harrison on 2022/05/24 **/ -public class ClassConfictConvertor implements ThrowableConverter { +public class ClassConflictConvertor implements ThrowableConverter { private Map, ClassNameConverter> throwableMap = new HashMap<>(); - private static final Pattern JAR_PATTERN = Pattern.compile("([\\w+-\\.]*\\.jar)"); + /** + * 获取对应的 JAR 包名称 + */ + private static final Pattern JAR_NAME_PATTERN = Pattern.compile("([\\w+-\\.]*\\.jar)"); - public ClassConfictConvertor() { + public ClassConflictConvertor() { // 类异常 this.throwableMap.put(ClassNotFoundException.class, Converter.CLASS); @@ -70,6 +80,7 @@ public class ClassConfictConvertor implements ThrowableConverter { sign = sign.getCause(); } + Set allPath = new HashSet<>(); for (String className : classNames) { String classFile = "/" + className.replaceAll("\\.", "/") + ".class"; try { @@ -79,10 +90,9 @@ public class ClassConfictConvertor implements ThrowableConverter { URL url = urls.nextElement(); urlList.add(url); } - Set allPath = new HashSet<>(); for (URL url : urlList) { String file = url.getFile(); - Matcher matcher = JAR_PATTERN.matcher(url.getFile()); + Matcher matcher = JAR_NAME_PATTERN.matcher(url.getFile()); if (matcher.find()) { String jar = matcher.group(); allPath.add(jar); @@ -93,11 +103,17 @@ public class ClassConfictConvertor implements ThrowableConverter { } } } - } catch (IOException ignore) { } } - return null; + + String msg = Strings.join("、", allPath); + + DetectorType type = DetectorType.JAR_CONFLICT; + return DetectorResult.exception(type, + ExceptionTips.create(Toolkit.i18nText(type.getTipsLocale()) + msg), + ExceptionSolution.create(Toolkit.i18nText(type.getSolutionLocale()), DetectorConstants.JAR_HELP_LINK, null), + ExceptionLog.create(Toolkit.i18nText(type.getLogLocale()), msg)); } private interface ClassNameConverter { diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java index f61d16913c..fe114b253e 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java @@ -2,6 +2,7 @@ package com.fr.env.detect.impl.converter; import com.fr.config.ConfigContext; import com.fr.config.Configuration; +import com.fr.design.dialog.FineJOptionPane; import com.fr.design.i18n.Toolkit; import com.fr.env.detect.base.DetectorConstants; import com.fr.env.detect.bean.DetectorResult; @@ -10,9 +11,14 @@ import com.fr.env.detect.bean.ExceptionSolution; import com.fr.env.detect.bean.Message; import com.fr.env.detect.bean.SolutionAction; import com.fr.env.detect.thowable.ThrowableConverter; +import com.fr.io.utils.ResourceIOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StableUtils; +import com.fr.stable.project.ProjectConstants; import com.fr.third.org.hibernate.exception.GenericJDBCException; import org.jetbrains.annotations.Nullable; +import javax.swing.JOptionPane; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -68,16 +74,29 @@ public class FineDbDirtyConverter implements ThrowableConverter { String tipsLocale = Toolkit.i18nText(detectorType.getTipsLocale(), tableName); String solutionLocale = detectorType.getSolutionLocale(); - ExceptionSolution exceptionSolution = new ExceptionSolution(new Message.Link(solutionLocale, DetectorConstants.FINE_DB_HELP_LINK), new SolutionAction() { + ExceptionSolution exceptionSolution = new ExceptionSolution(new Message.Link(Toolkit.i18nText(solutionLocale, DetectorConstants.FINE_DB_HELP_LINK), DetectorConstants.FINE_DB_HELP_LINK), new SolutionAction() { @Override public String name() { - // todo - return null; + return Toolkit.i18nText("Fine-Design_Basic_Reset_Immediately"); } @Override public void run() { - + boolean success = false; + try { + ResourceIOUtils.copy(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME), + StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_BAK_NAME)); + success = ResourceIOUtils.delete(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME)); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + if (!success) { + FineJOptionPane.showMessageDialog(null, + Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset_Result", + ResourceIOUtils.getRealPath(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME))), + Toolkit.i18nText("Fine-Design_Basic_Error"), + JOptionPane.ERROR_MESSAGE); + } } }); builder.withTips(tipsLocale) diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java index 09cc9b62f8..22f600104d 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java @@ -47,7 +47,7 @@ public class FineDbLockedConverter implements ThrowableConverter { return DetectorResult.builder() .withType(type) .withTips(Toolkit.i18nText(type.getTipsLocale())) - .withSolution(Toolkit.i18nText(type.getSolutionLocale()), DetectorConstants.FINE_DB_HELP_LINK) + .withSolution(Toolkit.i18nText(type.getSolutionLocale(),DetectorConstants.FINE_DB_HELP_LINK), DetectorConstants.FINE_DB_HELP_LINK) .withLog(Toolkit.i18nText(type.getLogLocale())) .build(); } diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java index 8052f81648..00775706dd 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java @@ -42,7 +42,8 @@ public class FineDbPermissionConverter implements ThrowableConverter { return DetectorResult.builder() .withType(type) .withTips(Toolkit.i18nText(type.getTipsLocale())) - .withSolution(Toolkit.i18nText(type.getSolutionLocale()), DetectorConstants.FINE_DB_HELP_LINK) + .withSolution(Toolkit.i18nText(type.getSolutionLocale(), DetectorConstants.FINE_DB_HELP_LINK), + DetectorConstants.FINE_DB_HELP_LINK) .withLog(type.getLogLocale()) .build(); } diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java b/designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java new file mode 100644 index 0000000000..96e8dfa3f8 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/ui/DetectorErrorDialog.java @@ -0,0 +1,135 @@ +package com.fr.env.detect.ui; + +import com.fr.design.RestartHelper; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.VerticalFlowLayout; +import com.fr.design.utils.ColorUtils; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.env.detect.base.DetectorUtil; +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.ExceptionSolution; +import com.fr.env.detect.bean.ExceptionTips; +import com.fr.env.detect.bean.Message; +import com.fr.exit.DesignerExiter; +import com.fr.general.FRFont; + +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +/** + * 未知错误框 + * todo 其实这里可以将多个 error-dialog 抽象在一起的。 时间不够, 简单写写 + * + * created by Harrison on 2022/05/29 + **/ +public class DetectorErrorDialog extends JDialog implements ActionListener { + + private UIButton okButton; + private UIButton restartButton; + + public DetectorErrorDialog(Frame parent, List results) { + + super(parent, true); + + JPanel northPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel messagePane = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true); + + UILabel boldHeader = new UILabel(Toolkit.i18nText("Fine-Design_Error_Start_Apology_Message")); + Font font = FRFont.getInstance(boldHeader.getFont().getFontName(), Font.BOLD, 20); + boldHeader.setFont(font); + messagePane.add(boldHeader); + + UILabel description = new UILabel(Toolkit.i18nText("Fine-Design_Send_Report_To_Us")); + messagePane.add(description); + northPane.add(messagePane); + + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + + UILabel detailDesc = new UILabel(Toolkit.i18nText("Fine-Design_Problem_Detail_Message")); + centerPane.add(detailDesc, BorderLayout.NORTH); + + JPanel detailPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, VerticalFlowLayout.TOP, 0, 10); + detailPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 10, 10)); + + for (DetectorResult result : results) { + ExceptionTips tips = result.getTips(); + if (tips != null) { + Message tipsMsg = tips.getMessage(); + detailPanel.add(DetectorUtil.convert2Component(tipsMsg)); + } + ExceptionSolution solution = result.getSolution(); + if (solution != null) { + Message solutionMsg = solution.getMessage(); + detailPanel.add(DetectorUtil.convert2Component(solutionMsg)); + } + } + + JScrollPane detailPanelWrapper = new JScrollPane(detailPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + ColorUtils.syncBackground(detailPanelWrapper, Color.WHITE); + centerPane.add(detailPanelWrapper, BorderLayout.CENTER); + + JPanel southPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + okButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Ok")); + okButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + okEvent(); + } + }); + buttonPane.add(okButton); + restartButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Restart")); + restartButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + restartEvent(); + } + }); + buttonPane.add(restartButton); + controlPane.add(buttonPane, BorderLayout.EAST); + southPane.add(controlPane); + + this.setTitle(Toolkit.i18nText("Fine-Design_Error_Start_Report")); + this.setResizable(false); + this.add(northPane, BorderLayout.NORTH); + this.add(centerPane, BorderLayout.CENTER); + this.add(southPane, BorderLayout.SOUTH); + this.setSize(new Dimension(600, 500)); + GUICoreUtils.centerWindow(this); + + } + + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + + protected void okEvent() { + + dispose(); + DesignerExiter.getInstance().execute(); + } + + protected void restartEvent() { + + dispose(); + RestartHelper.restart(); + } + +} diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java index d5a0c45eac..a5cea13235 100644 --- a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorDialog.java @@ -1,12 +1,9 @@ package com.fr.env.detect.ui; import com.fr.base.svg.IconUtils; -import com.fr.design.components.notification.NotificationAction; import com.fr.design.components.notification.NotificationDialog; import com.fr.design.components.notification.NotificationDialogProperties; -import com.fr.design.components.notification.NotificationMessage; import com.fr.design.components.notification.NotificationModel; -import com.fr.design.components.notification.NotificationType; import com.fr.design.components.table.TablePanel; import com.fr.design.constants.DesignerColor; import com.fr.design.gui.ibutton.UIButton; @@ -19,14 +16,11 @@ import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.env.detect.base.DetectorBridge; +import com.fr.env.detect.base.DetectorUtil; +import com.fr.env.detect.base.ExceptionDetectorConfig; import com.fr.env.detect.bean.DetectorResult; import com.fr.env.detect.bean.DetectorStatus; import com.fr.env.detect.bean.DetectorType; -import com.fr.env.detect.bean.ExceptionSolution; -import com.fr.env.detect.bean.ExceptionTips; -import com.fr.env.detect.bean.Message; -import com.fr.env.detect.bean.SolutionAction; -import com.fr.third.guava.collect.Lists; import org.jetbrains.annotations.NotNull; import javax.swing.BorderFactory; @@ -45,15 +39,10 @@ import java.awt.Image; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.concurrent.TimeUnit; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -63,6 +52,7 @@ import java.util.stream.Stream; public class EnvDetectorDialog extends JDialog { private static final ImageIcon LOADING_ICON = getLoadingIcon(); + public static final int TIMEOUT = 1000; private JPanel body; @@ -74,7 +64,7 @@ public class EnvDetectorDialog extends JDialog { /* 数据 model */ - private EnvDetectorModel model = new EnvDetectorModel(); + private EnvDetectorModel model; /* 流程 model */ @@ -87,11 +77,25 @@ public class EnvDetectorDialog extends JDialog { private SwingWorker detectWorker = null; + /* config model */ + + private boolean detectOpen = ExceptionDetectorConfig.getInstance().isOpen(); + public EnvDetectorDialog(Frame owner) { + this(owner, null); + } + + public EnvDetectorDialog(Frame owner, EnvDetectorModel model) { super(owner); configProperties(); + if (model == null) { + this.model = new EnvDetectorModel(); + } else { + this.model = model; + } + this.body = FRGUIPaneFactory.createBorderLayout_L_Pane(); Color backgroundColor = new Color(240, 240, 243, 1); this.body.setBackground( backgroundColor); @@ -116,6 +120,8 @@ public class EnvDetectorDialog extends JDialog { GUICoreUtils.centerWindow(this); } + + /* header */ @NotNull private JPanel createHeaderPanel() { @@ -184,12 +190,13 @@ public class EnvDetectorDialog extends JDialog { DetectorType type = item.getType(); // 执行检测, UI-当前在检测中 - Optional detect = UIUtil.waitUntil( + DetectorResult result = UIUtil.waitUntil( () -> DetectorBridge.getInstance().detect(type), - 1000, TimeUnit.MILLISECONDS); - // 获取结果,更新UI - detect.ifPresent(item::setResult); + TIMEOUT, TimeUnit.MILLISECONDS); + // 获取结果 + item.setResult(result); + // 更新UI // 只有还在运行中,才会真正的刷新面板 if (buttonStatus.isExecuting()) { // 在刷新一下面板 @@ -231,6 +238,8 @@ public class EnvDetectorDialog extends JDialog { }); } + /* table */ + @NotNull private TablePanel createTablePanel() { @@ -285,19 +294,6 @@ public class EnvDetectorDialog extends JDialog { } } - private static ImageIcon getLoadingIcon() { - - URL resource = EnvDetectorDialog.class.getResource("/com/fr/design/standard/loading/loading-120.gif"); - if (resource == null) { - return null; - } - ImageIcon loadingIcon = new ImageIcon(resource); - int width = 16; - int height = 16; - loadingIcon.setImage(loadingIcon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT)); - return loadingIcon; - } - private Component createResultComponent(DetectorResult result) { JPanel statusPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); @@ -305,89 +301,43 @@ public class EnvDetectorDialog extends JDialog { statusPanel.add(new UILabel(IconUtils.readIcon("/com/fr/design/standard/reminder/reminder_success.svg")), BorderLayout.WEST); statusPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Normal")), BorderLayout.CENTER); } else { - statusPanel.add(new UILabel(IconUtils.readIcon("/com/fr/design/standard/reminder/reminder_error.svg")), BorderLayout.WEST); - statusPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Exception")), BorderLayout.CENTER); - UILabel detailLabel = new UILabel(Toolkit.i18nText("Fine_Designer_Look_Detail")); - detailLabel.setForeground(new Color(65, 155, 249)); - detailLabel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent mouseEvent) { - NotificationDialogProperties properties = new NotificationDialogProperties((Frame) EnvDetectorDialog.this.getOwner(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); - Stream results = model.getResults(); - List notificationModels = results - .filter(Objects::nonNull) - .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) - .map(EnvDetectorDialog.this::convertDetectorResult) - .collect(Collectors.toList()); - - NotificationDialog dialog = new NotificationDialog(properties, notificationModels); - dialog.open(); - } - }); - statusPanel.add(detailLabel); - } - return statusPanel; - } - - private NotificationModel convertDetectorResult(DetectorResult result) { - - List messages = new ArrayList<>(); - - Function> convert2NotificationMsg = message -> { - - NotificationMessage notificationMessage = null; - if (message != null) { - Message.Type type = message.getType(); - switch (type) { - case SIMPLE: - notificationMessage = (new NotificationMessage.SimpleMessage(message.get())); - break; - case LINK: - Message.Link linkMsg = (Message.Link) message; - notificationMessage = new NotificationMessage.LinkMessage(linkMsg.getText(), linkMsg.getLink()); - break; - default: - break; - } + JPanel infoPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + { + infoPanel.add(new UILabel(IconUtils.readIcon("/com/fr/design/standard/reminder/reminder_error.svg")), BorderLayout.WEST); + infoPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Exception")), BorderLayout.CENTER); } - return Optional.ofNullable(notificationMessage); - }; - - ExceptionTips tips = result.getTips(); - convert2NotificationMsg - .apply(tips.getMessage()) - .ifPresent(messages::add); - - ExceptionSolution solution = result.getSolution(); - convert2NotificationMsg.apply(solution.getMessage()) - .ifPresent(messages::add); - - NotificationAction notificationAction = null; - SolutionAction solutionAction = solution.getAction(); - if (solutionAction != null) { - notificationAction = new NotificationAction() { - @Override - public String name() { - return solutionAction.name(); - } - - @Override - public void run(Object... args) { - solutionAction.run(); - } - }; + statusPanel.add(infoPanel, BorderLayout.WEST); + + JPanel detailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + { + detailPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); + UILabel detailLabel = new UILabel(Toolkit.i18nText("Fine_Designer_Look_Detail")); + detailLabel.setForeground(new Color(65, 155, 249)); + detailLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent mouseEvent) { + NotificationDialogProperties properties = new NotificationDialogProperties((Frame) EnvDetectorDialog.this.getOwner(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); + Stream results = model.getResults(); + List notificationModels = results + .filter(Objects::nonNull) + .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) + .map(DetectorUtil::convert2Notification) + .collect(Collectors.toList()); + + NotificationDialog dialog = new NotificationDialog(properties, notificationModels); + dialog.open(); + } + }); + detailPanel.add(detailLabel, BorderLayout.CENTER); + } + + statusPanel.add(detailPanel, BorderLayout.CENTER); } - - return new NotificationModel(NotificationType.WARNING, notificationAction, messages); - } - - private void refresh() { - - updateTable(this.tablePanel); - pack(); - repaint(); + return statusPanel; } + /* tail */ + @NotNull private JPanel createTailPanel() { @@ -397,6 +347,11 @@ public class EnvDetectorDialog extends JDialog { JPanel configPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); { UICheckBox checkBox = new UICheckBox(); + checkBox.setSelected(this.detectOpen); + checkBox.addChangeListener(e -> { + UICheckBox source = (UICheckBox) e.getSource(); + EnvDetectorDialog.this.detectOpen = source.isSelected(); + }); configPanel.add(checkBox, BorderLayout.WEST); UILabel description = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Detect_Switch")); configPanel.add(description, BorderLayout.EAST); @@ -411,7 +366,7 @@ public class EnvDetectorDialog extends JDialog { setVisible(false); dispose(); // 配置处理 - // todo + ExceptionDetectorConfig.getInstance().setOpen(this.detectOpen); }); actionsPanel.add(confirmButton, BorderLayout.WEST); @@ -426,89 +381,33 @@ public class EnvDetectorDialog extends JDialog { return tailPanel; } - private void configProperties() { - - setTitle(Toolkit.i18nText("Fine-Design_Basic_Detect_Title")); - setModal(false); - setFocusable(false); - setAutoRequestFocus(false); - setResizable(false); - } - - /** - * 数据 model - * - * kind-list_item - */ - private class EnvDetectorModel { - - private Map> itemMap = new LinkedHashMap<>(); - - public EnvDetectorModel() { - - itemMap.put(DetectorType.Kind.JAR, Lists.newArrayList(new EnvDetectorItem(DetectorType.LACK_OF_JAR), new EnvDetectorItem(DetectorType.JAR_IN_CONSISTENCE), new EnvDetectorItem(DetectorType.JAR_CONFLICT))); - - itemMap.put(DetectorType.Kind.FINE_DB, Lists.newArrayList(new EnvDetectorItem(DetectorType.FINE_DB_LOCKED), new EnvDetectorItem(DetectorType.FINE_DB_PERMISSION), new EnvDetectorItem(DetectorType.FINE_DB_DIRTY))); - } - - public void update(DetectorType type, DetectorResult result) { + private void refresh() { - List items = itemMap.get(type.getKind()); - items.stream() - .filter((e) -> e.getType() == type) - .findFirst() - .ifPresent((e) -> {e.setResult(result);}); - } - - public Stream getResults() { + updateTable(this.tablePanel); + pack(); + repaint(); + } - return getItems().stream() - .map(EnvDetectorItem::getResult); - } - - public List getItems() { - - return itemMap.values().stream() - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } + private static ImageIcon getLoadingIcon() { - public Map> getItemMap() { - - return this.itemMap; + URL resource = EnvDetectorDialog.class.getResource("/com/fr/design/standard/loading/loading-120.gif"); + if (resource == null) { + return null; } - + ImageIcon loadingIcon = new ImageIcon(resource); + int width = 16; + int height = 16; + loadingIcon.setImage(loadingIcon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT)); + return loadingIcon; } - private class EnvDetectorItem { - - private DetectorType type; - - private DetectorResult result; + private void configProperties() { - public EnvDetectorItem(DetectorType detectorType) { - this.type = detectorType; - } - - public DetectorType getType() { - return type; - } - - public String getKind() { - return this.type.getKind().getDescription(); - } - - public String getDescription() { - return this.type.getDescription(); - } - - public DetectorResult getResult() { - return result; - } - - public void setResult(DetectorResult result) { - this.result = result; - } + setTitle(Toolkit.i18nText("Fine-Design_Basic_Detect_Title")); + setModal(false); + setFocusable(false); + setAutoRequestFocus(false); + setResizable(false); } /** diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java new file mode 100644 index 0000000000..6b5b1159c8 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorItem.java @@ -0,0 +1,38 @@ +package com.fr.env.detect.ui; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; + +/** + * created by Harrison on 2022/05/27 + **/ +public class EnvDetectorItem { + + private DetectorType type; + + private DetectorResult result; + + public EnvDetectorItem(DetectorType detectorType) { + this.type = detectorType; + } + + public DetectorType getType() { + return type; + } + + public String getKind() { + return this.type.getKind().getDescription(); + } + + public String getDescription() { + return this.type.getDescription(); + } + + public DetectorResult getResult() { + return result; + } + + public void setResult(DetectorResult result) { + this.result = result; + } +} diff --git a/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java new file mode 100644 index 0000000000..8a698f3c31 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorModel.java @@ -0,0 +1,59 @@ +package com.fr.env.detect.ui; + +import com.fr.env.detect.bean.DetectorResult; +import com.fr.env.detect.bean.DetectorType; +import com.fr.third.guava.collect.Lists; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * created by Harrison on 2022/05/27 + **/ +public class EnvDetectorModel { + + private Map> itemMap = new LinkedHashMap<>(); + + public EnvDetectorModel() { + + itemMap.put(DetectorType.Kind.JAR, Lists.newArrayList(new EnvDetectorItem(DetectorType.LACK_OF_JAR), new EnvDetectorItem(DetectorType.JAR_IN_CONSISTENCE), new EnvDetectorItem(DetectorType.JAR_CONFLICT))); + + itemMap.put(DetectorType.Kind.FINE_DB, Lists.newArrayList(new EnvDetectorItem(DetectorType.FINE_DB_LOCKED), new EnvDetectorItem(DetectorType.FINE_DB_PERMISSION), new EnvDetectorItem(DetectorType.FINE_DB_DIRTY))); + } + + public void update(DetectorType type, DetectorResult result) { + + List items = itemMap.get(type.getKind()); + items.stream() + .filter((e) -> e.getType() == type) + .findFirst() + .ifPresent((e) -> { + e.setResult(result); + }); + } + + public Stream getResults() { + + return getItems().stream() + .map(EnvDetectorItem::getResult); + } + + public List getItems() { + + return itemMap.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + public Map> getItemMap() { + + return this.itemMap; + } + +} + +