Skip to content
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

Adds a browse button next to the path text field for aux-based groups #4743

Merged
merged 6 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/main/java/org/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +90,8 @@ class GroupDialog extends BaseDialog<AbstractGroup> {
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();
Expand Down Expand Up @@ -125,7 +129,7 @@ class GroupDialog extends BaseDialog<AbstractGroup> {
* @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);
Expand All @@ -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();
Expand All @@ -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));

Expand Down Expand Up @@ -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,
samiyac marked this conversation as resolved.
Show resolved Hide resolved
Localization.lang("The group name contains the keyword separator \"%0\" and thus probably does not work as expected.", Character.toString(keywordDelimiter)));
}

Optional<GroupTreeNode> rootGroup = jabrefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getGroups();
Optional<GroupTreeNode> rootGroup = basePanel.getBibDatabaseContext().getMetaData().getGroups();
if (rootGroup.isPresent()) {
int groupsWithSameName = rootGroup.get().findChildrenSatisfying(group -> group.getName().equals(groupName)).size();
boolean warnAboutSameName = false;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
* Opens "New Group Dialog" and add the resulting group to the specified group
*/
public void addNewSubgroup(GroupNodeViewModel parent) {
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog());
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog(dialogService));
newGroup.ifPresent(group -> {
parent.addSubgroup(group);

Expand All @@ -166,7 +166,7 @@ private void writeGroupChangesToMetaData() {
*/
public void editGroup(GroupNodeViewModel oldGroup) {
Optional<AbstractGroup> 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(
Expand Down