Skip to content

Commit

Permalink
Added message queue structure and max limit of simultaneous messages (J…
Browse files Browse the repository at this point in the history
  • Loading branch information
EduRibeiro00 committed Mar 27, 2021
1 parent e18e27e commit 50ab7f7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Queue;
import java.util.StringJoiner;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -67,17 +70,21 @@ public class JabRefDialogService implements DialogService {
public static final int DIALOG_SIZE_LIMIT = 300;

private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration.millis(3000);
private static final int MAX_TOASTS_DISPLAYED = 5;

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefDialogService.class);
private static PreferencesService preferences;

private final Window mainWindow;
private final JFXSnackbar statusLine;
private JFXSnackbarLayout currSnackbarLayout;
private Queue<String> snackbarMsgs;

public JabRefDialogService(Window mainWindow, Pane mainPane, PreferencesService preferences) {
this.mainWindow = mainWindow;
this.statusLine = new JFXSnackbar(mainPane);
JabRefDialogService.preferences = preferences;
this.snackbarMsgs = new LinkedList<>();
}

private FXDialog createDialog(AlertType type, String title, String content) {
Expand Down Expand Up @@ -339,10 +346,16 @@ public void notify(String message) {
LOGGER.info(message);
SnackbarEvent currEvent = statusLine.getCurrentEvent();
if (currEvent == null) {
snackbarMsgs.clear();
snackbarMsgs.add(message);
currSnackbarLayout = new JFXSnackbarLayout(message);
statusLine.fireEvent(new SnackbarEvent(currSnackbarLayout, TOAST_MESSAGE_DISPLAY_TIME));
} else if (currSnackbarLayout != null) {
currSnackbarLayout.setToast(message + "\n\n" + currSnackbarLayout.getToast());
snackbarMsgs.add(message);
while (snackbarMsgs.size() > MAX_TOASTS_DISPLAYED) {
snackbarMsgs.poll();
}
currSnackbarLayout.setToast(String.join("\n\n", snackbarMsgs));
}
}

Expand Down

0 comments on commit 50ab7f7

Please sign in to comment.