Skip to content

Commit

Permalink
fixes #4610. Changed the way the GroupDialog description is displayed. (
Browse files Browse the repository at this point in the history
#4660)

* Changed the way the GroupDialog description is displayed. It now uses a TextFlow Node to display the stylised text. The string with html tags is parsed and the sections of text within html tags are put in stylised Text Nodes. Rearranged the GroupDialog window, since the window grew larger then the display size. GroupDialog window is no longer resizable. fixes #4610

* Added a check to see if a database is currently open when attempting to create a new group. If no database is open we show a warning to the user. Added a german translation.

* Changed wording of an error message. Databases are nor referred to as libraries.
  • Loading branch information
LeonhardWolz authored and tobiasdiez committed Feb 21, 2019
1 parent 3589dc3 commit 2415c3c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/groups/GroupDescriptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ private GroupDescriptions() {
public static String getDescriptionForPreview(String field, String expr, boolean caseSensitive, boolean regExp) {
String header = regExp ? Localization.lang(
"This group contains entries whose <b>%0</b> field contains the regular expression <b>%1</b>",
field, StringUtil.quoteForHTML(expr)) : Localization.lang(
field, expr) : Localization.lang(
"This group contains entries whose <b>%0</b> field contains the keyword <b>%1</b>",
field, StringUtil.quoteForHTML(expr));
field, expr);
String caseSensitiveText = caseSensitive ? Localization.lang("case sensitive") : Localization
.lang("case insensitive");
String footer = regExp ? Localization
Expand All @@ -30,7 +30,7 @@ public static String getDescriptionForPreview(String field, String expr, boolean
+ "then using the context menu. "
+ "This process removes the term <b>%1</b> from "
+ "each entry's <b>%0</b> field.",
field, StringUtil.quoteForHTML(expr));
field, expr);
return String.format("%s (%s). %s", header, caseSensitiveText, footer);
}

Expand Down
103 changes: 77 additions & 26 deletions src/main/java/org/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.Separator;
import javafx.scene.control.TextField;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
Expand All @@ -26,7 +29,6 @@
import javafx.scene.text.FontPosture;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.scene.web.WebView;

import org.jabref.Globals;
import org.jabref.JabRefGUI;
Expand Down Expand Up @@ -104,7 +106,7 @@ class GroupDialog extends BaseDialog<AbstractGroup> {
private final TextField texGroupFilePath = new TextField();

// for all types
private final WebView descriptionWebView = new WebView();
private final TextFlow descriptionTextFlow = new TextFlow();
private final StackPane optionsPanel = new StackPane();


Expand All @@ -120,7 +122,10 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {

explicitRadioButton.setSelected(true);

descriptionWebView.setPrefWidth(585);
descriptionTextFlow.setMinWidth(585);
descriptionTextFlow.setPrefWidth(585);
descriptionTextFlow.setMinHeight(180);
descriptionTextFlow.setPrefHeight(180);

// set default values (overwritten if editedGroup != null)
keywordGroupSearchField.setText(jabrefFrame.prefs().get(JabRefPreferences.GROUPS_DEFAULT_FIELD));
Expand Down Expand Up @@ -196,26 +201,31 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) {
selectPanel.setPadding(new Insets(0, 0, 0, 10));

// Description panel
ScrollPane descriptionPane = new ScrollPane(descriptionWebView);
ScrollPane descriptionPane = new ScrollPane(descriptionTextFlow);
descriptionPane.setHbarPolicy(ScrollBarPolicy.AS_NEEDED);
descriptionPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);

// create layout
VBox mainPanel = new VBox(15);
HBox mainPanel = new HBox(15);
getDialogPane().setContent(mainPanel);
mainPanel.setPadding(new Insets(5, 15, 5, 15));
mainPanel.getChildren().setAll(
generalPanel,
new VBox(5,
new Label(Localization.lang("Type")),
selectPanel
),
new VBox(
new Label(Localization.lang("Options")),
optionsPanel
generalPanel,
new VBox(5,
new Label(Localization.lang("Type")),
selectPanel
)
),
new Label(Localization.lang("Description")),
descriptionPane
new Separator(Orientation.VERTICAL),
new VBox(5,
new VBox(
new Label(Localization.lang("Options")),
optionsPanel
),
new Label(Localization.lang("Description")),
descriptionPane
)
);

updateComponents();
Expand Down Expand Up @@ -393,6 +403,9 @@ groupName, getContext(),
texGroupFilePath.setText(group.getFilePath().toString());
}
}

setResizable(false);
getDialogPane().getScene().getWindow().sizeToScene();
}

public GroupDialog() {
Expand Down Expand Up @@ -517,7 +530,7 @@ private void updateComponents() {
boolean okEnabled = !nameField.getText().trim().isEmpty();
if (!okEnabled) {
setDescription(Localization.lang("Please enter a name for the group."));
//TODO: okButton.setDisable(true);
getDialogPane().lookupButton(ButtonType.OK).setDisable(true);
return;
}
String s1;
Expand All @@ -532,27 +545,27 @@ private void updateComponents() {
try {
Pattern.compile(s2);
setDescription(GroupDescriptions.getDescriptionForPreview(s1, s2, keywordGroupCaseSensitive.isSelected(),
keywordGroupRegExp.isSelected()));
keywordGroupRegExp.isSelected()));
} catch (PatternSyntaxException e) {
okEnabled = false;
setDescription(formatRegExException(s2, e));
}
} else {
setDescription(GroupDescriptions.getDescriptionForPreview(s1, s2, keywordGroupCaseSensitive.isSelected(),
keywordGroupRegExp.isSelected()));
keywordGroupRegExp.isSelected()));
}
} else {
setDescription(Localization.lang(
"Please enter the field to search (e.g. <b>keywords</b>) and the keyword to search it for (e.g. <b>electrical</b>)."));
"Please enter the field to search (e.g. <b>keywords</b>) and the keyword to search it for (e.g. <b>electrical</b>)."));
}
setNameFontItalic(true);
} else if (searchRadioButton.isSelected()) {
s1 = searchGroupSearchExpression.getText().trim();
okEnabled = okEnabled & !s1.isEmpty();
if (okEnabled) {
setDescription(fromTextFlowToHTMLString(SearchDescribers.getSearchDescriberFor(
new SearchQuery(s1, isCaseSensitive(), isRegex()))
.getDescription()));
new SearchQuery(s1, isCaseSensitive(), isRegex()))
.getDescription()));

if (isRegex()) {
try {
Expand All @@ -564,17 +577,17 @@ private void updateComponents() {
}
} else {
setDescription(Localization
.lang("Please enter a search term. For example, to search all fields for <b>Smith</b>, enter:<p>"
+ "<tt>smith</tt><p>"
+ "To search the field <b>Author</b> for <b>Smith</b> and the field <b>Title</b> for <b>electrical</b>, enter:<p>"
+ "<tt>author=smith and title=electrical</tt>"));
.lang("Please enter a search term. For example, to search all fields for <b>Smith</b>, enter:<p>"
+ "<tt>smith</tt><p>"
+ "To search the field <b>Author</b> for <b>Smith</b> and the field <b>Title</b> for <b>electrical</b>, enter:<p>"
+ "<tt>author=smith and title=electrical</tt>"));
}
setNameFontItalic(true);
} else if (explicitRadioButton.isSelected()) {
setDescription(GroupDescriptions.getDescriptionForPreview());
setNameFontItalic(false);
}
//TODO: okButton.setDisable(!okEnabled);
getDialogPane().lookupButton(ButtonType.OK).setDisable(!okEnabled);
}

private String fromTextFlowToHTMLString(TextFlow textFlow) {
Expand All @@ -596,7 +609,45 @@ private boolean isCaseSensitive() {
}

private void setDescription(String description) {
descriptionWebView.getEngine().loadContent("<html>" + description + "</html>");
descriptionTextFlow.getChildren().setAll(createFormattedDescription(description));
}

private ArrayList<Node> createFormattedDescription(String descriptionHTML) {
ArrayList<Node> nodes = new ArrayList<>();

descriptionHTML = descriptionHTML.replaceAll("<p>|<br>", "\n");

String[] boldSplit = descriptionHTML.split("(?=<b>)|(?<=</b>)|(?=<i>)|(?<=</i>)|(?=<tt>)|(?<=</tt>)|(?=<kbd>)|(?<=</kbd>)");

for (String bs : boldSplit) {

if (bs.matches("<b>[^<>]*</b>")) {

bs = bs.replaceAll("<b>|</b>", "");
Text textElement = new Text(bs);
textElement.setStyle("-fx-font-weight: bold");
nodes.add(textElement);

} else if (bs.matches("<i>[^<>]*</i>")) {

bs = bs.replaceAll("<i>|</i>", "");
Text textElement = new Text(bs);
textElement.setStyle("-fx-font-style: italic");
nodes.add(textElement);

} else if (bs.matches("<tt>[^<>]*</tt>|<kbd>[^<>]*</kbd>")) {

bs = bs.replaceAll("<tt>|</tt>|<kbd>|</kbd>", "");
Text textElement = new Text(bs);
textElement.setStyle("-fx-font-family: 'Courier New', Courier, monospace");
nodes.add(textElement);

} else {
nodes.add(new Text(bs));
}
}

return nodes;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ private void onSelectedGroupChanged(ObservableList<GroupNodeViewModel> newValue)
* Opens "New Group Dialog" and add the resulting group to the root
*/
public void addNewGroupToRoot() {
addNewSubgroup(rootGroup.get());
if (currentDatabase.isPresent()) {
addNewSubgroup(rootGroup.get());
} else {
dialogService.showWarningDialogAndWait(Localization.lang("Cannot create group"), Localization.lang("Cannot create group. Please create a library first."));
}
}

/**
Expand All @@ -124,8 +128,8 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
rootGroup.setValue(newRoot);
this.selectedGroups.setAll(
stateManager.getSelectedGroup(newDatabase.get()).stream()
.map(selectedGroup -> new GroupNodeViewModel(newDatabase.get(), stateManager, taskExecutor, selectedGroup, localDragboard))
.collect(Collectors.toList()));
.map(selectedGroup -> new GroupNodeViewModel(newDatabase.get(), stateManager, taskExecutor, selectedGroup, localDragboard))
.collect(Collectors.toList()));
} else {
rootGroup.setValue(GroupNodeViewModel.getAllEntriesGroup(new BibDatabaseContext(), stateManager, taskExecutor, localDragboard));
}
Expand Down Expand Up @@ -228,7 +232,7 @@ public void removeGroupKeepSubgroups(GroupNodeViewModel group) {
//panel.getUndoManager().addEdit(undo);
GroupTreeNode groupNode = group.getGroupNode();
groupNode.getParent()
.ifPresent(parent -> groupNode.moveAllChildrenTo(parent, parent.getIndexOfChild(groupNode).get()));
.ifPresent(parent -> groupNode.moveAllChildrenTo(parent, parent.getIndexOfChild(groupNode).get()));
groupNode.removeFromParent();

dialogService.notify(Localization.lang("Removed group \"%0\".", group.getDisplayName()));
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Cancel=Abbrechen

Cannot\ add\ entries\ to\ group\ without\ generating\ keys.\ Generate\ keys\ now?=Einträge können einer Gruppe nicht hinzugefügt werden, ohne Keys zu generieren. Sollen die Keys jetzt generiert werden?

Cannot\ create\ group=Gruppe kann nicht erstellt werden

Cannot\ create\ group.\ Please\ create\ a\ library\ first.=Gruppe kann nicht erstellt werden. Erstellen sie zuerst eine Bibliothek.

Cannot\ merge\ this\ change=Kann diese Änderung nicht einfügen

case\ insensitive=Groß-/Kleinschreibung wird nicht unterschieden
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Cancel=Cancel

Cannot\ add\ entries\ to\ group\ without\ generating\ keys.\ Generate\ keys\ now?=Cannot add entries to group without generating keys. Generate keys now?

Cannot\ create\ group=Cannot create group

Cannot\ create\ group.\ Please\ create\ a\ library\ first.=Cannot create group. Please create a library first.

Cannot\ merge\ this\ change=Cannot merge this change

case\ insensitive=case insensitive
Expand Down

0 comments on commit 2415c3c

Please sign in to comment.