From fe6277cba982e2a9881508e143f6b6ebac43f338 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 24 Dec 2018 00:50:44 +0100 Subject: [PATCH] Fixes that renaming a group did not change the group name in the interface Fixes #3189. --- CHANGELOG.md | 1 + .../jabref/gui/groups/GroupNodeViewModel.java | 12 ++++++------ .../org/jabref/gui/groups/GroupTreeView.java | 16 ++++++++++------ .../jabref/gui/groups/GroupTreeViewModel.java | 14 ++++++++++---- .../gui/util/ViewModelTreeTableCellFactory.java | 4 ++++ .../org/jabref/model/groups/GroupTreeNode.java | 14 +++++--------- 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d3e7c71f2f..b1c3fd7d4be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where the menu on Mac OS was not displayed in the usual Mac-specific way. https://github.com/JabRef/jabref/issues/3146 - We improved the integrity check for page numbers. [#4113](https://github.com/JabRef/jabref/issues/4113) and [feature request in the forum](http://discourse.jabref.org/t/pages-field-allow-use-of-en-dash/1199) - We fixed an issue where the order of fields in customized entry types was not saved correctly. [#4033](http://github.com/JabRef/jabref/issues/4033) +- We fixed an issue where renaming a group did not change the group name in the interface. [#3189](https://github.com/JabRef/jabref/issues/3189) - We fixed an issue where the groups tree of the last database was still shown even after the database was already closed. - We fixed an issue where the "Open file dialog" may disappear behind other windows. https://github.com/JabRef/jabref/issues/3410 - We fixed an issue where the number of entries matched was not updated correctly upon adding or removing an entry. [#3537](https://github.com/JabRef/jabref/issues/3537) diff --git a/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java index 12abad57d6c..c31c9ce6dd9 100644 --- a/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java @@ -63,16 +63,16 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state this.groupNode = Objects.requireNonNull(groupNode); this.localDragBoard = Objects.requireNonNull(localDragBoard); - LatexToUnicodeFormatter formatter = new LatexToUnicodeFormatter(); - displayName = formatter.format(groupNode.getName()); + displayName = new LatexToUnicodeFormatter().format(groupNode.getName()); isRoot = groupNode.isRoot(); if (groupNode.getGroup() instanceof AutomaticGroup) { AutomaticGroup automaticGroup = (AutomaticGroup) groupNode.getGroup(); - children = automaticGroup.createSubgroups(databaseContext.getDatabase().getEntries()).stream() - .map(this::toViewModel) - .sorted((group1, group2) -> group1.getDisplayName().compareToIgnoreCase(group2.getDisplayName())) - .collect(Collectors.toCollection(FXCollections::observableArrayList)); + children = automaticGroup.createSubgroups(this.databaseContext.getDatabase().getEntries()) + .stream() + .map(this::toViewModel) + .sorted((group1, group2) -> group1.getDisplayName().compareToIgnoreCase(group2.getDisplayName())) + .collect(Collectors.toCollection(FXCollections::observableArrayList)); } else { children = BindingsHelper.mapBacked(groupNode.getChildren(), this::toViewModel); } diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeView.java b/src/main/java/org/jabref/gui/groups/GroupTreeView.java index 6cdcae3c8ee..4dbbf152859 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeView.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeView.java @@ -114,15 +114,16 @@ public void initialize() { // Icon and group name mainColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty()); - mainColumn.setCellFactory(new ViewModelTreeTableCellFactory() + new ViewModelTreeTableCellFactory() .withText(GroupNodeViewModel::getDisplayName) .withIcon(GroupNodeViewModel::getIcon) - .withTooltip(GroupNodeViewModel::getDescription)); + .withTooltip(GroupNodeViewModel::getDescription) + .install(mainColumn); // Number of hits PseudoClass anySelected = PseudoClass.getPseudoClass("any-selected"); PseudoClass allSelected = PseudoClass.getPseudoClass("all-selected"); - numberColumn.setCellFactory(new ViewModelTreeTableCellFactory() + new ViewModelTreeTableCellFactory() .withGraphic(group -> { final StackPane node = new StackPane(); node.getStyleClass().setAll("hits"); @@ -138,11 +139,12 @@ public void initialize() { node.getChildren().add(text); node.setMaxWidth(Control.USE_PREF_SIZE); return node; - })); + }) + .install(numberColumn); // Arrow indicating expanded status disclosureNodeColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty()); - disclosureNodeColumn.setCellFactory(new ViewModelTreeTableCellFactory() + new ViewModelTreeTableCellFactory() .withGraphic(viewModel -> { final StackPane disclosureNode = new StackPane(); disclosureNode.visibleProperty().bind(viewModel.hasChildrenProperty()); @@ -156,7 +158,8 @@ public void initialize() { .withOnMouseClickedEvent(group -> event -> { group.toggleExpansion(); event.consume(); - })); + }) + .install(disclosureNodeColumn); // Set pseudo-classes to indicate if row is root or sub-item ( > 1 deep) PseudoClass rootPseudoClass = PseudoClass.getPseudoClass("root"); @@ -316,6 +319,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) { editGroup.setOnAction(event -> { menu.hide(); viewModel.editGroup(group); + groupTree.refresh(); }); MenuItem addSubgroup = new MenuItem(Localization.lang("Add subgroup")); diff --git a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index 356a6989995..ab1cb4449e6 100644 --- a/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -57,10 +57,13 @@ public GroupTreeViewModel(StateManager stateManager, DialogService dialogService EasyBind.subscribe(selectedGroups, this::onSelectedGroupChanged); // Set-up bindings - filterPredicate - .bind(Bindings.createObjectBinding(() -> group -> group.isMatchedBy(filterText.get()), filterText)); + filterPredicate.bind(Bindings.createObjectBinding(() -> group -> group.isMatchedBy(filterText.get()), filterText)); // Init + refresh(); + } + + private void refresh() { onActiveDatabaseChanged(stateManager.activeDatabaseProperty().getValue()); } @@ -166,13 +169,13 @@ public void editGroup(GroupNodeViewModel oldGroup) { Localization.lang("Change of Grouping Method"), Localization.lang("Assign the original group's entries to this group?")); // WarnAssignmentSideEffects.warnAssignmentSideEffects(newGroup, panel.frame()); - boolean removePreviousAssignents = (oldGroup.getGroupNode().getGroup() instanceof ExplicitGroup) + boolean removePreviousAssignments = (oldGroup.getGroupNode().getGroup() instanceof ExplicitGroup) && (group instanceof ExplicitGroup); oldGroup.getGroupNode().setGroup( group, keepPreviousAssignments, - removePreviousAssignents, + removePreviousAssignments, stateManager.getEntriesInCurrentDatabase()); // TODO: Add undo @@ -194,6 +197,9 @@ public void editGroup(GroupNodeViewModel oldGroup) { dialogService.notify(Localization.lang("Modified group \"%0\".", group.getName())); writeGroupChangesToMetaData(); + + // This is ugly but we have no proper update mechanism in place to propagate the changes, so redraw everything + refresh(); }); } diff --git a/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java b/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java index 80e7b071aba..233178e17fd 100644 --- a/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java +++ b/src/main/java/org/jabref/gui/util/ViewModelTreeTableCellFactory.java @@ -84,4 +84,8 @@ protected void updateItem(T item, boolean empty) { } }; } + + public void install(TreeTableColumn column) { + column.setCellFactory(this); + } } diff --git a/src/main/java/org/jabref/model/groups/GroupTreeNode.java b/src/main/java/org/jabref/model/groups/GroupTreeNode.java index 367b2ac1184..f0f0b9d4745 100644 --- a/src/main/java/org/jabref/model/groups/GroupTreeNode.java +++ b/src/main/java/org/jabref/model/groups/GroupTreeNode.java @@ -222,15 +222,11 @@ public GroupTreeNode copyNode() { * @param entries list of entries to be searched * @return number of hits */ - public int calculateNumberOfMatches(List entries) { - int hits = 0; + public long calculateNumberOfMatches(List entries) { SearchMatcher matcher = getSearchMatcher(); - for (BibEntry entry : entries) { - if (matcher.isMatch(entry)) { - hits++; - } - } - return hits; + return entries.stream() + .filter(matcher::isMatch) + .count(); } /** @@ -238,7 +234,7 @@ public int calculateNumberOfMatches(List entries) { * @param database database to be searched * @return number of hits */ - public int calculateNumberOfMatches(BibDatabase database) { + public long calculateNumberOfMatches(BibDatabase database) { return calculateNumberOfMatches(database.getEntries()); }