Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.StateManager;
import org.jabref.gui.edit.automaticfiededitor.clearcontent.ClearContentTabView;
import org.jabref.gui.edit.automaticfiededitor.copyormovecontent.CopyOrMoveFieldContentTabView;
import org.jabref.gui.edit.automaticfiededitor.editfieldcontent.EditFieldContentTabView;
import org.jabref.gui.edit.automaticfiededitor.renamefield.RenameFieldTabView;
Expand All @@ -28,6 +29,7 @@ public AutomaticFieldEditorViewModel(List<BibEntry> selectedEntries, BibDatabase
fieldEditorTabs.addAll(
new EditFieldContentTabView(database, stateManager),
new CopyOrMoveFieldContentTabView(database, stateManager),
new ClearContentTabView(stateManager),
new RenameFieldTabView(database, stateManager)
);
}
Expand Down
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");
}
}
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)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

public class EditFieldContentTabView extends AbstractAutomaticFieldEditorTabView {
public Button appendValueButton;
public Button clearFieldButton;
public Button setValueButton;
@FXML
private ComboBox<Field> fieldComboBox;
Expand Down Expand Up @@ -72,7 +71,6 @@ public void initialize() {

appendValueButton.disableProperty().bind(viewModel.canAppendProperty().not());
setValueButton.disableProperty().bind(viewModel.fieldValidationStatus().validProperty().not());
clearFieldButton.disableProperty().bind(viewModel.fieldValidationStatus().validProperty().not());
overwriteFieldContentCheckBox.disableProperty().bind(viewModel.fieldValidationStatus().validProperty().not());

Platform.runLater(() -> visualizer.initVisualization(viewModel.fieldValidationStatus(), fieldComboBox, true));
Expand All @@ -88,11 +86,6 @@ void appendToFieldValue() {
viewModel.appendToFieldValue();
}

@FXML
void clearField() {
viewModel.clearSelectedField();
}

@FXML
void setFieldValue() {
viewModel.setFieldValue();
Expand Down
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>
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<Button fx:id="setValueButton" mnemonicParsing="false" onAction="#setFieldValue" text="%Set" />
<Button fx:id="appendValueButton" mnemonicParsing="false" onAction="#appendToFieldValue" text="%Append" />
<Separator maxHeight="1.7976931348623157E308" minWidth="10.0" orientation="VERTICAL" prefWidth="11.0" />
<Button fx:id="clearFieldButton" mnemonicParsing="false" onAction="#clearField" text="%Clear field content" >
<graphic>
<JabRefIconView glyph="DELETE_ENTRY"/>
</graphic>
</Button>
</children>
</HBox>
<HBox spacing="8.0" GridPane.columnSpan="3" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" GridPane.vgrow="NEVER">
Expand Down
3 changes: 3 additions & 0 deletions jablib/src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,7 @@ Show\ preferences=Show preferences
Save\ actions=Save actions
Other\ fields=Other fields
Show\ remaining\ fields=Show remaining fields
Show\ only\ set\ fields=Show only set fields

link\ should\ refer\ to\ a\ correct\ file\ path=link should refer to a correct file path
abbreviation\ detected=abbreviation detected
Expand Down Expand Up @@ -2587,6 +2588,8 @@ Overwrite\ field\ content=Overwrite field content
Set=Set
Append=Append
Clear\ field\ content=Clear field content
Clear\ field\ content\ for\ selected\ entries=Clear field content for selected entries
Clear\ content=Clear content
Set\ or\ append\ content=Set or append content
Edit\ field\ content\ for\ selected\ entries=Edit field content for selected entries
Rename=Rename
Expand Down