-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented error console in JavaFX #1383
Changes from 1 commit
02d25f1
9b8e932
cf785e5
89ed474
4092ecf
0466d00
221e555
0cbf8ec
cb146de
9b821d7
910d9a9
1b7eccd
0395b2c
d6c8eb1
76d72dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,18 @@ | |
|
||
import net.sf.jabref.gui.FXAlert; | ||
import net.sf.jabref.gui.IconTheme; | ||
import net.sf.jabref.logic.error.LogMessage; | ||
import net.sf.jabref.logic.error.MessageType; | ||
import net.sf.jabref.logic.l10n.Localization; | ||
|
||
import com.airhacks.afterburner.views.FXMLView; | ||
import com.sun.star.lang.IndexOutOfBoundsException; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
|
||
import static org.apache.logging.log4j.Level.ERROR; | ||
import static org.apache.logging.log4j.Level.INFO; | ||
import static org.apache.logging.log4j.Level.WARN; | ||
|
||
public class ErrorConsoleView extends FXMLView { | ||
|
||
|
@@ -44,7 +51,7 @@ public class ErrorConsoleView extends FXMLView { | |
@FXML | ||
private Button createIssueButton; | ||
@FXML | ||
private ListView<LogMessage> allMessages; | ||
private ListView<LogEvent> allMessages; | ||
@FXML | ||
private Label descriptionLabel; | ||
|
||
|
@@ -59,12 +66,14 @@ public void show() { | |
errorConsole.setDialogPane(pane); | ||
errorConsole.setResizable(true); | ||
errorConsole.show(); | ||
Log log = LogFactory.getLog(this.getClass()); | ||
log.error("", new IndexOutOfBoundsException()); | ||
} | ||
|
||
@FXML | ||
private void initialize() { | ||
listViewStyle(); | ||
allMessages.setItems(errorViewModel.getAllMessagesData()); | ||
allMessages.itemsProperty().bind(errorViewModel.allMessagesDataproperty()); | ||
descriptionLabel.setGraphic(IconTheme.JabRefIcon.CONSOLE.getGraphicNode()); | ||
} | ||
|
||
|
@@ -90,38 +99,32 @@ private void closeErrorDialog() { | |
private void listViewStyle() { | ||
// Handler for listCell appearance (example for exception Cell) | ||
allMessages.setCellFactory( | ||
new Callback<ListView<LogMessage>, ListCell<LogMessage>>() { | ||
new Callback<ListView<LogEvent>, ListCell<LogEvent>>() { | ||
@Override | ||
public ListCell<LogMessage> call( | ||
ListView<LogMessage> listView) { | ||
return new ListCell<LogMessage>() { | ||
public ListCell<LogEvent> call( | ||
ListView<LogEvent> listView) { | ||
return new ListCell<LogEvent>() { | ||
|
||
@Override | ||
public void updateItem(LogMessage logMessage, boolean empty) { | ||
public void updateItem(LogEvent logMessage, boolean empty) { | ||
super.updateItem(logMessage, empty); | ||
if (logMessage != null) { | ||
setText(logMessage.getMessage()); | ||
|
||
MessageType prio = logMessage.getPriority(); | ||
switch (prio) { | ||
case EXCEPTION: | ||
getStyleClass().add("exception"); | ||
setGraphic(IconTheme.JabRefIcon.INTEGRITY_FAIL.getGraphicNode()); | ||
break; | ||
case OUTPUT: | ||
getStyleClass().add("output"); | ||
setGraphic(IconTheme.JabRefIcon.INTEGRITY_WARN.getGraphicNode()); | ||
break; | ||
case LOG: | ||
getStyleClass().add("log"); | ||
setGraphic(IconTheme.JabRefIcon.INTEGRITY_INFO.getGraphicNode()); | ||
break; | ||
default: | ||
break; | ||
setText(logMessage.getMessage().toString()); | ||
|
||
Level prio = logMessage.getLevel(); | ||
if (prio.equals(ERROR)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls use a switch statement here and show an info by default (instead of nothing with |
||
getStyleClass().add("exception"); | ||
setGraphic(IconTheme.JabRefIcon.INTEGRITY_FAIL.getGraphicNode()); | ||
} else if (prio.equals(WARN)) { | ||
getStyleClass().add("output"); | ||
setGraphic(IconTheme.JabRefIcon.INTEGRITY_WARN.getGraphicNode()); | ||
} else if (prio.equals(INFO)) { | ||
getStyleClass().add("log"); | ||
setGraphic(IconTheme.JabRefIcon.INTEGRITY_INFO.getGraphicNode()); | ||
} else { | ||
setText(null); | ||
setGraphic(null); | ||
} | ||
} else { | ||
setText(null); | ||
setGraphic(null); | ||
} | ||
} | ||
}; | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
package net.sf.jabref.logic.error; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import javafx.application.Platform; | ||
|
||
import net.sf.jabref.logic.logging.LogMessages; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.impl.Log4jLogEvent; | ||
import org.apache.logging.log4j.message.SimpleMessage; | ||
|
||
/** | ||
* Allows to eavesdrop on an out and an err stream. | ||
* <p/> | ||
* It can be used to listen to any messages to the System.out and System.err. | ||
*/ | ||
public class StreamEavesdropper { | ||
|
||
private final ByteArrayOutputStream errByteStream = new ByteArrayOutputStream(); | ||
private final ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); | ||
|
||
private final PrintStream systemOut; | ||
private final PrintStream systemErr; | ||
|
||
|
@@ -33,40 +34,47 @@ public static StreamEavesdropper eavesdropOnSystem() { | |
return streamEavesdropper; | ||
} | ||
|
||
public TeeStream getOutStream() { | ||
PrintStream consoleOut = new PrintStream(outByteStream) { | ||
/** | ||
* Return a new {@code PrintStream} which also creates a new log event with {@link Level#WARN} for each message and forwards it to the {@link LogMessages} archive. | ||
* @return a PrintStream | ||
*/ | ||
public PrintStream getOutStream() { | ||
return new PrintStream(systemOut) { | ||
@Override | ||
public void write(byte[] buf, int off, int len) { | ||
super.write(buf, off, len); | ||
String message = new String(buf, off, len); | ||
addToLog(message, MessageType.OUTPUT); | ||
addToLog(message, Level.WARN); | ||
} | ||
}; | ||
return new TeeStream(consoleOut, systemOut); | ||
} | ||
|
||
public TeeStream getErrStream() { | ||
PrintStream consoleErr = new PrintStream(errByteStream) { | ||
/** | ||
* Return a new {@code PrintStream} which also creates a new log event with {@link Level#ERROR} for each message and forwards it to the {@link LogMessages} archive. | ||
* @return a PrintStream | ||
*/ | ||
public PrintStream getErrStream() { | ||
return new PrintStream(systemErr) { | ||
@Override | ||
public void write(byte[] buf, int off, int len) { | ||
super.write(buf, off, len); | ||
String message = new String(buf, off, len); | ||
addToLog(message, MessageType.EXCEPTION | ||
); | ||
addToLog(message, Level.ERROR); | ||
} | ||
}; | ||
return new TeeStream(consoleErr, systemErr); | ||
} | ||
|
||
private void addToLog(String s, MessageType priority) { | ||
if (!s.equals(System.lineSeparator())) { | ||
LogMessage messageWithPriority = new LogMessage(s.replaceAll(System.lineSeparator(), ""), priority); | ||
/** | ||
* Creates a new log event with the given parameters and forwards it to the {@link LogMessages} archive. | ||
* @param message message of log event | ||
* @param priority level of log event | ||
*/ | ||
private void addToLog(String message, Level priority) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please go through the code that all |
||
if (!message.equals(System.lineSeparator())) { | ||
String messageFormat = message.replaceAll(System.lineSeparator(), ""); | ||
LogEvent messageWithPriority = Log4jLogEvent.newBuilder().setMessage(new SimpleMessage(messageFormat)).setLevel(priority).build(); | ||
Platform.runLater(() -> LogMessages.getInstance().add(messageWithPriority)); | ||
} | ||
} | ||
|
||
public String getOutput() { | ||
return outByteStream.toString(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was for test purposes, right? Please remove it.