-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Automatic field editor: Add Clear content tab + viewmodel #13824
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
Merged
calixtus
merged 11 commits into
JabRef:main
from
Akanksha928:feat/automatic-field-editor-clear-tab
Oct 7, 2025
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
137fddf
Automatic field editor: Add Clear content tab + viewmodel
Akanksha928 bb07ec4
Removing comments
Akanksha928 6c2e29a
PR comment changes
Akanksha928 e8185b1
Bot suggested changes
Akanksha928 9afbe20
Bot suggested changes
Akanksha928 c0edaaf
merge
Siedlerchr 3320a9d
reformat
Siedlerchr acd1ddb
fix fxml
Siedlerchr 049fa0d
Added tests, reformats and visual modifications. Fixed number of affe…
calixtus c1a059b
Fixed tab number
calixtus 2a6a62e
CHANGELOG.md
calixtus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...c/main/java/org/jabref/gui/edit/automaticfiededitor/clearcontent/ClearContentTabView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package org.jabref.gui.edit.automaticfiededitor.clearcontent; | ||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.control.CheckBox; | ||
| import javafx.scene.control.ComboBox; | ||
|
|
||
| import org.jabref.gui.StateManager; | ||
| import org.jabref.gui.edit.automaticfiededitor.AbstractAutomaticFieldEditorTabView; | ||
| import org.jabref.gui.edit.automaticfiededitor.AutomaticFieldEditorTab; | ||
| import org.jabref.logic.l10n.Localization; | ||
| import org.jabref.model.entry.field.Field; | ||
|
|
||
| import com.airhacks.afterburner.views.ViewLoader; | ||
|
|
||
| import static org.jabref.gui.util.FieldsUtil.FIELD_STRING_CONVERTER; | ||
|
|
||
| public class ClearContentTabView extends AbstractAutomaticFieldEditorTabView implements AutomaticFieldEditorTab { | ||
|
|
||
| @FXML private ComboBox<Field> fieldComboBox; | ||
| @FXML private CheckBox showOnlySetFieldsCheckBox; | ||
| @FXML private Button clearButton; | ||
| private final StateManager stateManager; | ||
| private ClearContentViewModel viewModel; | ||
|
|
||
| public ClearContentTabView(StateManager stateManager) { | ||
| this.stateManager = stateManager; | ||
| ViewLoader.view(this) | ||
| .root(this) | ||
| .load(); | ||
| } | ||
|
|
||
| @FXML | ||
| public void initialize() { | ||
| viewModel = new ClearContentViewModel(stateManager); | ||
|
|
||
| fieldComboBox.setConverter(FIELD_STRING_CONVERTER); | ||
|
|
||
| fieldComboBox.getItems().setAll(viewModel.getAllFields()); | ||
|
|
||
| if (!fieldComboBox.getItems().isEmpty()) { | ||
| fieldComboBox.getSelectionModel().selectFirst(); | ||
| } | ||
| showOnlySetFieldsCheckBox.setOnAction(e -> { | ||
| var items = showOnlySetFieldsCheckBox.isSelected() | ||
| ? viewModel.getSetFieldsOnly() | ||
| : viewModel.getAllFields(); | ||
| fieldComboBox.getItems().setAll(items); | ||
| if (!items.isEmpty()) { | ||
| fieldComboBox.getSelectionModel().selectFirst(); | ||
| } | ||
| }); | ||
|
|
||
| clearButton.disableProperty().bind(fieldComboBox.valueProperty().isNull()); | ||
|
|
||
| Platform.runLater(fieldComboBox::requestFocus); | ||
| } | ||
|
|
||
| @FXML | ||
| private void onClear() { | ||
| Field chosen = fieldComboBox.getValue(); | ||
| if (chosen != null) { | ||
| viewModel.clearField(chosen); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getTabName() { | ||
| return Localization.lang("Clear content"); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
...main/java/org/jabref/gui/edit/automaticfiededitor/clearcontent/ClearContentViewModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package org.jabref.gui.edit.automaticfiededitor.clearcontent; | ||
|
|
||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.jabref.gui.StateManager; | ||
| import org.jabref.gui.edit.automaticfiededitor.LastAutomaticFieldEditorEdit; | ||
| import org.jabref.gui.undo.NamedCompound; | ||
| import org.jabref.gui.undo.UndoableFieldChange; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.field.Field; | ||
| import org.jabref.model.entry.field.FieldFactory; | ||
|
|
||
| public class ClearContentViewModel { | ||
|
|
||
| private final StateManager stateManager; | ||
|
|
||
| public ClearContentViewModel(StateManager stateManager) { | ||
| this.stateManager = stateManager; | ||
| } | ||
|
|
||
| public Set<Field> getAllFields() { | ||
| return FieldFactory.getAllFieldsWithOutInternal(); | ||
| } | ||
|
|
||
| public Set<Field> getSetFieldsOnly() { | ||
| return stateManager.getSelectedEntries().stream() | ||
| .flatMap(entry -> entry.getFields().stream() | ||
| .filter(f -> entry.getField(f).isPresent() && !entry.getField(f).get().isBlank())) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new)); | ||
| } | ||
|
|
||
| public void clearField(Field field) { | ||
| NamedCompound edits = new NamedCompound("Clear field content"); | ||
| List<BibEntry> selected = stateManager.getSelectedEntries(); | ||
|
|
||
| for (BibEntry entry : selected) { | ||
| entry.clearField(field).ifPresent(change -> | ||
| edits.addEdit(new UndoableFieldChange(change)) | ||
| ); | ||
| } | ||
|
|
||
| if (edits.hasEdits()) { | ||
| edits.end(); | ||
| stateManager.setLastAutomaticFieldEditorEdit( | ||
| new LastAutomaticFieldEditorEdit(selected.size(), 1, edits) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../main/resources/org/jabref/gui/edit/automaticfiededitor/clearcontent/ClearContentTab.fxml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.geometry.Insets?> | ||
| <?import javafx.scene.control.Button?> | ||
| <?import javafx.scene.control.CheckBox?> | ||
| <?import javafx.scene.control.ComboBox?> | ||
| <?import javafx.scene.control.Label?> | ||
| <?import javafx.scene.layout.AnchorPane?> | ||
| <?import javafx.scene.layout.ColumnConstraints?> | ||
| <?import javafx.scene.layout.GridPane?> | ||
| <?import javafx.scene.layout.HBox?> | ||
| <?import javafx.scene.layout.RowConstraints?> | ||
| <fx:root prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.edit.automaticfiededitor.clearcontent.ClearContentTabView"> | ||
| <children> | ||
| <GridPane hgap="8.0" prefWidth="568.0" vgap="8.0" AnchorPane.leftAnchor="16.0" AnchorPane.rightAnchor="16.0" AnchorPane.topAnchor="0.0"> | ||
| <columnConstraints> | ||
| <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> | ||
| <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> | ||
| <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/> | ||
| </columnConstraints> | ||
| <rowConstraints> | ||
| <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
| <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
| <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
| </rowConstraints> | ||
| <children> | ||
| <HBox alignment="BOTTOM_LEFT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" GridPane.hgrow="ALWAYS" GridPane.rowSpan="2" GridPane.vgrow="ALWAYS"> | ||
| <children> | ||
| <Label styleClass="sectionHeader" text="%Clear field content for selected entries"> | ||
| <HBox.margin><Insets bottom="10.0"/></HBox.margin> | ||
| </Label> | ||
| </children> | ||
| </HBox> | ||
| <HBox spacing="8.0" GridPane.rowIndex="2" GridPane.columnSpan="3" GridPane.hgrow="ALWAYS"> | ||
| <children> | ||
| <ComboBox fx:id="fieldComboBox" prefHeight="36.0" editable="true" HBox.hgrow="ALWAYS" /> | ||
| <CheckBox fx:id="showOnlySetFieldsCheckBox" text="%Show only set fields"/> | ||
| </children> | ||
| </HBox> | ||
| <HBox spacing="8.0" GridPane.rowIndex="3" GridPane.columnSpan="3"> | ||
| <children> | ||
| <Button fx:id="clearButton" text="%Clear field content" onAction="#onClear"/> | ||
| </children> | ||
| </HBox> | ||
| </children> | ||
| </GridPane> | ||
| </children> | ||
| </fx:root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.