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

GUI for consistency check #12433

Merged
merged 34 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7d7a7f8
Create simple table UI
priyanshu16095 Jan 27, 2025
77150ba
Add combox for entry type
priyanshu16095 Jan 30, 2025
46efae8
Add a CHANGELOG.md entry
priyanshu16095 Jan 30, 2025
31fe861
Merge branch 'main' into consistencyGuiCheck
priyanshu16095 Jan 30, 2025
09723ce
Correct a typo in JabRef_en.properties
priyanshu16095 Jan 30, 2025
9df0562
Merge branch 'consistencyGuiCheck' of https://github.com/priyanshu160…
priyanshu16095 Jan 30, 2025
3b250f1
Make use of view model class
priyanshu16095 Jan 31, 2025
09251a8
Changes according to reviews
priyanshu16095 Feb 1, 2025
35e01fb
Update CHANGELOG.md
priyanshu16095 Feb 2, 2025
dc25fbb
Run tasks in background
priyanshu16095 Feb 2, 2025
0f2357f
Merge branch 'consistencyGuiCheck' of https://github.com/priyanshu160…
priyanshu16095 Feb 2, 2025
c8168e5
Table shows data properly
priyanshu16095 Feb 3, 2025
af407a0
Add regex in string builder
priyanshu16095 Feb 3, 2025
bf5ad84
Add jump to the selected row feature
priyanshu16095 Feb 3, 2025
a2fe47f
Add entry type filter and make use of background task
priyanshu16095 Feb 3, 2025
690e30b
Pass the unit tests check
priyanshu16095 Feb 3, 2025
3d8be2b
Remove the dialog box content
priyanshu16095 Feb 3, 2025
00d16a5
Add icons and dialog for information
priyanshu16095 Feb 4, 2025
1d30f6a
Rename icon names and add removed lines from JabRef_en.properties
priyanshu16095 Feb 5, 2025
1035150
Correct a typo in JabRef_en.properties
priyanshu16095 Feb 5, 2025
7ac0404
Pass the checks
priyanshu16095 Feb 5, 2025
205f2e2
Use enum for symbols
priyanshu16095 Feb 7, 2025
aab4f36
Update CHANGELOG.md
priyanshu16095 Feb 7, 2025
39ef76d
Add horizontal scrolling inside table
priyanshu16095 Feb 7, 2025
23968c1
Merge branch 'main' into consistencyGuiCheck
priyanshu16095 Feb 7, 2025
2faabdd
Update ConsistencyCheckDialog.fxml
priyanshu16095 Feb 7, 2025
a6f8c65
Update src/main/java/org/jabref/gui/consistency/ConsistencyCheckDialo…
priyanshu16095 Feb 8, 2025
13b21dd
Define variable EXTRA_COLUMNS_COUNT
priyanshu16095 Feb 8, 2025
2e8cd0b
Use stream in consistencydialog.fromText method
priyanshu16095 Feb 9, 2025
5832df6
Merge branch 'main' into consistencyGuiCheck
priyanshu16095 Feb 9, 2025
1d0fd15
Correct the icon description
priyanshu16095 Feb 9, 2025
ebb4460
correct l10n
Siedlerchr Feb 9, 2025
3e7afcb
intellij suggestions
Siedlerchr Feb 9, 2025
9dda8d7
Remove unnecessary comment
priyanshu16095 Feb 9, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a GUI for bibliography consistency check. [#11950](https://github.com/JabRef/jabref/pull/12433)

### Changed

- We improved the offline parsing of BibTeX data from PDF-documents. [#12278](https://github.com/JabRef/jabref/issues/12278)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public enum StandardActions implements Action {
MERGE_ENTRIES(Localization.lang("Merge entries"), IconTheme.JabRefIcons.MERGE_ENTRIES, KeyBinding.MERGE_ENTRIES),
RESOLVE_DUPLICATE_KEYS(Localization.lang("Resolve duplicate citation keys"), Localization.lang("Find and remove duplicate citation keys"), KeyBinding.RESOLVE_DUPLICATE_CITATION_KEYS),
CHECK_INTEGRITY(Localization.lang("Check integrity"), KeyBinding.CHECK_INTEGRITY),
CHECK_CONSISTENCY(Localization.lang("Check consistency"), KeyBinding.CHECK_CONSISTENCY),
FIND_UNLINKED_FILES(Localization.lang("Search for unlinked local files"), IconTheme.JabRefIcons.SEARCH, KeyBinding.FIND_UNLINKED_FILES),
AUTO_LINK_FILES(Localization.lang("Automatically set file links"), IconTheme.JabRefIcons.AUTO_FILE_LINK, KeyBinding.AUTOMATICALLY_LINK_FILES),
LOOKUP_DOC_IDENTIFIER(Localization.lang("Search document identifier online")),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jabref.gui.consistency;

import java.util.List;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheck;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

public class ConsistencyCheckAction extends SimpleCommand {

private final DialogService dialogService;
private final StateManager stateManager;
private final GuiPreferences preferences;

public ConsistencyCheckAction(DialogService dialogService, StateManager stateManager, GuiPreferences preferences) {
this.dialogService = dialogService;
this.stateManager = stateManager;
this.preferences = preferences;
}

@Override
public void execute() {
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null"));
List<BibEntry> entries = databaseContext.getDatabase().getEntries();

BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck();
BibliographyConsistencyCheck.Result result = consistencyCheck.check(entries);

dialogService.showCustomDialogAndWait(new ConsistencyCheckDialog(result, dialogService, preferences));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<DialogPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="600.0" prefWidth="1200.0"
xmlns="http://javafx.com/javafx/8.0.121" fx:controller="org.jabref.gui.consistency.ConsistencyCheckDialog">
<content>
<VBox spacing="10.0">
<TableView fx:id="tableView" prefHeight="550" prefWidth="1200.0" VBox.vgrow="ALWAYS" HBox.hgrow="ALWAYS">
<columns>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN"/>
</columnResizePolicy>
</TableView>
<HBox spacing="4.0" alignment="CENTER">
<Label text="%Entry type"/>
<ComboBox fx:id="entryTypeCombo" maxWidth="Infinity" HBox.hgrow="ALWAYS" />
<Button onAction="#selectEntry" text="%Select">
<tooltip>
<Tooltip text="%Shows results for the selected entry type."/>
</tooltip>
</Button>
</HBox>
<HBox spacing="4.0">
<Button onAction="#exportAsCsv" text="%Export as csv file" />
<Button onAction="#exportAsTxt" text="%Export as txt file" alignment="CENTER_LEFT" />
</HBox>
</VBox>
</content>
<ButtonType fx:constant="CLOSE"/>
</DialogPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.jabref.gui.consistency;

import java.util.Collection;

import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;

import org.jabref.gui.DialogService;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.util.BaseDialog;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheck;
import org.jabref.logic.quality.consistency.ConsistencyMessage;
import org.jabref.model.entry.field.Field;

import com.airhacks.afterburner.views.ViewLoader;

public class ConsistencyCheckDialog extends BaseDialog<Void> {

@FXML private TableView<ConsistencyMessage> tableView;
@FXML private ComboBox<String> entryTypeCombo;

private final BibliographyConsistencyCheck.Result result;
private final DialogService dialogService;
private final GuiPreferences preferences;
private String selectedEntry;

private ConsistencyCheckDialogViewModel viewModel;

public ConsistencyCheckDialog(BibliographyConsistencyCheck.Result result, DialogService dialogService, GuiPreferences preferences) {
this.result = result;
this.dialogService = dialogService;
this.preferences = preferences;

this.setTitle(Localization.lang("Check consistency"));
this.initModality(Modality.NONE);

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

public ConsistencyCheckDialogViewModel getViewModel() {
return viewModel;
}

@FXML
public void initialize() {
viewModel = new ConsistencyCheckDialogViewModel(result, dialogService, preferences);

result.entryTypeToResultMap().forEach((entrySet, entryTypeResult) -> {
entryTypeCombo.getItems().add(entrySet.toString());

Collection<Field> fields = entryTypeResult.fields();
for (Field field: fields) {
TableColumn<ConsistencyMessage, String> tableColumn = new TableColumn<>(field.toString());
tableColumn.setCellValueFactory(new PropertyValueFactory<>(field.toString()));
tableView.getColumns().add(tableColumn);
}
});

entryTypeCombo.getSelectionModel().select(entryTypeCombo.getItems().getFirst());
}

public void selectEntry() {
selectedEntry = entryTypeCombo.getSelectionModel().getSelectedItem();
}

public void exportAsCsv() {
viewModel.startExportAsCsv();
}

public void exportAsTxt() {
viewModel.startExportAsTxt();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jabref.gui.consistency;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheck;
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultCsvWriter;
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultTxtWriter;
import org.jabref.logic.util.StandardFileType;

public class ConsistencyCheckDialogViewModel extends AbstractViewModel {
private final DialogService dialogService;
private final GuiPreferences preferences;
private final BibliographyConsistencyCheck.Result result;

public ConsistencyCheckDialogViewModel(BibliographyConsistencyCheck.Result result, DialogService dialogService, GuiPreferences preferences) {
this.result = result;
this.dialogService = dialogService;
this.preferences = preferences;
}

public void startExportAsTxt() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory())
.addExtensionFilter(StandardFileType.TXT)
.withDefaultExtension(StandardFileType.TXT)
.build();
Optional<Path> exportPath = dialogService.showFileSaveDialog(fileDialogConfiguration);

if (exportPath.isEmpty()) {
return;
}

try (Writer writer = new OutputStreamWriter(Files.newOutputStream(exportPath.get()))) {
BibliographyConsistencyCheckResultTxtWriter bibliographyConsistencyCheckResultTxtWriter = new BibliographyConsistencyCheckResultTxtWriter(result, writer);
bibliographyConsistencyCheckResultTxtWriter.writeFindings();
} catch (IOException e) {
dialogService.notify(Localization.lang("Failed to export file!"));
}
}

public void startExportAsCsv() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory())
.addExtensionFilter(StandardFileType.TXT)
.withDefaultExtension(StandardFileType.TXT)
.build();
Optional<Path> exportPath = dialogService.showFileSaveDialog(fileDialogConfiguration);

try (Writer writer = new OutputStreamWriter(Files.newOutputStream(exportPath.get()))) {
BibliographyConsistencyCheckResultCsvWriter bibliographyConsistencyCheckResultTxtWriter = new BibliographyConsistencyCheckResultCsvWriter(result, writer);
bibliographyConsistencyCheckResultTxtWriter.writeFindings();
} catch (IOException e) {
dialogService.notify(Localization.lang("Failed to export file!"));
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/frame/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jabref.gui.auximport.NewSubLibraryAction;
import org.jabref.gui.citationkeypattern.GenerateCitationKeyAction;
import org.jabref.gui.cleanup.CleanupAction;
import org.jabref.gui.consistency.ConsistencyCheckAction;
import org.jabref.gui.copyfiles.CopyFilesAction;
import org.jabref.gui.documentviewer.ShowDocumentViewerAction;
import org.jabref.gui.duplicationFinder.DuplicateSearch;
Expand Down Expand Up @@ -245,6 +246,7 @@ private void createMenu() {
factory.createMenuItem(StandardActions.FIND_DUPLICATES, new DuplicateSearch(frame::getCurrentLibraryTab, dialogService, stateManager, preferences, entryTypesManager, taskExecutor)),
factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(dialogService, stateManager, undoManager, preferences)),
factory.createMenuItem(StandardActions.CHECK_INTEGRITY, new IntegrityCheckAction(frame::getCurrentLibraryTab, preferences, dialogService, stateManager, (UiTaskExecutor) taskExecutor, abbreviationRepository)),
factory.createMenuItem(StandardActions.CHECK_CONSISTENCY, new ConsistencyCheckAction(dialogService, stateManager, preferences)),
factory.createMenuItem(StandardActions.CLEANUP_ENTRIES, new CleanupAction(frame::getCurrentLibraryTab, preferences, dialogService, stateManager, taskExecutor, undoManager)),

new SeparatorMenuItem(),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/keyboard/KeyBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum KeyBinding {
ACCEPT("Accept", Localization.lang("Accept"), "ctrl+ENTER", KeyBindingCategory.EDIT),
AUTOMATICALLY_LINK_FILES("Automatically link files", Localization.lang("Automatically set file links"), "F7", KeyBindingCategory.QUALITY),
CHECK_INTEGRITY("Check integrity", Localization.lang("Check integrity"), "ctrl+F8", KeyBindingCategory.QUALITY),
CHECK_CONSISTENCY("Check consistency", Localization.lang("Check consistency"), "ctrl+F9", KeyBindingCategory.QUALITY),
CLEANUP("Cleanup", Localization.lang("Cleanup entries"), "alt+F8", KeyBindingCategory.QUALITY),
CLOSE_DATABASE("Close library", Localization.lang("Close library"), "ctrl+W", KeyBindingCategory.FILE),
CLOSE("Close dialog", Localization.lang("Close dialog"), "Esc", KeyBindingCategory.VIEW),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.jabref.logic.quality.consistency;

public class ConsistencyMessage {

public ConsistencyMessage() { }
}
8 changes: 8 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,14 @@ Line\ %0\:\ Found\ corrupted\ citation\ key\ %1\ (comma\ missing).=Line %0: Foun
Check\ integrity=Check integrity
Checking\ integrity...=Checking integrity...

Check\ consistency=Check consistency
Select=Select
Entry\ type=Entry type
Export\ as\ csv\ file =Export as csv file
Export\ as\ txt\ file =Export as txt file
Shows\ results\ for\ the\ selected\ entry\ type.=Show results for the selected entry type.
Failed\ to\ export\ file!=Failed to export file!

Field\ Presence\ Consistency\ Check\ Result=Field Presence Consistency Check Result
required\ field\ is\ present=required field is present
optional\ field\ is\ present=optional field is present
Expand Down