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

User specific comment #9727

Merged
merged 37 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
25180f8
Create user specific comment field
NiD133 Apr 1, 2023
c9abf69
User can make user-specific comments
NiD133 Apr 1, 2023
27cffa6
User specific comment will not display in other fields
NiD133 Apr 1, 2023
56aba71
Refactor the code
NiD133 Apr 1, 2023
b467264
Make changes
NiD133 Apr 1, 2023
29fb2d0
Make changes
NiD133 Apr 1, 2023
14e8b6d
Force to make user specific comments
NiD133 Apr 1, 2023
18bc42b
Fix error
NiD133 Apr 1, 2023
2337579
Test if to show the other user's comments
NiD133 Apr 2, 2023
a70f5d2
Delete useless code
NiD133 Apr 2, 2023
248cf4f
Add changes in CHANGELOG
NiD133 Apr 2, 2023
e3c988a
Merge branch 'main' into user_specific_comment
Siedlerchr Apr 2, 2023
7c390fb
Merge branch 'main' into user_specific_comment
koppor Apr 4, 2023
115c7e3
Make changes only author can edit user specific comment
NiD133 Apr 5, 2023
86d284d
Merge remote-tracking branch 'origin/user_specific_comment' into user…
NiD133 Apr 5, 2023
0be6fe2
Specify the user specific comment does not belong to current user
NiD133 Apr 6, 2023
fd362e9
Add test case for comments tab
NiD133 Apr 6, 2023
4410553
Refactor code based on the feedback
NiD133 May 22, 2023
f023fec
Refactor tests about the CommentsTab
NiD133 May 24, 2023
8d76630
Add missing localization keys in the English language file.
NiD133 May 24, 2023
1a8a5b6
Merge branch 'main' into user_specific_comment
Siedlerchr May 24, 2023
7f2e445
Modify the failing checkstyle tests
NiD133 May 26, 2023
058115d
Modify the order of import
NiD133 May 26, 2023
ea57028
Separate the UndoManager import
NiD133 May 26, 2023
1e92667
Make changes
NiD133 May 26, 2023
dc8f4de
Update the user specific comment field
NiD133 May 27, 2023
24d11cb
Remove the dependency on the entry type for presence of comments
NiD133 May 27, 2023
6db3b35
Change code for checkstyle
NiD133 May 27, 2023
87947d1
Additional logic to parseField to better handle user specific comment.
NiD133 May 28, 2023
66f945a
Fetch the username using PreferencesService to improve simplicity.
NiD133 Jun 4, 2023
2d3ac52
Merge branch 'main' into user_specific_comment
koppor Jun 6, 2023
0d7da65
Merge "All-Comments" into tab "Comments"
koppor Jun 6, 2023
7d2099b
Minor code beautification
koppor Jun 6, 2023
e1bf03a
Simplify tests (and add one more test)
koppor Jun 6, 2023
0abf13b
Always list "Comment" field
koppor Jun 6, 2023
9d07247
Refine CHANGELOG entry
koppor Jun 6, 2023
5ecb0e6
Remove tool tip (not containing much additional information)
koppor Jun 6, 2023
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 @@ -12,6 +12,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
### Added

- We added a field showing the BibTeX/biblatex source for added and deleted entries in the "External Changes Resolver" dialog. [#9509](https://github.com/JabRef/jabref/issues/9509)
- We added user specific comment field so that user can make comments with username suffix.[#543](https://github.com/koppor/jabref/issues/543)
- We added a search history list in the search field's right click menu. [#7906](https://github.com/JabRef/jabref/issues/7906)
- We added a full text fetcher for IACR eprints. [#9651](https://github.com/JabRef/jabref/pull/9651)
- We added "Attach file from URL" to right-click context menu to download and store a file with the reference library. [#9646](https://github.com/JabRef/jabref/issues/9646)
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/CommentsTab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.jabref.gui.entryeditor;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javax.swing.undo.UndoManager;

import javafx.scene.control.Tooltip;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.search.indexing.IndexingTaskManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UserSpecificCommentField;
import org.jabref.preferences.PreferencesService;

public class CommentsTab extends FieldsEditorTab {

private final BibEntryTypesManager entryTypesManager;

private final String name;
public CommentsTab(String name,
BibDatabaseContext databaseContext,
SuggestionProviders suggestionProviders,
UndoManager undoManager,
DialogService dialogService,
PreferencesService preferences,
StateManager stateManager,
ThemeManager themeManager,
IndexingTaskManager indexingTaskManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository) {
super(
false,
databaseContext,
suggestionProviders,
undoManager,
dialogService,
preferences,
stateManager,
themeManager,
taskExecutor,
journalAbbreviationRepository,
indexingTaskManager
);
this.entryTypesManager = entryTypesManager;
this.name = name;
setText(Localization.lang("All comments"));
setTooltip(new Tooltip(Localization.lang("Display all comments")));
setGraphic(IconTheme.JabRefIcons.REQUIRED.getGraphicNode());
}

protected Set<Field> determineFieldsToShow(BibEntry entry) {
BibDatabaseMode mode = databaseContext.getMode();
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), mode);

if (entryType.isPresent()) {
UserSpecificCommentField defaultCommentField = new UserSpecificCommentField(name);
Set<Field> comments = new LinkedHashSet<>();
comments.add(defaultCommentField);

comments.addAll(entry.getFields().stream()
.filter(field -> field.equals(StandardField.COMMENT) || field instanceof UserSpecificCommentField || field.getName().toLowerCase().contains("comment"))
.collect(Collectors.toSet()));

return comments;
} else {
// Entry type unknown -> treat all fields as required
return Collections.emptySet();
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ private List<EntryEditorTab> createTabs() {
// Other fields
entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));

// Comment Tab
entryEditorTabs.add(new CommentsTab(preferencesService.getOwnerPreferences().getDefaultOwner(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));

// General fields from preferences
for (Map.Entry<String, Set<Field>> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) {
entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), taskExecutor, journalAbbreviationRepository));
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/OtherFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.BibField;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldProperty;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.UserSpecificCommentField;
import org.jabref.preferences.PreferencesService;

public class OtherFieldsTab extends FieldsEditorTab {
Expand Down Expand Up @@ -72,8 +74,9 @@ protected Set<Field> determineFieldsToShow(BibEntry entry) {
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), mode);
if (entryType.isPresent()) {
Set<Field> allKnownFields = entryType.get().getAllFields();
Set<Field> otherFields = entry.getFields().stream().filter(field -> !allKnownFields.contains(field)).collect(Collectors.toCollection(LinkedHashSet::new));

Set<Field> otherFields = entry.getFields().stream()
.filter(field -> !allKnownFields.contains(field) && !field.getName().toLowerCase().contains("comment"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be startsWith and comment-, because UserSpecificCommentField.java is implemented like that.

Maybe also check for plain comment in addition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the following not work here?

(that code is from above)

   field -> field.equals(StandardField.COMMENT) || field instanceof UserSpecificCommentField

.collect(Collectors.toCollection(LinkedHashSet::new));
otherFields.removeAll(entryType.get().getDeprecatedFields(mode));
otherFields.removeAll(entryType.get().getOptionalFields().stream().map(BibField::field).collect(Collectors.toSet()));
otherFields.remove(InternalField.KEY_FIELD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private static Set<Field> getAllFields() {
fields.addAll(EnumSet.allOf(InternalField.class));
fields.addAll(EnumSet.allOf(SpecialField.class));
fields.addAll(EnumSet.allOf(StandardField.class));
fields.removeIf(field -> field instanceof UserSpecificCommentField);
return fields;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public enum FieldProperty {
SINGLE_ENTRY_LINK,
TYPE,
VERBATIM,
YES_NO
YES_NO,
COMMENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum StandardField implements Field {
BOOKTITLEADDON("booktitleaddon"),
CHAPTER("chapter"),
COMMENTATOR("commentator", FieldProperty.PERSON_NAMES),
COMMENT("comment"),
COMMENT("comment", FieldProperty.COMMENT),
CROSSREF("crossref", FieldProperty.SINGLE_ENTRY_LINK),
DATE("date", FieldProperty.DATE),
DAY("day"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.jabref.model.entry.field;

import java.util.EnumSet;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;

public class UserSpecificCommentField implements Field {
private final String name;
private final Set<FieldProperty> properties;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be static final


public UserSpecificCommentField(String username) {
this.name = "comment-" + username;
this.properties = EnumSet.of(FieldProperty.COMMENT);
}

@Override
public Set<FieldProperty> getProperties() {
return properties;
}

@Override
public String getName() {
return name;
}

@Override
public boolean isStandardField() {
return false;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Field)) {
return false;
}
Field other = (Field) o;
return name.equalsIgnoreCase(other.getName());
}

@Override
public int hashCode() {
return Objects.hash(name.toLowerCase(Locale.ENGLISH));
}

@Override
public String toString() {
return "UnknownCommentField{" +
"name='" + name + '\'' +
'}';
}
}