Skip to content

Tabular UI for naming linked files #12624

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

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9b11edf
Add fix options for integrity issues
priyanshu16095 Feb 12, 2025
02d8e75
Fix the check
priyanshu16095 Feb 12, 2025
754b6ad
Add a missing entry for Localization.lang
priyanshu16095 Feb 12, 2025
696f904
Fix the check
priyanshu16095 Feb 12, 2025
4ab36a8
Refactor code
priyanshu16095 Feb 14, 2025
28de796
Fix the check
priyanshu16095 Feb 14, 2025
70ae8eb
Add a CHANGELOG.md entry
priyanshu16095 Feb 14, 2025
77df6ea
Refactor the code
priyanshu16095 Feb 19, 2025
30c81ce
Make use of IntegrityIssue enum
priyanshu16095 Feb 20, 2025
5b389da
Add keys in Localization.lang
priyanshu16095 Feb 20, 2025
3a0d9a1
Refactor the code
priyanshu16095 Feb 20, 2025
a04e06a
Remove use of enum
priyanshu16095 Feb 20, 2025
8e9341a
Remove use of enum from PageChecker class
priyanshu16095 Feb 20, 2025
235c74f
Add fixAll method
priyanshu16095 Feb 20, 2025
9839137
Add a check for fixAll and fixByType method
priyanshu16095 Feb 20, 2025
5754680
Fix a bug
priyanshu16095 Feb 20, 2025
8f7bdc2
Use dialogService.notify() to notify
priyanshu16095 Feb 22, 2025
f57719c
Remove unused imports
priyanshu16095 Feb 22, 2025
2105a13
Merge branch 'main' into integrityCheckActions
priyanshu16095 Feb 22, 2025
e37ba79
Merge branch 'main' into integrityCheckActions
priyanshu16095 Feb 23, 2025
139777e
Add tests for methods
priyanshu16095 Feb 25, 2025
39dbfd1
Fix the check and updates based on review
priyanshu16095 Feb 26, 2025
16e9817
Use enum for passing issue message
priyanshu16095 Feb 28, 2025
102e789
Fix the checkstyle check
priyanshu16095 Feb 28, 2025
92d91b5
Add the gui
priyanshu16095 Mar 3, 2025
b726f30
Add files in logic directory
priyanshu16095 Mar 5, 2025
86518fc
Revert changes in three files
priyanshu16095 Mar 5, 2025
6f985ec
Revert some more files
priyanshu16095 Mar 5, 2025
5ea4754
Revert some more files
priyanshu16095 Mar 5, 2025
237af3d
Revert changes
priyanshu16095 Mar 5, 2025
038f8e2
Revert changes
priyanshu16095 Mar 5, 2025
e5e4f75
Revert changes
priyanshu16095 Mar 5, 2025
7c7ddd1
Revert changes
priyanshu16095 Mar 5, 2025
3e795c7
Remove comment
priyanshu16095 Mar 5, 2025
1f84f0f
Rename variables
priyanshu16095 Mar 5, 2025
429af55
Show entry types in table
priyanshu16095 Mar 6, 2025
3c1708d
Add a CHANGELOG.md entry and Fix the check
priyanshu16095 Mar 6, 2025
995760a
Merge branch 'main' into tabularUI
priyanshu16095 Mar 6, 2025
0c44228
Add more patterns and solve dropdown UI issue
priyanshu16095 Mar 6, 2025
d0153e5
Change default pattern
priyanshu16095 Mar 6, 2025
6715540
Remove commented code
priyanshu16095 Mar 7, 2025
5036cf5
Remove commented method
priyanshu16095 Mar 7, 2025
5d5ada3
Add preference migration
priyanshu16095 Mar 11, 2025
88c9e4f
Merge branch 'main' of https://github.com/priyanshu16095/jabref into …
priyanshu16095 Mar 16, 2025
de46be4
Rename LinkedFileNamePattern and CitationKeyPattern to Pattern
priyanshu16095 Mar 21, 2025
279ce8f
Merge branch 'main' into tabularUI
priyanshu16095 Mar 21, 2025
a3383a2
Renmae LinkedFileNamePatternsPanelItemModel and CitationKeyPatternsIt…
priyanshu16095 Mar 21, 2025
967a4a5
Rename LinkedFileNamePatternsSuggestionCell and CitationKeyPatternsSu…
priyanshu16095 Mar 21, 2025
1261731
Fix the checkstyle check
priyanshu16095 Mar 21, 2025
965d4df
Remove the redundant check
priyanshu16095 Mar 21, 2025
a0a00ef
Fix the check
priyanshu16095 Mar 21, 2025
ba11cf3
Fix import in MetaDataParse.java
priyanshu16095 Mar 26, 2025
d000184
Rename Pattern to KeyPattern
priyanshu16095 Mar 31, 2025
2ef68ef
Add logic to store in FilePreference.java
priyanshu16095 Apr 10, 2025
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 @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a table for naming linked files in the Linked Files tab in Preferences. [#11368](https://github.com/JabRef/jabref/issues/11368)
- We added a feature to rename the subgroup, with the keybinding (<kbd>F2</kbd>) for quick access. [#11896](https://github.com/JabRef/jabref/issues/11896)
- We added a new functionality that displays a drop-down list of matching suggestions when typing a citation key pattern. [#12502](https://github.com/JabRef/jabref/issues/12502)
- We added a new CLI that supports txt, csv, and console-based output for consistency in BibTeX entries. [#11984](https://github.com/JabRef/jabref/issues/11984)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.jabref.gui.linkedfile;

import java.util.Objects;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.model.entry.types.EntryType;

public class LinkedFileNamePatternsItemModel {
private final ObjectProperty<EntryType> entryType = new SimpleObjectProperty<>();
private final StringProperty pattern = new SimpleStringProperty("");

public LinkedFileNamePatternsItemModel(EntryType entryType, String pattern) {
Objects.requireNonNull(entryType);
Objects.requireNonNull(pattern);
this.entryType.setValue(entryType);
this.pattern.setValue(pattern);
}

public EntryType getEntryType() {
return entryType.getValue();
}

public ObjectProperty<EntryType> entryType() {
return entryType;
}

public void setPattern(String pattern) {
this.pattern.setValue(pattern);
}

public String getPattern() {
return pattern.getValue();
}

public StringProperty pattern() {
return pattern;
}

@Override
public String toString() {
return "[" + entryType.getValue().getName() + "," + pattern.getValue() + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<fx:root editable="true" minWidth="280.0" type="TableView"
xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.jabref.gui.linkedfile.LinkedFileNamePatternsPanel">
<columns>
<TableColumn fx:id="entryTypeColumn" editable="false" minWidth="100.0" text="%Name"/>
<TableColumn fx:id="patternColumn" minWidth="100.0" text="%Key pattern"/>
<TableColumn fx:id="actionsColumn" editable="false" maxWidth="30.0" minWidth="30.0" prefWidth="30.0"
reorderable="false" resizable="false" sortable="false"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</fx:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package org.jabref.gui.linkedfile;

import java.util.Collection;

import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.input.KeyEvent;

import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.linkedfile.AbstractLinkedFileNamePatterns;
import org.jabref.logic.linkedfile.LinkedFileNamePattern;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.types.EntryType;

import com.airhacks.afterburner.views.ViewLoader;

public class LinkedFileNamePatternsPanel extends TableView<LinkedFileNamePatternsItemModel> {

@FXML public TableColumn<LinkedFileNamePatternsItemModel, EntryType> entryTypeColumn;
@FXML public TableColumn<LinkedFileNamePatternsItemModel, String> patternColumn;
@FXML public TableColumn<LinkedFileNamePatternsItemModel, EntryType> actionsColumn;

private LinkedFileNamePatternsPanelViewModel viewModel;

private long lastKeyPressTime;
private String tableSearchTerm;
private final ObservableList<String> patterns;

public LinkedFileNamePatternsPanel() {
super();
this.patterns = FXCollections.observableArrayList(
LinkedFileNamePattern.getAllPatterns().stream()
.map(LinkedFileNamePattern::stringRepresentation)
.toList()
);

ViewLoader.view(this)
.root(this)
.load();
}

@FXML
private void initialize() {
viewModel = new LinkedFileNamePatternsPanelViewModel();

this.setEditable(true);

entryTypeColumn.setSortable(true);
entryTypeColumn.setReorderable(false);
entryTypeColumn.setCellValueFactory(cellData -> cellData.getValue().entryType());
new ValueTableCellFactory<LinkedFileNamePatternsItemModel, EntryType>()
.withText(EntryType::getDisplayName)
.install(entryTypeColumn);
this.setOnSort(event ->
viewModel.patternListProperty().sort(LinkedFileNamePatternsPanelViewModel.defaultOnTopComparator));

patternColumn.setSortable(true);
patternColumn.setReorderable(false);
patternColumn.setCellValueFactory(cellData -> cellData.getValue().pattern());
patternColumn.setCellFactory(a -> new LinkedFileNamePatternsSuggestionCell(patterns));
patternColumn.setEditable(true);
patternColumn.setOnEditCommit(
(TableColumn.CellEditEvent<LinkedFileNamePatternsItemModel, String> event) ->
event.getRowValue().setPattern(event.getNewValue()));

actionsColumn.setSortable(false);
actionsColumn.setReorderable(false);
actionsColumn.setCellValueFactory(cellData -> cellData.getValue().entryType());
new ValueTableCellFactory<LinkedFileNamePatternsItemModel, EntryType>()
.withGraphic(entryType -> IconTheme.JabRefIcons.REFRESH.getGraphicNode())
.withTooltip(entryType ->
Localization.lang("Reset %s to default value").formatted(entryType.getDisplayName()))
.withOnMouseClickedEvent(item -> evt ->
viewModel.setItemToDefaultPattern(this.getFocusModel().getFocusedItem()))
.install(actionsColumn);

this.setRowFactory(item -> new HighlightTableRow());
this.setOnKeyTyped(this::jumpToSearchKey);
this.itemsProperty().bindBidirectional(viewModel.patternListProperty());
}

public void setValues(Collection<BibEntryType> entryTypeList, AbstractLinkedFileNamePatterns keyPattern) {
viewModel.setValues(entryTypeList, keyPattern);
}

public void resetAll() {
viewModel.resetAll();
}

public ListProperty<LinkedFileNamePatternsItemModel> patternListProperty() {
return viewModel.patternListProperty();
}

public ObjectProperty<LinkedFileNamePatternsItemModel> defaultNamePatternProperty() {
return viewModel.defaultNamePatternProperty();
}

private void jumpToSearchKey(KeyEvent keypressed) {
if (keypressed.getCharacter() == null) {
return;
}

if (System.currentTimeMillis() - lastKeyPressTime < 1000) {
tableSearchTerm += keypressed.getCharacter().toLowerCase();
} else {
tableSearchTerm = keypressed.getCharacter().toLowerCase();
}
Comment on lines +113 to +117
Copy link

Choose a reason for hiding this comment

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

The code uses a magic number '1000' which should be replaced with a named constant for better readability and maintainability.


lastKeyPressTime = System.currentTimeMillis();

this.getItems().stream().filter(item -> item.getEntryType().getName().toLowerCase().startsWith(tableSearchTerm))
.findFirst().ifPresent(this::scrollTo);
}

private static class HighlightTableRow extends TableRow<LinkedFileNamePatternsItemModel> {
@Override
public void updateItem(LinkedFileNamePatternsItemModel item, boolean empty) {
super.updateItem(item, empty);
if (item == null || item.getEntryType() == null) {
setStyle("");
} else if (isSelected()) {
setStyle("-fx-background-color: -fx-selection-bar");
} else if (LinkedFileNamePatternsPanelViewModel.ENTRY_TYPE_DEFAULT_NAME.equals(item.getEntryType().getName())) {
setStyle("-fx-background-color: -fx-default-button");
} else {
setStyle("");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.jabref.gui.linkedfile;

import java.util.Collection;
import java.util.Comparator;

import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;

import org.jabref.logic.l10n.Localization;
import org.jabref.logic.linkedfile.AbstractLinkedFileNamePatterns;
import org.jabref.logic.linkedfile.LinkedFileNamePattern;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.types.EntryType;

public class LinkedFileNamePatternsPanelViewModel {
public static final String ENTRY_TYPE_DEFAULT_NAME = "default";

public static Comparator<LinkedFileNamePatternsItemModel> defaultOnTopComparator = (o1, o2) -> {
String itemOneName = o1.getEntryType().getName();
String itemTwoName = o2.getEntryType().getName();

if (itemOneName.equals(itemTwoName)) {
return 0;
} else if (ENTRY_TYPE_DEFAULT_NAME.equals(itemOneName)) {
return -1;
} else if (ENTRY_TYPE_DEFAULT_NAME.equals(itemTwoName)) {
return 1;
}

return 0;
};

private final ListProperty<LinkedFileNamePatternsItemModel> patternListProperty = new SimpleListProperty<>();
private final ObjectProperty<LinkedFileNamePatternsItemModel> defaultItemProperty = new SimpleObjectProperty<>();

public LinkedFileNamePatternsPanelViewModel() { }

public void setValues(Collection<BibEntryType> entryTypeList, AbstractLinkedFileNamePatterns initialNamePattern) {
String defaultPattern;
if ((initialNamePattern.getDefaultValue() == null) || initialNamePattern.getDefaultValue().equals(LinkedFileNamePattern.NULL_LINKED_FILE_NAME_PATTERN)) {
defaultPattern = "";
} else {
defaultPattern = initialNamePattern.getDefaultValue().stringRepresentation();
}

defaultItemProperty.setValue(new LinkedFileNamePatternsItemModel(new DefaultEntryType(), defaultPattern));
patternListProperty.setValue(FXCollections.observableArrayList());
patternListProperty.add(defaultItemProperty.getValue());

entryTypeList.stream()
.map(BibEntryType::getType)
.forEach(entryType -> {
String pattern;
if (initialNamePattern.isDefaultValue(entryType)) {
pattern = "";
} else {
pattern = initialNamePattern.getPatterns().get(entryType).stringRepresentation();
}
patternListProperty.add(new LinkedFileNamePatternsItemModel(entryType, pattern));
});
}

public void setItemToDefaultPattern(LinkedFileNamePatternsItemModel item) {
item.setPattern(LinkedFileNamePattern.AUTHOR_YEAR.stringRepresentation());
}

public void resetAll() {
patternListProperty.forEach(item -> item.setPattern(""));
defaultItemProperty.getValue().setPattern(ENTRY_TYPE_DEFAULT_NAME);
}

public ListProperty<LinkedFileNamePatternsItemModel> patternListProperty() {
return patternListProperty;
}

public ObjectProperty<LinkedFileNamePatternsItemModel> defaultNamePatternProperty() {
return defaultItemProperty;
}

public static class DefaultEntryType implements EntryType {
@Override
public String getName() {
return ENTRY_TYPE_DEFAULT_NAME;
}

@Override
public String getDisplayName() {
return Localization.lang("Default pattern");
}
}
}
Loading