Skip to content

Commit c97e096

Browse files
committed
Added link in lonsole to show error details
1 parent 344b787 commit c97e096

File tree

2 files changed

+80
-16
lines changed

2 files changed

+80
-16
lines changed

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/console/log/LogPanel.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.MetadataRetrieveEvent;
1818

1919
import java.awt.*;
20+
import java.util.HashMap;
2021
import java.util.Map;
2122

2223
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.event.QueryParametersRetrievalErrorEvent.PARAMS_ERROR_COMMON_MSG;
23-
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.util.ExceptionWrapper.getCause;
24-
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.util.ExceptionWrapper.truncateString;
24+
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.log.ShowExceptionDetailsFilter.SHOW_DETAILS;
2525
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.util.ExceptionWrapper.wrapExceptionInMeaningMessage;
2626

2727
public class LogPanel implements Disposable {
28-
2928
private ConsoleView log;
29+
private Map<String, String> exceptions = new HashMap<>();
30+
private Map<String, String> causes = new HashMap<>();
3031

3132
public void initialize(GraphConsoleView graphConsoleView, Project project) {
3233
MessageBus messageBus = project.getMessageBus();
@@ -35,6 +36,7 @@ public void initialize(GraphConsoleView graphConsoleView, Project project) {
3536
.createBuilder(project)
3637
.getConsole();
3738
log.addMessageFilter(new GoToTabFilter(log));
39+
log.addMessageFilter(new ShowExceptionDetailsFilter(log, exceptions));
3840

3941
Disposer.register(graphConsoleView, log);
4042
graphConsoleView.getLogTab().add(log.getComponent(), BorderLayout.CENTER);
@@ -109,8 +111,10 @@ public void metadataRefreshSucceed(DataSourceApi nodeDataSource, DataSourceMetad
109111

110112
@Override
111113
public void metadataRefreshFailed(DataSourceApi nodeDataSource, Exception exception) {
112-
error(String.format("DataSource[%s] - metadata refresh failed. Reason: ", nodeDataSource.getName()));
113-
printException(exception);
114+
String prefix = String.format("DataSource[%s] - metadata refresh failed. Reason: ", nodeDataSource.getName());
115+
error(prefix);
116+
String errorMessage = prefix + printException(exception) + "\n";
117+
exceptions.put(errorMessage, exception.getMessage());
114118
newLine();
115119
}
116120
});
@@ -122,40 +126,39 @@ public void metadataRefreshFailed(DataSourceApi nodeDataSource, Exception except
122126
});
123127
}
124128

125-
public void userInput(String message) {
129+
private void userInput(String message) {
126130
log.print(message, ConsoleViewContentType.USER_INPUT);
127131
}
128132

129-
public void printParametersMap(Map<String, Object> parameters) {
133+
private void printParametersMap(Map<String, Object> parameters) {
130134
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
131135
String message = String.format("%s: %s", entry.getKey(), entry.getValue());
132136
log.print(message, ConsoleViewContentType.USER_INPUT);
133137
newLine();
134138
}
135139
}
136140

137-
public void info(String message) {
141+
private void info(String message) {
138142
log.print(message, ConsoleViewContentType.NORMAL_OUTPUT);
139143
}
140144

141145
public void error(String message) {
142146
log.print(message, ConsoleViewContentType.ERROR_OUTPUT);
143147
}
144148

145-
public void printException(Exception exception) {
149+
private String printException(Exception exception) {
150+
String errorMessage;
146151
if (exception.getMessage() != null) {
147-
error(wrapExceptionInMeaningMessage(exception));
152+
errorMessage = wrapExceptionInMeaningMessage(exception) + " " + SHOW_DETAILS;
148153
} else {
149-
error(exception.toString());
154+
errorMessage = exception.toString() + " " + SHOW_DETAILS;
150155
}
156+
error(errorMessage);
151157
newLine();
152-
153-
String cause = getCause(exception);
154-
error(truncateString(cause, 100));
158+
return errorMessage;
155159
}
156160

157-
158-
public void newLine() {
161+
private void newLine() {
159162
log.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
160163
}
161164

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.log;
2+
3+
import com.intellij.execution.filters.Filter;
4+
import com.intellij.execution.filters.HyperlinkInfo;
5+
import com.intellij.execution.ui.ConsoleView;
6+
import com.intellij.icons.AllIcons;
7+
import com.intellij.openapi.ui.popup.JBPopupFactory;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import javax.swing.*;
12+
import java.util.Map;
13+
import java.util.Optional;
14+
15+
public class ShowExceptionDetailsFilter implements Filter {
16+
public static final String SHOW_DETAILS = "Show details";
17+
18+
private ConsoleView log;
19+
private Map<String, String> exceptions;
20+
21+
ShowExceptionDetailsFilter(ConsoleView log, Map<String, String> exceptions) {
22+
this.log = log;
23+
this.exceptions = exceptions;
24+
}
25+
26+
@Nullable
27+
@Override
28+
public Result applyFilter(@NotNull String textLine, int endPoint) {
29+
return createLink(textLine, endPoint, SHOW_DETAILS).orElse(null);
30+
}
31+
32+
private Optional<Filter.Result> createLink(String textLine, int endPoint, String linkText) {
33+
int startPoint = endPoint - textLine.length();
34+
35+
int tabLinkPos = textLine.lastIndexOf(linkText);
36+
if (tabLinkPos > -1) {
37+
HyperlinkInfo showPopup = e -> {
38+
showPopup("Error details", exceptions.get(textLine));
39+
};
40+
Result graphTabLink = new Result(
41+
startPoint + tabLinkPos,
42+
startPoint + tabLinkPos + linkText.length(),
43+
showPopup);
44+
45+
return Optional.of(graphTabLink);
46+
}
47+
return Optional.empty();
48+
}
49+
50+
private void showPopup(String title, String text) {
51+
JBPopupFactory.getInstance()
52+
.createComponentPopupBuilder(
53+
new JLabel(text,
54+
AllIcons.General.Error,
55+
JLabel.LEFT),
56+
log.getComponent())
57+
.setTitle(title)
58+
.createPopup()
59+
.showInFocusCenter();
60+
}
61+
}

0 commit comments

Comments
 (0)