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

Updates to colored group indicator for cited entries #7173

Merged
merged 35 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
42dc97b
Fix matched groups binding
k3KAW8Pnf7mkmdSMPHz27 Dec 5, 2020
9b2c9b1
Code style and typos
k3KAW8Pnf7mkmdSMPHz27 Dec 7, 2020
72e75b6
Extend TexGroup with Observable
k3KAW8Pnf7mkmdSMPHz27 Dec 8, 2020
ca85073
Add missed code style change
k3KAW8Pnf7mkmdSMPHz27 Dec 8, 2020
55845ce
Revert parts of matched groups binding
k3KAW8Pnf7mkmdSMPHz27 Dec 14, 2020
e5324fa
Change data structure of stored listeners
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
0520009
Fix managing listeners of Observable groups
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
beb1a3e
Fix display of group count when using TexGroups
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
ee7296e
Fix use of deprecated setGroup
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
20d5e16
Remove check for null value
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
68a0a5d
Fix execution thread
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
a2972a9
Fix updating entries in selected groups
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
3d24c67
Fix concurrent modification issue
k3KAW8Pnf7mkmdSMPHz27 Dec 16, 2020
ca0c800
Merge branch 'master' into fix-for-issue-6394
k3KAW8Pnf7mkmdSMPHz27 Dec 21, 2020
21f7aae
Add MetaData GroupUpdatedEvent without saving
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
8501704
Merge branch 'master' into fix-for-issue-6394
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
536c96b
Add a GroupInvalidatedEvent
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
54c7e3d
Update JavaDoc
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
45d8c22
Add EventBus adapter
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
98ca673
Fix invalidation listener
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
410b8fa
Fix minor mistakes
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
2353e4d
Fix GroupInvalidatedEvent
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
d754190
Fix GroupInvalidatedEvent
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
c7fb44e
Refactoring for readability
k3KAW8Pnf7mkmdSMPHz27 Dec 23, 2020
338af18
Remove empty class
k3KAW8Pnf7mkmdSMPHz27 Dec 26, 2020
ced6720
Add JavaDoc to GroupInvalidatedEventBusAdapter
k3KAW8Pnf7mkmdSMPHz27 Dec 26, 2020
f64b215
Fix CheckStyle
k3KAW8Pnf7mkmdSMPHz27 Dec 28, 2020
996b0fe
Fix using an ObservableOptional root group wrapper
k3KAW8Pnf7mkmdSMPHz27 Dec 28, 2020
996329f
Refactor for readability
k3KAW8Pnf7mkmdSMPHz27 Dec 28, 2020
605b6bd
Drop update for groups other than TexGroup
k3KAW8Pnf7mkmdSMPHz27 Dec 28, 2020
73d9af9
Change where switch to JavaFX thread occurs
k3KAW8Pnf7mkmdSMPHz27 Dec 28, 2020
9d4847c
Add UiThread wrapper for groupsRootBinding
k3KAW8Pnf7mkmdSMPHz27 Jan 3, 2021
34c98b3
Updates CHANGELOG.md
k3KAW8Pnf7mkmdSMPHz27 Jan 3, 2021
f4d051d
Merge branch 'master' into fix-for-issue-6394
k3KAW8Pnf7mkmdSMPHz27 Jan 3, 2021
6c98807
Move the UI thread switch to View-Model
k3KAW8Pnf7mkmdSMPHz27 Jan 10, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the password for a shared SQL database was not remembered [#6869](https://github.com/JabRef/jabref/issues/6869)
- We fixed an issue where newly added entires were not synced to a shared SQL database [#7176](https://github.com/JabRef/jabref/issues/7176)
- We fixed an issue where the PDF-Content importer threw an exception when no DOI number is present at the first page of the PDF document [#7203](https://github.com/JabRef/jabref/issues/7203)
- We fixed an issue where groups created from aux files did not update on file changes [#6394](https://github.com/JabRef/jabref/issues/6394)
- We fixed an issue where authors that only have last names were incorrectly identified as institutes when generating citation keys [#7199](https://github.com/JabRef/jabref/issues/7199)
- We fixed an issue where institutes were incorrectly identified as universities when generating citation keys [#6942](https://github.com/JabRef/jabref/issues/6942)

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/jabref/gui/collab/GroupChangeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ public GroupChangeViewModel(GroupDiff diff) {

@Override
public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
GroupTreeNode root = database.getMetaData().getGroups().orElse(null);
if (root == null) {
root = new GroupTreeNode(DefaultGroupsFactory.getAllEntriesGroup());
database.getMetaData().setGroups(root);
}
GroupTreeNode root = database.getMetaData().getGroups().orElseGet(() -> {
GroupTreeNode groupTreeNode = new GroupTreeNode(DefaultGroupsFactory.getAllEntriesGroup());
database.getMetaData().setGroups(groupTreeNode);
return groupTreeNode;
});

final UndoableModifySubtree undo = new UndoableModifySubtree(
new GroupTreeNodeViewModel(database.getMetaData().getGroups().orElse(null)),
new GroupTreeNodeViewModel(root), Localization.lang("Modified groups"));
root.removeAllChildren();
if (changedGroups == null) {
// I think setting root to null is not possible
root.setGroup(DefaultGroupsFactory.getAllEntriesGroup());
root.setGroup(DefaultGroupsFactory.getAllEntriesGroup(), false, false, null);
} else {
// change root group, even though it'll be AllEntries anyway
root.setGroup(changedGroups.getGroup());
root.setGroup(changedGroups.getGroup(), false, false, null);
for (GroupTreeNode child : changedGroups.getChildren()) {
child.copySubtree().moveTo(root);
}
Expand Down
37 changes: 24 additions & 13 deletions src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.IntegerBinding;
Expand Down Expand Up @@ -34,6 +36,7 @@
import org.jabref.model.groups.AutomaticGroup;
import org.jabref.model.groups.GroupEntryChanger;
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.groups.TexGroup;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.PreferencesService;

Expand All @@ -59,6 +62,7 @@ public class GroupNodeViewModel {
private final CustomLocalDragboard localDragBoard;
private final ObservableList<BibEntry> entriesList;
private final PreferencesService preferencesService;
private final InvalidationListener onInvalidatedGroup = (listener) -> refreshGroup();

public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager stateManager, TaskExecutor taskExecutor, GroupTreeNode groupNode, CustomLocalDragboard localDragBoard, PreferencesService preferencesService) {
this.databaseContext = Objects.requireNonNull(databaseContext);
Expand All @@ -81,6 +85,9 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state
} else {
children = EasyBind.mapBacked(groupNode.getChildren(), this::toViewModel);
}
if (groupNode.getGroup() instanceof TexGroup) {
databaseContext.getMetaData().groupsBinding().addListener(new WeakInvalidationListener(onInvalidatedGroup));
}
hasChildren = new SimpleBooleanProperty();
hasChildren.bind(Bindings.isNotEmpty(children));
updateMatchedEntries();
Expand Down Expand Up @@ -250,6 +257,15 @@ private void onDatabaseChanged(ListChangeListener.Change<? extends BibEntry> cha
}
}

private void refreshGroup() {
updateMatchedEntries(); // Update the entries matched by the group
// "Re-add" to the selected groups if it were selected, this refreshes the entries the user views
ObservableList<GroupTreeNode> selectedGroups = this.stateManager.getSelectedGroup(this.databaseContext);
if (selectedGroups.remove(this.groupNode)) {
selectedGroups.add(this.groupNode);
}
}

private void updateMatchedEntries() {
// We calculate the new hit value
// We could be more intelligent and try to figure out the new number of hits based on the entry change
Expand Down Expand Up @@ -290,10 +306,11 @@ public Optional<GroupNodeViewModel> getChildByPath(String pathToSource) {
}

/**
* Decides if the content stored in the given {@link Dragboard} can be droped on the given target row.
* Currently, the following sources are allowed:
* - another group (will be added as subgroup on drop)
* - entries if the group implements {@link GroupEntryChanger} (will be assigned to group on drop)
* Decides if the content stored in the given {@link Dragboard} can be dropped on the given target row. Currently, the following sources are allowed:
* <ul>
* <li>another group (will be added as subgroup on drop)</li>
* <li>entries if the group implements {@link GroupEntryChanger} (will be assigned to group on drop)</li>
* </ul>
*/
public boolean acceptableDrop(Dragboard dragboard) {
// TODO: we should also check isNodeDescendant
Expand Down Expand Up @@ -343,15 +360,9 @@ public void draggedOn(GroupNodeViewModel target, DroppingMouseLocation mouseLoca
// Bottom + top -> insert source row before / after this row
// Center -> add as child
switch (mouseLocation) {
case BOTTOM:
this.moveTo(targetParent.get(), targetIndex + 1);
break;
case CENTER:
this.moveTo(target);
break;
case TOP:
this.moveTo(targetParent.get(), targetIndex);
break;
case BOTTOM -> this.moveTo(targetParent.get(), targetIndex + 1);
case CENTER -> this.moveTo(target);
case TOP -> this.moveTo(targetParent.get(), targetIndex);
}
} else {
// No parent = root -> just add
Expand Down
29 changes: 13 additions & 16 deletions src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import javafx.beans.Observable;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;

import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
Expand All @@ -36,7 +37,7 @@ public class BibEntryTableViewModel {
private final Map<SpecialField, OptionalBinding<SpecialFieldValueViewModel>> specialFieldValues = new HashMap<>();
private final EasyBinding<List<LinkedFile>> linkedFiles;
private final EasyBinding<Map<Field, String>> linkedIdentifiers;
private final ObservableValue<List<AbstractGroup>> matchedGroups;
private final Binding<List<AbstractGroup>> matchedGroups;

public BibEntryTableViewModel(BibEntry entry, BibDatabaseContext bibDatabaseContext, ObservableValue<MainTableFieldValueFormatter> fieldValueFormatter) {
this.entry = entry;
Expand Down Expand Up @@ -67,19 +68,15 @@ public BibEntry getEntry() {
return entry;
}

private static ObservableValue<List<AbstractGroup>> createMatchedGroupsBinding(BibDatabaseContext database, BibEntry entry) {
Optional<GroupTreeNode> root = database.getMetaData().getGroups();
if (root.isPresent()) {
return EasyBind.map(entry.getFieldBinding(StandardField.GROUPS), field -> {
List<AbstractGroup> groups = root.get().getMatchingGroups(entry)
.stream()
.map(GroupTreeNode::getGroup)
.collect(Collectors.toList());
groups.remove(root.get().getGroup());
return groups;
});
}
return new SimpleObjectProperty<>(Collections.emptyList());
private static Binding<List<AbstractGroup>> createMatchedGroupsBinding(BibDatabaseContext database, BibEntry entry) {
return EasyBind.combine(entry.getFieldBinding(StandardField.GROUPS), database.getMetaData().groupsBinding(),
(a, b) ->
database.getMetaData().getGroups().map(groupTreeNode ->
groupTreeNode.getMatchingGroups(entry).stream()
.map(GroupTreeNode::getGroup)
.filter(Predicate.not(Predicate.isEqual(groupTreeNode.getGroup())))
.collect(Collectors.toList()))
.orElse(Collections.emptyList()));
}

public OptionalBinding<String> getField(Field field) {
Expand Down Expand Up @@ -119,7 +116,7 @@ public ObservableValue<String> getFields(OrFields fields) {
observables.add(fieldValueFormatter);

value = Bindings.createStringBinding(() ->
fieldValueFormatter.getValue().formatFieldsValues(fields, entry),
fieldValueFormatter.getValue().formatFieldsValues(fields, entry),
observables.toArray(Observable[]::new));
fieldValues.put(fields, value);
return value;
Expand Down
27 changes: 8 additions & 19 deletions src/main/java/org/jabref/gui/preview/CopyCitationAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import org.slf4j.LoggerFactory;

/**
* Copies the selected entries and formats them with the selected citation style (or preview), then it is copied to the clipboard.
* This worker cannot be reused.
* Copies the selected entries and formats them with the selected citation style (or preview), then it is copied to the clipboard. This worker cannot be reused.
*/
public class CopyCitationAction extends SimpleCommand {

Expand Down Expand Up @@ -93,8 +92,7 @@ private List<String> generateCitations() throws IOException {
}

/**
* Generates a plain text string out of the preview and copies it additionally to the html to the clipboard
* (WYSIWYG Editors use the HTML, plain text editors the text)
* Generates a plain text string out of the preview and copies it additionally to the html to the clipboard (WYSIWYG Editors use the HTML, plain text editors the text)
*/
protected static ClipboardContent processPreview(List<String> citations) {
ClipboardContent content = new ClipboardContent();
Expand Down Expand Up @@ -182,23 +180,14 @@ private void setClipBoardContent(List<String> citations) {
// if it's generated by a citation style take care of each output format
ClipboardContent content;
switch (outputFormat) {
case HTML:
content = processHtml(citations);
break;
case RTF:
content = processRtf(citations);
break;
case XSL_FO:
content = processXslFo(citations);
break;
case ASCII_DOC:
case TEXT:
content = processText(citations);
break;
default:
case HTML -> content = processHtml(citations);
case RTF -> content = processRtf(citations);
case XSL_FO -> content = processXslFo(citations);
case ASCII_DOC, TEXT -> content = processText(citations);
default -> {
LOGGER.warn("unknown output format: '" + outputFormat + "', processing it via the default.");
content = processText(citations);
break;
}
}
clipBoardManager.setContent(content);
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/jabref/gui/util/BindingsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import com.tobiasdiez.easybind.Subscription;

/**
* Helper methods for javafx binding.
* Some methods are taken from https://bugs.openjdk.java.net/browse/JDK-8134679
* Helper methods for javafx binding. Some methods are taken from https://bugs.openjdk.java.net/browse/JDK-8134679
*/
public class BindingsHelper {

Expand All @@ -43,7 +42,7 @@ public static Subscription includePseudoClassWhen(Node node, PseudoClass pseudoC
}

public static <T, U> ObservableList<U> map(ObservableValue<T> source, Function<T, List<U>> mapper) {
PreboundBinding<List<U>> binding = new PreboundBinding<List<U>>(source) {
PreboundBinding<List<U>> binding = new PreboundBinding<>(source) {

@Override
protected List<U> computeValue() {
Expand All @@ -57,7 +56,7 @@ protected List<U> computeValue() {
}

/**
* Binds propertA bidirectional to propertyB using the provided map functions to convert between them.
* Binds propertyA bidirectional to propertyB using the provided map functions to convert between them.
*/
public static <A, B> void bindBidirectional(Property<A> propertyA, Property<B> propertyB, Function<A, B> mapAtoB, Function<B, A> mapBtoA) {
Consumer<B> updateA = newValueB -> propertyA.setValue(mapBtoA.apply(newValueB));
Expand All @@ -66,15 +65,14 @@ public static <A, B> void bindBidirectional(Property<A> propertyA, Property<B> p
}

/**
* Binds propertA bidirectional to propertyB while using updateB to update propertyB when propertyA changed.
* Binds propertyA bidirectional to propertyB while using updateB to update propertyB when propertyA changed.
*/
public static <A> void bindBidirectional(Property<A> propertyA, ObservableValue<A> propertyB, Consumer<A> updateB) {
bindBidirectional(propertyA, propertyB, propertyA::setValue, updateB);
}

/**
* Binds propertA bidirectional to propertyB using updateB to update propertyB when propertyA changed and similar
* for updateA.
* Binds propertyA bidirectional to propertyB using updateB to update propertyB when propertyA changed and similar for updateA.
*/
public static <A, B> void bindBidirectional(ObservableValue<A> propertyA, ObservableValue<B> propertyB, Consumer<B> updateA, Consumer<A> updateB) {
final BidirectionalBinding<A, B> binding = new BidirectionalBinding<>(propertyA, propertyB, updateA, updateB);
Expand Down Expand Up @@ -135,7 +133,7 @@ public static <A, V, B> void bindContentBidirectional(ObservableMap<A, V> proper
}

public static <T> ObservableValue<T> constantOf(T value) {
return new ObjectBinding<T>() {
return new ObjectBinding<>() {

@Override
protected T computeValue() {
Expand Down
Loading