Skip to content

Commit

Permalink
Changed isGroup boolean to enum declaration, added GroupDialogHeader.…
Browse files Browse the repository at this point in the history
…java to store enum
  • Loading branch information
daolin committed May 12, 2021
1 parent 1cc0946 commit c9cdff3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupDialogHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.jabref.gui.groups;

public enum GroupDialogHeader {
GROUP, SUBGROUP
}
12 changes: 6 additions & 6 deletions src/main/java/org/jabref/gui/groups/GroupDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ public class GroupDialogView extends BaseDialog<AbstractGroup> {
private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();
private final GroupDialogViewModel viewModel;

public GroupDialogView(DialogService dialogService, BibDatabaseContext currentDatabase, PreferencesService preferencesService, AbstractGroup editedGroup, boolean isGroup) {
viewModel = new GroupDialogViewModel(dialogService, currentDatabase, preferencesService, editedGroup, isGroup);
public GroupDialogView(DialogService dialogService, BibDatabaseContext currentDatabase, PreferencesService preferencesService, AbstractGroup editedGroup, GroupDialogHeader groupDialogHeader) {
viewModel = new GroupDialogViewModel(dialogService, currentDatabase, preferencesService, editedGroup, groupDialogHeader);

ViewLoader.view(this)
.load()
.setAsDialogPane(this);

if (editedGroup == null) {
if (isGroup == true) {
this.setTitle(Localization.lang("Add group")); // header title
} else {
this.setTitle(Localization.lang("Add subgroup")); // header title\
if (groupDialogHeader == GroupDialogHeader.GROUP) {
this.setTitle(Localization.lang("Add group"));
} else if (groupDialogHeader == GroupDialogHeader.SUBGROUP) {
this.setTitle(Localization.lang("Add subgroup"));
}
} else {
this.setTitle(Localization.lang("Edit group") + " " + editedGroup.getName());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ public class GroupDialogViewModel {
private final PreferencesService preferencesService;
private final BibDatabaseContext currentDatabase;
private final AbstractGroup editedGroup;
private final boolean isGroup;
private final GroupDialogHeader isgroup;

public GroupDialogViewModel(DialogService dialogService, BibDatabaseContext currentDatabase, PreferencesService preferencesService, AbstractGroup editedGroup, boolean isGroup) {
public GroupDialogViewModel(DialogService dialogService, BibDatabaseContext currentDatabase, PreferencesService preferencesService, AbstractGroup editedGroup, GroupDialogHeader isgroup) {
this.dialogService = dialogService;
this.preferencesService = preferencesService;
this.currentDatabase = currentDatabase;
this.editedGroup = editedGroup;
this.isGroup = isGroup;
this.isgroup = isgroup;

setupValidation();
setValues();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
MenuItem addSubgroup = new MenuItem(Localization.lang("Add subgroup"));
addSubgroup.setOnAction(event -> {
menu.hide();
viewModel.addNewSubgroup(group, false);
viewModel.addNewSubgroup(group, GroupDialogHeader.SUBGROUP);
});

MenuItem removeSubgroups = new MenuItem(Localization.lang("Remove subgroups"));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void onSelectedGroupChanged(ObservableList<GroupNodeViewModel> newValue)
*/
public void addNewGroupToRoot() {
if (currentDatabase.isPresent()) {
addNewSubgroup(rootGroup.get(), true);
addNewSubgroup(rootGroup.get(), GroupDialogHeader.GROUP);
} else {
dialogService.showWarningDialogAndWait(Localization.lang("Cannot create group"), Localization.lang("Cannot create group. Please create a library first."));
}
Expand Down Expand Up @@ -148,14 +148,14 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
* Opens "New Group Dialog" and add the resulting group to the specified group
*/

public void addNewSubgroup(GroupNodeViewModel parent, boolean isGroup) {
public void addNewSubgroup(GroupNodeViewModel parent, GroupDialogHeader groupDialogHeader) {
currentDatabase.ifPresent(database -> {
Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialogView(
dialogService,
database,
preferences,
null,
isGroup));
groupDialogHeader));

newGroup.ifPresent(group -> {
parent.addSubgroup(group);
Expand Down Expand Up @@ -187,7 +187,7 @@ public void editGroup(GroupNodeViewModel oldGroup) {
database,
preferences,
oldGroup.getGroupNode().getGroup(),
false));
GroupDialogHeader.SUBGROUP));

newGroup.ifPresent(group -> {
// TODO: Keep assignments
Expand Down

0 comments on commit c9cdff3

Please sign in to comment.