From 4525f446c33adbc268e0850eaed4abc0aad652d1 Mon Sep 17 00:00:00 2001 From: samiyac Date: Sun, 10 Mar 2019 19:10:30 +0530 Subject: [PATCH 1/5] Fixes #4586 --- CHANGELOG.md | 1 + .../org/jabref/gui/groups/GroupDialog.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eecbaff3814..4efb45787a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We grouped and reordered the Main Menu (File, Edit, Library, Quality, Tools, and View tabs & icons). [#4666](https://github.com/JabRef/jabref/issues/4666) [#4667](https://github.com/JabRef/jabref/issues/4667) [#4668](https://github.com/JabRef/jabref/issues/4668) [#4669](https://github.com/JabRef/jabref/issues/4669) [#4670](https://github.com/JabRef/jabref/issues/4670) [#4671](https://github.com/JabRef/jabref/issues/4671) [#4672](https://github.com/JabRef/jabref/issues/4672) [#4673](https://github.com/JabRef/jabref/issues/4673) - We added additional modifiers (capitalize, titlecase and sentencecase) to the Bibtex key generator. [#1506](https://github.com/JabRef/jabref/issues/1506) - We grouped the toolbar icons and changed the Open Library and Copy icons. [#4584](https://github.com/JabRef/jabref/issues/4584) +- We added a browse button next to the path text field for aux-based groups. [#4586](https://github.com/JabRef/jabref/issues/4586) ### Fixed diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index 16b8601a8dd..5b09d07a1c7 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -13,6 +13,7 @@ import javafx.geometry.Insets; import javafx.geometry.Orientation; import javafx.scene.Node; +import javafx.scene.control.Button; import javafx.scene.control.ButtonType; import javafx.scene.control.CheckBox; import javafx.scene.control.Label; @@ -24,6 +25,7 @@ import javafx.scene.control.Toggle; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.text.Font; @@ -33,13 +35,16 @@ import org.jabref.Globals; import org.jabref.JabRefGUI; +import org.jabref.gui.DialogService; import org.jabref.gui.JabRefFrame; import org.jabref.gui.search.rules.describer.SearchDescribers; import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.TooltipTextUtil; import org.jabref.logic.auxparser.DefaultAuxParser; import org.jabref.logic.l10n.Localization; import org.jabref.logic.search.SearchQuery; +import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.FieldName; import org.jabref.model.entry.Keyword; @@ -105,6 +110,8 @@ class GroupDialog extends BaseDialog { // for TexGroup private final TextField texGroupFilePath = new TextField(); + private final Button texGroupBrowseButton = new Button("Browse"); + private final HBox texGroupHBox = new HBox(10); // for all types private final TextFlow descriptionTextFlow = new TextFlow(); @@ -145,7 +152,7 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) { VBox keywordPanel = createOptionsKeywordGroup(); VBox searchPanel = createOptionsSearchGroup(); VBox autoPanel = createOptionsAutoGroup(); - VBox texPanel = createOptionsTexGroup(); + VBox texPanel = createOptionsTexGroup(jabrefFrame); optionsPanel.getChildren().addAll(explicitPanel, keywordPanel, searchPanel, autoPanel, texPanel); optionsPanel.setPadding(new Insets(0, 0, 0, 10)); @@ -438,11 +445,16 @@ private static String formatRegExException(String regExp, Exception e) { return s; } - private VBox createOptionsTexGroup() { + private VBox createOptionsTexGroup(JabRefFrame jabRefFrame) { VBox texPanel = new VBox(); texPanel.setVisible(false); texPanel.getChildren().add(new Label(Localization.lang("Aux file"))); - texPanel.getChildren().add(texGroupFilePath); + EventHandler actionHandler = (ActionEvent e) -> openBrowseDialog(jabRefFrame); + texGroupBrowseButton.setOnAction(actionHandler); + texGroupHBox.getChildren().add(texGroupFilePath); + texGroupHBox.getChildren().add(texGroupBrowseButton); + texGroupHBox.setHgrow(texGroupFilePath, Priority.ALWAYS); + texPanel.getChildren().add(texGroupHBox); return texPanel; } @@ -586,6 +598,15 @@ private void updateComponents() { getDialogPane().lookupButton(ButtonType.OK).setDisable(!okEnabled); } + private void openBrowseDialog(JabRefFrame jabRefFrame) { + DialogService dialogService = jabRefFrame.getDialogService(); + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + .addExtensionFilter(StandardFileType.AUX) + .withDefaultExtension(StandardFileType.AUX) + .withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build(); + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> texGroupFilePath.setText(file.toAbsolutePath().toString())); + } + private String fromTextFlowToHTMLString(TextFlow textFlow) { StringBuilder htmlStringBuilder = new StringBuilder(); for (Node node : textFlow.getChildren()) { From 8cf46a90b14eef73bce4d35f02b92c92c1f88512 Mon Sep 17 00:00:00 2001 From: samiyac Date: Sun, 10 Mar 2019 22:54:48 +0530 Subject: [PATCH 2/5] implementing suggestions from code review --- src/main/java/org/jabref/gui/groups/GroupDialog.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index 5b09d07a1c7..de2a6cf3029 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -449,8 +449,7 @@ private VBox createOptionsTexGroup(JabRefFrame jabRefFrame) { VBox texPanel = new VBox(); texPanel.setVisible(false); texPanel.getChildren().add(new Label(Localization.lang("Aux file"))); - EventHandler actionHandler = (ActionEvent e) -> openBrowseDialog(jabRefFrame); - texGroupBrowseButton.setOnAction(actionHandler); + texGroupBrowseButton.setOnAction((ActionEvent e) -> openBrowseDialog(jabRefFrame.getDialogService())); texGroupHBox.getChildren().add(texGroupFilePath); texGroupHBox.getChildren().add(texGroupBrowseButton); texGroupHBox.setHgrow(texGroupFilePath, Priority.ALWAYS); @@ -598,8 +597,7 @@ private void updateComponents() { getDialogPane().lookupButton(ButtonType.OK).setDisable(!okEnabled); } - private void openBrowseDialog(JabRefFrame jabRefFrame) { - DialogService dialogService = jabRefFrame.getDialogService(); + private void openBrowseDialog(DialogService dialogService) { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.AUX) .withDefaultExtension(StandardFileType.AUX) From 6fddf4ce4d048a7a8b611ddb187ebdafa75e8e9c Mon Sep 17 00:00:00 2001 From: samiyac Date: Mon, 11 Mar 2019 23:55:50 +0530 Subject: [PATCH 3/5] Updated constructor to remove JabRefFrame object --- .../org/jabref/gui/groups/GroupDialog.java | 37 +++++++++++-------- .../jabref/gui/groups/GroupTreeViewModel.java | 4 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index de2a6cf3029..4377984cb05 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -7,6 +7,8 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import javax.swing.JOptionPane; + import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.event.EventHandler; @@ -35,8 +37,8 @@ import org.jabref.Globals; import org.jabref.JabRefGUI; +import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; -import org.jabref.gui.JabRefFrame; import org.jabref.gui.search.rules.describer.SearchDescribers; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.FileDialogConfiguration; @@ -88,6 +90,8 @@ class GroupDialog extends BaseDialog { private final RadioButton independentButton = new RadioButton(Localization.lang("Independent group: When selected, view only this group's entries")); private final RadioButton intersectionButton = new RadioButton(Localization.lang("Refine supergroup: When selected, view entries contained in both this group and its supergroup")); private final RadioButton unionButton = new RadioButton(Localization.lang("Include subgroups: When selected, view entries contained in this group or its subgroups")); + private final DialogService dialogService; + private final JabRefPreferences prefs; // for KeywordGroup private final TextField keywordGroupSearchTerm = new TextField(); @@ -125,7 +129,7 @@ class GroupDialog extends BaseDialog { * @param editedGroup The group being edited, or null if a new group is to be * created. */ - public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) { + public GroupDialog(DialogService dialogService, BasePanel basePanel, JabRefPreferences prefs, AbstractGroup editedGroup) { this.setTitle(Localization.lang("Edit group")); explicitRadioButton.setSelected(true); @@ -135,8 +139,11 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) { descriptionTextFlow.setMinHeight(180); descriptionTextFlow.setPrefHeight(180); + this.dialogService = dialogService; + this.prefs = prefs; + // set default values (overwritten if editedGroup != null) - keywordGroupSearchField.setText(jabrefFrame.prefs().get(JabRefPreferences.GROUPS_DEFAULT_FIELD)); + keywordGroupSearchField.setText(prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD)); // configure elements ToggleGroup groupType = new ToggleGroup(); @@ -152,7 +159,7 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) { VBox keywordPanel = createOptionsKeywordGroup(); VBox searchPanel = createOptionsSearchGroup(); VBox autoPanel = createOptionsAutoGroup(); - VBox texPanel = createOptionsTexGroup(jabrefFrame); + VBox texPanel = createOptionsTexGroup(); optionsPanel.getChildren().addAll(explicitPanel, keywordPanel, searchPanel, autoPanel, texPanel); optionsPanel.setPadding(new Insets(0, 0, 0, 10)); @@ -268,11 +275,11 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) { if (explicitRadioButton.isSelected()) { Character keywordDelimiter = Globals.prefs.getKeywordDelimiter(); if (groupName.contains(Character.toString(keywordDelimiter))) { - jabrefFrame.showMessage( + JOptionPane.showMessageDialog(null, Localization.lang("The group name contains the keyword separator \"%0\" and thus probably does not work as expected.", Character.toString(keywordDelimiter))); } - Optional rootGroup = jabrefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getGroups(); + Optional rootGroup = basePanel.getBibDatabaseContext().getMetaData().getGroups(); if (rootGroup.isPresent()) { int groupsWithSameName = rootGroup.get().findChildrenSatisfying(group -> group.getName().equals(groupName)).size(); boolean warnAboutSameName = false; @@ -286,7 +293,7 @@ public GroupDialog(JabRefFrame jabrefFrame, AbstractGroup editedGroup) { } if (warnAboutSameName) { - jabrefFrame.showMessage( + JOptionPane.showMessageDialog(null, Localization.lang("There exists already a group with the same name.", Character.toString(keywordDelimiter))); return null; } @@ -330,7 +337,7 @@ groupName, getContext(), resultingGroup.setIconName(iconField.getText()); return resultingGroup; } catch (IllegalArgumentException | IOException exception) { - jabrefFrame.showMessage(exception.getLocalizedMessage()); + JOptionPane.showMessageDialog(null, exception.getLocalizedMessage()); return null; } } @@ -411,12 +418,12 @@ groupName, getContext(), getDialogPane().getScene().getWindow().sizeToScene(); } - public GroupDialog() { - this(JabRefGUI.getMainFrame(), null); + public GroupDialog(DialogService dialogService) { + this(dialogService, JabRefGUI.getMainFrame().getCurrentBasePanel(), Globals.prefs, null); } - public GroupDialog(AbstractGroup editedGroup) { - this(JabRefGUI.getMainFrame(), editedGroup); + public GroupDialog(DialogService dialogService, AbstractGroup editedGroup) { + this(dialogService, JabRefGUI.getMainFrame().getCurrentBasePanel(), Globals.prefs, editedGroup); } private static String formatRegExException(String regExp, Exception e) { @@ -445,11 +452,11 @@ private static String formatRegExException(String regExp, Exception e) { return s; } - private VBox createOptionsTexGroup(JabRefFrame jabRefFrame) { + private VBox createOptionsTexGroup() { VBox texPanel = new VBox(); texPanel.setVisible(false); texPanel.getChildren().add(new Label(Localization.lang("Aux file"))); - texGroupBrowseButton.setOnAction((ActionEvent e) -> openBrowseDialog(jabRefFrame.getDialogService())); + texGroupBrowseButton.setOnAction((ActionEvent e) -> openBrowseDialog()); texGroupHBox.getChildren().add(texGroupFilePath); texGroupHBox.getChildren().add(texGroupBrowseButton); texGroupHBox.setHgrow(texGroupFilePath, Priority.ALWAYS); @@ -597,7 +604,7 @@ private void updateComponents() { getDialogPane().lookupButton(ButtonType.OK).setDisable(!okEnabled); } - private void openBrowseDialog(DialogService dialogService) { + private void openBrowseDialog() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.AUX) .withDefaultExtension(StandardFileType.AUX) diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index de4c279e59c..bccddf297e5 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -141,7 +141,7 @@ private void onActiveDatabaseChanged(Optional newDatabase) { * Opens "New Group Dialog" and add the resulting group to the specified group */ public void addNewSubgroup(GroupNodeViewModel parent) { - Optional newGroup = dialogService.showCustomDialogAndWait(new GroupDialog()); + Optional newGroup = dialogService.showCustomDialogAndWait(new GroupDialog(dialogService)); newGroup.ifPresent(group -> { parent.addSubgroup(group); @@ -166,7 +166,7 @@ private void writeGroupChangesToMetaData() { */ public void editGroup(GroupNodeViewModel oldGroup) { Optional newGroup = dialogService - .showCustomDialogAndWait(new GroupDialog(oldGroup.getGroupNode().getGroup())); + .showCustomDialogAndWait(new GroupDialog(dialogService, oldGroup.getGroupNode().getGroup())); newGroup.ifPresent(group -> { // TODO: Keep assignments boolean keepPreviousAssignments = dialogService.showConfirmationDialogAndWait( From 6b58c0e5d5ed3c9acb53ff38328b3e632763d2e4 Mon Sep 17 00:00:00 2001 From: samiyac Date: Tue, 12 Mar 2019 01:08:16 +0530 Subject: [PATCH 4/5] Using DialogService to show warnings/errors --- src/main/java/org/jabref/gui/groups/GroupDialog.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index 4377984cb05..39f255a8a37 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -7,8 +7,6 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import javax.swing.JOptionPane; - import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.event.EventHandler; @@ -275,7 +273,7 @@ public GroupDialog(DialogService dialogService, BasePanel basePanel, JabRefPrefe if (explicitRadioButton.isSelected()) { Character keywordDelimiter = Globals.prefs.getKeywordDelimiter(); if (groupName.contains(Character.toString(keywordDelimiter))) { - JOptionPane.showMessageDialog(null, + dialogService.showWarningDialogAndWait(Localization.lang("Keyword separator in group name"), Localization.lang("The group name contains the keyword separator \"%0\" and thus probably does not work as expected.", Character.toString(keywordDelimiter))); } @@ -293,8 +291,7 @@ public GroupDialog(DialogService dialogService, BasePanel basePanel, JabRefPrefe } if (warnAboutSameName) { - JOptionPane.showMessageDialog(null, - Localization.lang("There exists already a group with the same name.", Character.toString(keywordDelimiter))); + dialogService.showErrorDialogAndWait(Localization.lang("There exists already a group with the same name.", Character.toString(keywordDelimiter))); return null; } } @@ -337,7 +334,7 @@ groupName, getContext(), resultingGroup.setIconName(iconField.getText()); return resultingGroup; } catch (IllegalArgumentException | IOException exception) { - JOptionPane.showMessageDialog(null, exception.getLocalizedMessage()); + dialogService.showErrorDialogAndWait(exception.getLocalizedMessage(), exception); return null; } } From 7541c01dfec038cf7f690574c0b9f68ba98d8e05 Mon Sep 17 00:00:00 2001 From: samiyac Date: Tue, 12 Mar 2019 02:08:37 +0530 Subject: [PATCH 5/5] changes implemented --- src/main/java/org/jabref/gui/groups/GroupDialog.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialog.java b/src/main/java/org/jabref/gui/groups/GroupDialog.java index 39f255a8a37..9859213c926 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialog.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialog.java @@ -273,8 +273,7 @@ public GroupDialog(DialogService dialogService, BasePanel basePanel, JabRefPrefe if (explicitRadioButton.isSelected()) { Character keywordDelimiter = Globals.prefs.getKeywordDelimiter(); if (groupName.contains(Character.toString(keywordDelimiter))) { - dialogService.showWarningDialogAndWait(Localization.lang("Keyword separator in group name"), - Localization.lang("The group name contains the keyword separator \"%0\" and thus probably does not work as expected.", Character.toString(keywordDelimiter))); + dialogService.showWarningDialogAndWait(null, Localization.lang("The group name contains the keyword separator \"%0\" and thus probably does not work as expected.", Character.toString(keywordDelimiter))); } Optional rootGroup = basePanel.getBibDatabaseContext().getMetaData().getGroups();