Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.swing.undo.UndoManager;

Expand Down Expand Up @@ -75,10 +76,10 @@ private void notifyOnChange(List<DatabaseChange> changes) {
notificationPane.notify(
IconTheme.JabRefIcons.SAVE.getGraphicNode(),
Localization.lang("The library has been modified by another program."),
List.of(new Action(Localization.lang("Dismiss changes"), event -> notificationPane.hide()),
new Action(Localization.lang("Review changes"), event -> {
List.of(new Action(Localization.lang("Dismiss changes"), _ -> notificationPane.hide()),
new Action(Localization.lang("Review changes"), _ -> {
DatabaseChangesResolverDialog databaseChangesResolverDialog = new DatabaseChangesResolverDialog(changes, database, Localization.lang("External Changes Resolver"));
var areAllChangesResolved = dialogService.showCustomDialogAndWait(databaseChangesResolverDialog);
Optional<Boolean> areAllChangesResolved = dialogService.showCustomDialogAndWait(databaseChangesResolverDialog);
saveState = stateManager.activeTabProperty().get().get();
final NamedCompound ce = new NamedCompound(Localization.lang("Merged external changes"));
changes.stream().filter(DatabaseChange::isAccepted).forEach(change -> change.applyChange(ce));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static Optional<ParserResult> showRestoreBackupDialog(DialogService dialo
FileUpdateMonitor fileUpdateMonitor,
UndoManager undoManager,
StateManager stateManager) {
var actionOpt = showBackupResolverDialog(
Optional<ButtonType> actionOpt = showBackupResolverDialog(
dialogService,
preferences.getExternalApplicationsPreferences(),
originalPath,
Expand Down Expand Up @@ -100,7 +100,7 @@ private static Optional<ParserResult> showReviewBackupDialog(
changes,
originalDatabase, "Review Backup"
);
var allChangesResolved = dialogService.showCustomDialogAndWait(reviewBackupDialog);
Optional<Boolean> allChangesResolved = dialogService.showCustomDialogAndWait(reviewBackupDialog);
LibraryTab saveState = stateManager.activeTabProperty().get().get();
final NamedCompound CE = new NamedCompound(Localization.lang("Merged external changes"));
changes.stream().filter(DatabaseChange::isAccepted).forEach(change -> change.applyChange(CE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public List<ImportFilesResultItemViewModel> call() {
});
}
} else if (FileUtil.isBibFile(file)) {
var bibtexParserResult = contentImporter.importFromBibFile(file, fileUpdateMonitor);
ParserResult bibtexParserResult = contentImporter.importFromBibFile(file, fileUpdateMonitor);
List<BibEntry> entries = bibtexParserResult.getDatabaseContext().getEntries();
entriesToAdd.addAll(entries);
boolean success = !bibtexParserResult.hasWarnings();
Expand Down Expand Up @@ -207,7 +207,7 @@ public List<ImportFilesResultItemViewModel> call() {
}

private void addResultToList(Path newFile, boolean success, String logMessage) {
var result = new ImportFilesResultItemViewModel(newFile, success, logMessage);
ImportFilesResultItemViewModel result = new ImportFilesResultItemViewModel(newFile, success, logMessage);
results.add(result);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class GroupNodeViewModel {
@SuppressWarnings("FieldCanBeLocal")
private final ObservableList<BibEntry> entriesList;
@SuppressWarnings("FieldCanBeLocal")
private final InvalidationListener onInvalidatedGroup = listener -> refreshGroup();
private final InvalidationListener onInvalidatedGroup = _ -> refreshGroup();

public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager stateManager, TaskExecutor taskExecutor, GroupTreeNode groupNode, CustomLocalDragboard localDragBoard, GuiPreferences preferences) {
this.databaseContext = Objects.requireNonNull(databaseContext);
Expand Down Expand Up @@ -111,9 +111,9 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state

hasChildren = new SimpleBooleanProperty();
hasChildren.bind(Bindings.isNotEmpty(children));
EasyBind.subscribe(preferences.getGroupsPreferences().displayGroupCountProperty(), shouldDisplay -> updateMatchedEntries());
EasyBind.subscribe(preferences.getGroupsPreferences().displayGroupCountProperty(), _ -> updateMatchedEntries());
expandedProperty.set(groupNode.getGroup().isExpanded());
expandedProperty.addListener((observable, oldValue, newValue) -> groupNode.getGroup().setExpanded(newValue));
expandedProperty.addListener((_, _, newValue) -> groupNode.getGroup().setExpanded(newValue));

// Register listener
// The wrapper created by the FXCollections will set a weak listener on the wrapped list. This weak listener gets garbage collected. Hence, we need to maintain a reference to this list.
Expand Down Expand Up @@ -147,7 +147,7 @@ public List<FieldChange> addEntriesToGroup(List<BibEntry> entries) {
// return; // user aborted operation
// }

var changes = groupNode.addEntriesToGroup(entries);
List<FieldChange> changes = groupNode.addEntriesToGroup(entries);

// Update appearance of group
anySelectedEntriesMatched.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void initialize() {
.install(labelColumn, new DefaultStringConverter());
labelColumn.setOnEditCommit((TableColumn.CellEditEvent<ConstantsItemModel, String> cellEvent) -> {

var tableView = cellEvent.getTableView();
TableView<ConstantsItemModel> tableView = cellEvent.getTableView();
ConstantsItemModel cellItem = tableView.getItems()
.get(cellEvent.getTablePosition().getRow());

Expand All @@ -77,7 +77,7 @@ public void initialize() {

// Resort the entries based on the keys and set the focus to the newly-created entry
viewModel.resortStrings();
var selectionModel = tableView.getSelectionModel();
TableView.TableViewSelectionModel<ConstantsItemModel> selectionModel = tableView.getSelectionModel();
selectionModel.select(cellItem);
selectionModel.focus(selectionModel.getSelectedIndex());
tableView.refresh();
Expand All @@ -97,9 +97,9 @@ public void initialize() {
actionsColumn.setReorderable(false);
actionsColumn.setCellValueFactory(cellData -> cellData.getValue().labelProperty());
new ValueTableCellFactory<ConstantsItemModel, String>()
.withGraphic(label -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
.withGraphic(_ -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
.withTooltip(label -> Localization.lang("Remove string %0", label))
.withOnMouseClickedEvent(item -> evt ->
.withOnMouseClickedEvent(_ -> _ ->
viewModel.removeString(stringsList.getFocusModel().getFocusedItem()))
.install(actionsColumn);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public BibEntry getEntry() {

private static Binding<List<AbstractGroup>> createMatchedGroupsBinding(BibDatabaseContext database, BibEntry entry) {
return new UiThreadBinding<>(EasyBind.combine(entry.getFieldBinding(StandardField.GROUPS), database.getMetaData().groupsBinding(),
(a, b) ->
(_, _) ->
database.getMetaData().getGroups().map(groupTreeNode ->
groupTreeNode.getMatchingGroups(entry).stream()
.map(GroupTreeNode::getGroup)
Expand Down Expand Up @@ -119,7 +119,7 @@ public ObservableValue<Optional<SpecialFieldValueViewModel>> getSpecialField(Spe
Optional<String> currentValue = this.entry.getField(field);
if (value != null) {
if (currentValue.isEmpty() && value.getValue().isEmpty()) {
var zeroValue = getField(field).flatMapOpt(fieldValue -> field.parseValue("CLEAR_RANK").map(SpecialFieldValueViewModel::new));
OptionalBinding<SpecialFieldValueViewModel> zeroValue = getField(field).flatMapOpt(_ -> field.parseValue("CLEAR_RANK").map(SpecialFieldValueViewModel::new));
specialFieldValues.put(field, zeroValue);
return zeroValue;
} else if (value.getValue().isEmpty() || !value.getValue().get().getValue().getFieldValue().equals(currentValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEn
super(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, preferences, rowIndex);
assert field.getProperties().contains(FieldProperty.PERSON_NAMES);

var authorsParser = new AuthorListParser();
AuthorListParser authorsParser = new AuthorListParser();
leftEntryNames = authorsParser.parse(viewModel.getLeftFieldValue());
rightEntryNames = authorsParser.parse(viewModel.getRightFieldValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ protected List<Path> call() {
}
};

taskConnectIfInstalled.setOnSucceeded(evt -> {
taskConnectIfInstalled.setOnSucceeded(_ -> {
List<Path> installations = new ArrayList<>(taskConnectIfInstalled.getValue());
if (installations.isEmpty()) {
officeInstallation.selectInstallationPath().ifPresent(installations::add);
Expand All @@ -398,7 +398,7 @@ protected List<Path> call() {
}

private void connectManually() {
var fileDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(System.getProperty("user.home")).build();
DirectoryDialogConfiguration fileDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(System.getProperty("user.home")).build();
Optional<Path> selectedPath = dialogService.showDirectorySelectionDialog(fileDialogConfiguration);

DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(openOfficePreferences, dialogService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void setupEntryTypesTable() {
entryTypeActionsColumn.setReorderable(false);
entryTypeActionsColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().entryType().get().getType().getDisplayName()));
new ValueTableCellFactory<EntryTypeViewModel, String>()
.withGraphic((type, name) -> {
.withGraphic((type, _) -> {
if (type instanceof CustomEntryTypeViewModel) {
return IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode();
} else {
Expand All @@ -120,11 +120,11 @@ private void setupEntryTypesTable() {
return null;
}
})
.withOnMouseClickedEvent((type, name) -> {
.withOnMouseClickedEvent((type, _) -> {
if (type instanceof CustomEntryTypeViewModel) {
return evt -> viewModel.removeEntryType(entryTypesTable.getSelectionModel().getSelectedItem());
return _ -> viewModel.removeEntryType(entryTypesTable.getSelectionModel().getSelectedItem());
} else {
return evt -> {
return _ -> {
};
}
})
Expand All @@ -135,7 +135,7 @@ private void setupEntryTypesTable() {

EasyBind.subscribe(viewModel.selectedEntryTypeProperty(), type -> {
if (type != null) {
var items = type.fields();
ObservableList<FieldViewModel> items = type.fields();
Copy link

Choose a reason for hiding this comment

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

The patch replaces 'var' with 'ObservableList', which is correct for type safety, but it should also consider using modern Java data structures as per best practices.

fields.setItems(items);
} else {
fields.setItems(null);
Expand Down Expand Up @@ -185,9 +185,9 @@ private void setupFieldsTable() {
fieldTypeActionColumn.setCellValueFactory(cellData -> cellData.getValue().displayNameProperty());

new ValueTableCellFactory<FieldViewModel, String>()
.withGraphic(item -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
.withGraphic(_ -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
.withTooltip(name -> Localization.lang("Remove field %0 from currently selected entry type", name))
.withOnMouseClickedEvent(item -> evt -> viewModel.removeField(fields.getSelectionModel().getSelectedItem()))
.withOnMouseClickedEvent(_ -> _ -> viewModel.removeField(fields.getSelectionModel().getSelectedItem()))
.install(fieldTypeActionColumn);

new ViewModelTableRowFactory<FieldViewModel>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void storeSettings() {
entryTypesManager.update(newType, bibDatabaseMode);
}

for (var entryType : entryTypesToDelete) {
for (BibEntryType entryType : entryTypesToDelete) {
entryTypesManager.removeCustomOrModifiedEntryType(entryType, bibDatabaseMode);
}

Expand Down
14 changes: 7 additions & 7 deletions jabgui/src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import javafx.application.Platform;
Expand Down Expand Up @@ -57,12 +57,12 @@ public class PreviewViewer extends ScrollPane implements InvalidationListener {
// https://stackoverflow.com/questions/5669448/get-selected-texts-html-in-div/5670825#5670825
private static final String JS_GET_SELECTION_HTML_SCRIPT = """
function getSelectionHtml() {
var html = "";
let html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
let sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
let container = document.createElement("div");
for (let i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
Expand Down Expand Up @@ -266,13 +266,13 @@ public void print() {

public void copyPreviewHtmlToClipBoard() {
Document document = previewView.getEngine().getDocument();
ClipboardContent content = ClipboardContentGenerator.processHtml(Arrays.asList(document.getElementById("content").getTextContent()));
ClipboardContent content = ClipboardContentGenerator.processHtml(List.of(document.getElementById("content").getTextContent()));
clipBoardManager.setContent(content);
}

public void copyPreviewTextToClipBoard() {
Document document = previewView.getEngine().getDocument();
ClipboardContent content = ClipboardContentGenerator.processText(Arrays.asList(document.getElementById("content").getTextContent()));
ClipboardContent content = ClipboardContentGenerator.processText(List.of(document.getElementById("content").getTextContent()));
clipBoardManager.setContent(content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static Optional<Exporter> getExporter(FileChooser.ExtensionFilter extensi
}

public static FileChooser.ExtensionFilter forAllImporters(SortedSet<Importer> importers) {
List<FileType> fileTypes = importers.stream().map(Importer::getFileType).collect(Collectors.toList());
List<FileType> fileTypes = importers.stream().map(Importer::getFileType).toList();
List<String> flatExtensions = fileTypes.stream()
.flatMap(type -> type.getExtensionsWithAsteriskAndDot().stream())
.collect(Collectors.toList());
Expand All @@ -86,7 +86,7 @@ public static FileFilter toFileFilter(FileChooser.ExtensionFilter extensionFilte
}

public static FileFilter toFileFilter(List<String> extensions) {
var filter = toDirFilter(extensions);
Filter<Path> filter = toDirFilter(extensions);
Copy link

Choose a reason for hiding this comment

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

The explicit type declaration 'Filter' is preferred over 'var' for clarity and type safety, aligning with modern Java best practices.

return file -> {
try {
return filter.accept(file.toPath());
Expand All @@ -100,10 +100,10 @@ public static Filter<Path> toDirFilter(List<String> extensions) {
List<String> extensionsCleaned = extensions.stream()
.map(extension -> extension.replace(".", "").replace("*", ""))
.filter(StringUtil::isNotBlank)
.collect(Collectors.toList());
.toList();
if (extensionsCleaned.isEmpty()) {
// Except every file
return path -> true;
return _ -> true;
} else {
return path -> FileUtil.getFileExtension(path)
.map(extensionsCleaned::contains)
Expand Down
Loading