From 39e92164473ea958d7471e5c2da89263e930deb5 Mon Sep 17 00:00:00 2001 From: Ekaterina Chernikova Date: Fri, 28 Feb 2025 15:58:19 +0100 Subject: [PATCH] DBE-15813, DBE-19168: added 'Full Message' button to show a full error message GitOrigin-RevId: 1abfa859bdd0822a5f7a9130bcc1c659919ddb36 --- .../messages/DataGridBundle.properties | 1 + .../src/run/ui/ErrorNotificationPanel.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/grid/core-impl/resources/messages/DataGridBundle.properties b/grid/core-impl/resources/messages/DataGridBundle.properties index e5394794d4ac..5c1ca0c81cee 100644 --- a/grid/core-impl/resources/messages/DataGridBundle.properties +++ b/grid/core-impl/resources/messages/DataGridBundle.properties @@ -16,6 +16,7 @@ grid.delete.selected.row.action.confirmation=One row selected.\nAre you sure you grid.delete.selected.rows.action.confirmation=%s rows selected.\nAre you sure you want to delete the selected rows? grid.delete.selected.row.action.text=Delete Row %s action.details.text=Details +action.full.message.text=Full Message action.close.text=Close tooltip.close.esc=Close (Esc) dialog.title.query.error=Query Error diff --git a/grid/impl/src/run/ui/ErrorNotificationPanel.java b/grid/impl/src/run/ui/ErrorNotificationPanel.java index eb18e6fe1318..f56e5a64c65c 100644 --- a/grid/impl/src/run/ui/ErrorNotificationPanel.java +++ b/grid/impl/src/run/ui/ErrorNotificationPanel.java @@ -135,6 +135,8 @@ public final class ErrorNotificationPanel extends JPanel { private final List> myShowHideHandlers = new ArrayList<>(); private final StringBuilder myHtmlBuilder = new StringBuilder(); + private boolean isChoppedMessage = false; + private MessageType myType = MessageType.ERROR; private Builder(@NlsContexts.NotificationContent @Nullable String message, @Nullable Throwable error, @NotNull JComponent baseComponent) { @@ -204,6 +206,14 @@ public final class ErrorNotificationPanel extends JPanel { new String[]{CommonBundle.getOkButtonText()}, 0, Messages.getErrorIcon(), null)); } + public @NotNull Builder addFullMessageButtonIfNeeded() { + if (!isChoppedMessage) return this; + return addLink("details", DataGridBundle.message("action.full.message.text"), () -> Messages.showIdeaMessageDialog(null, myMessage, + DataGridBundle.message("dialog.title.query.error"), + new String[]{CommonBundle.getOkButtonText()}, 0, Messages.getErrorIcon(), null)); + + } + public @NotNull Builder addCloseButton(Runnable action) { return addIconLink(DataGridBundle.message("action.close.text"), DataGridBundle.message("tooltip.close.esc"), AllIcons.Actions.Close, action); } @@ -225,21 +235,23 @@ public final class ErrorNotificationPanel extends JPanel { myHtmlBuilder.append(""); } - private static @NlsContexts.NotificationContent @NotNull String getNormalizedMessage(@NotNull Throwable error) { + private @NlsContexts.NotificationContent @NotNull String getNormalizedMessage(@NotNull Throwable error) { String sourceMessage = StringUtil.notNullize(error.getMessage(), - DataGridBundle.message("notification.content.unknown.problem.occurred.see.details")); + DataGridBundle.message("notification.content.unknown.problem.occurred.see.details")) + "kgmsdkgmksdfgnmksndfgknskdfgnksndgkndfkgnsdkfgnskdngkndsfgksnkgnfksdngksdnfgksndkgnsdkfgnksdnfgkndkfgnskngfksnkgfnksdnfgksdnfgknsdkgnslgnskldfnglksnfgksnfgksnkfgnksdfngksdnfgksdngksndfgknsdkf"; // In some cases source message contains stacktrace inside. Let's chop it int divPos = sourceMessage.indexOf("\n\tat "); if (divPos != -1) { sourceMessage = sourceMessage.substring(0, divPos); + isChoppedMessage = true; } return getNormalized(sourceMessage); } - private static @NlsContexts.NotificationContent @NotNull String getNormalized(@NlsContexts.NotificationContent @NotNull String sourceMessage) { + private @NlsContexts.NotificationContent @NotNull String getNormalized(@NlsContexts.NotificationContent @NotNull String sourceMessage) { int lineLimit = StringUtil.lineColToOffset(sourceMessage, 5, 0); int charLimit = 1024; int limit = lineLimit == -1 || lineLimit > charLimit ? charLimit : lineLimit; + if (sourceMessage.length() > limit) isChoppedMessage = true; return StringUtil.trimLog(sourceMessage, limit + 1); }