-
-
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 all 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
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
73 changes: 73 additions & 0 deletions
73
...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,73 @@ | ||
package org.jabref.gui.edit.automaticfiededitor.clearcontent; | ||
|
||
import java.util.Set; | ||
|
||
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 com.tobiasdiez.easybind.EasyBind; | ||
|
||
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(); | ||
} | ||
|
||
EasyBind.subscribe(showOnlySetFieldsCheckBox.selectedProperty(), selected -> { | ||
Set<Field> items = selected ? 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"); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...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,59 @@ | ||
package org.jabref.gui.edit.automaticfiededitor.clearcontent; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Optional; | ||
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.NamedCompoundEdit; | ||
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 { | ||
public static final int TAB_INDEX = 2; | ||
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) { | ||
NamedCompoundEdit edits = new NamedCompoundEdit("CLEAR_SELECTED_FIELD"); | ||
List<BibEntry> selected = stateManager.getSelectedEntries(); | ||
int affectedEntriesCount = 0; | ||
for (BibEntry entry : selected) { | ||
Optional<String> oldFieldValue = entry.getField(field); | ||
if (oldFieldValue.isPresent()) { | ||
entry.clearField(field) | ||
.ifPresent(change -> edits.addEdit(new UndoableFieldChange(change))); | ||
affectedEntriesCount++; | ||
} | ||
} | ||
|
||
if (edits.hasEdits()) { | ||
edits.end(); | ||
} | ||
stateManager.setLastAutomaticFieldEditorEdit( | ||
new LastAutomaticFieldEditorEdit( | ||
affectedEntriesCount, | ||
TAB_INDEX, | ||
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
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
51 changes: 51 additions & 0 deletions
51
.../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,51 @@ | ||
<?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.ColumnConstraints?> | ||
<?import javafx.scene.layout.GridPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.RowConstraints?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import org.jabref.gui.icon.JabRefIconView?> | ||
<fx:root prefHeight="400.0" prefWidth="600.0" type="VBox" styleClass="edit-field-content-pane" | ||
xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" | ||
fx:controller="org.jabref.gui.edit.automaticfiededitor.clearcontent.ClearContentTabView"> | ||
<GridPane hgap="8.0" prefWidth="568.0" vgap="8.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> | ||
<HBox alignment="BOTTOM_LEFT" | ||
maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" | ||
minHeight="-Infinity" minWidth="-Infinity" | ||
GridPane.hgrow="ALWAYS" GridPane.rowSpan="2" GridPane.vgrow="ALWAYS"> | ||
<Label styleClass="sectionHeader" | ||
text="%Clear field content for selected entries"> | ||
<HBox.margin> | ||
<Insets bottom="10.0"/> | ||
</HBox.margin> | ||
</Label> | ||
</HBox> | ||
<HBox spacing="8.0" GridPane.rowIndex="2" GridPane.columnSpan="3" GridPane.hgrow="ALWAYS"> | ||
<ComboBox fx:id="fieldComboBox" prefHeight="36.0" editable="true" HBox.hgrow="ALWAYS" /> | ||
<CheckBox fx:id="showOnlySetFieldsCheckBox" text="%Show only set fields"/> | ||
</HBox> | ||
<HBox spacing="8.0" GridPane.rowIndex="3" GridPane.columnSpan="3"> | ||
<Button fx:id="clearButton" text="%Clear field content" onAction="#onClear"> | ||
<graphic> | ||
<JabRefIconView glyph="DELETE_ENTRY"/> | ||
</graphic> | ||
</Button> | ||
</HBox> | ||
</GridPane> | ||
</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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TAB_INDEX constant is horrible, but is actually consistent with the current design of the dialog. Neccessary for the fancy infotext about affected files after applying the change. Should be refactored in the future, but for now, it can just stay.