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

Extraction of Globals.prefs.put and .get #7121

Merged
merged 31 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
87c0da9
Extracted Globals.prefs from SidePaneManager
calixtus Nov 21, 2020
c0566c4
Merge remote-tracking branch 'upstream/master' into refactor-globals-…
calixtus Nov 21, 2020
fd83cfe
Fixed failing tests
calixtus Nov 21, 2020
064e773
Extracted Globals.prefs from ClipBoardManager
calixtus Nov 21, 2020
edc04c6
Introduced GuiPreferences
calixtus Nov 21, 2020
1051c2c
Extracted prefs.get and put from ImportCommand and ExportCommand
calixtus Nov 22, 2020
eafc356
Extracted prefs.get and put from ExternalFileTypes
calixtus Nov 22, 2020
0f9301b
Extracted more prefs.get and put
calixtus Nov 22, 2020
ddfb805
Extracted more prefs.get and put from MergeEntries
calixtus Nov 22, 2020
bf36959
Extracted Globals.prefs.get and .put out of push package
calixtus Nov 29, 2020
0d03690
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
Siedlerchr Dec 5, 2020
0d19091
Extrract calls to JabRefPreferences.getInstance()
Siedlerchr Dec 5, 2020
fb7e499
Extracted MrDlibPreferences, Fixed CrawlerTest, Removed some unnecess…
calixtus Dec 5, 2020
9f57e38
Fixed tests
calixtus Dec 7, 2020
9ee60c7
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
calixtus Dec 7, 2020
85d0a6a
Fixed more tests
calixtus Dec 7, 2020
f2a62fd
Fixed NPEs in tests and checkstyle
calixtus Dec 7, 2020
426532b
l10n
calixtus Dec 7, 2020
ac6d4b5
Fixed NPE in CrawlerTest
calixtus Dec 7, 2020
9e85f9c
Cleanups
calixtus Dec 7, 2020
de26c7d
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
calixtus Dec 7, 2020
eeb679b
Extracted TelemetryPreferences
calixtus Dec 7, 2020
43ced4c
Extracted calls to JabRefPreferences out of CustomImportList
calixtus Dec 8, 2020
7b56a94
Made storing of ProtectedTermsPreferences consistent
calixtus Dec 9, 2020
5a11a64
Extracted JabRefPreferences out ouf EntryEditor, reduced unnecessary …
calixtus Dec 9, 2020
2d15f61
Finished extracting unnecessary calls to JabRefPreferences
calixtus Dec 9, 2020
95882e5
Merge remote-tracking branch 'upstream/master' into refactor-prefs-calls
calixtus Dec 9, 2020
14d509d
l10n
calixtus Dec 9, 2020
465b180
Merge branch 'master' into refactor-prefs-calls
tobiasdiez Dec 13, 2020
abe7f4f
Fixed merge error
calixtus Dec 14, 2020
f1b16ce
Fix checkstyle
Siedlerchr Dec 14, 2020
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
Prev Previous commit
Next Next commit
Extracted calls to JabRefPreferences out of CustomImportList
  • Loading branch information
calixtus committed Dec 8, 2020
commit 43ced4c7ee112ad8a5af69210c62f30ed46a5345
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import javax.inject.Inject;

import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
Expand All @@ -15,7 +14,6 @@
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.importer.fileformat.CustomImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.PreferencesService;

Expand All @@ -27,10 +25,10 @@ public class ImportCustomizationDialog extends BaseDialog<Void> {
@FXML private ButtonType addButton;
@FXML private ButtonType removeButton;
@FXML private ButtonType closeButton;
@FXML private TableView<CustomImporter> importerTable;
@FXML private TableColumn<CustomImporter, String> nameColumn;
@FXML private TableColumn<CustomImporter, String> classColumn;
@FXML private TableColumn<CustomImporter, String> basePathColumn;
@FXML private TableView<ImporterViewModel> importerTable;
@FXML private TableColumn<ImporterViewModel, String> nameColumn;
@FXML private TableColumn<ImporterViewModel, String> classColumn;
@FXML private TableColumn<ImporterViewModel, String> basePathColumn;

@Inject private DialogService dialogService;
@Inject private PreferencesService preferences;
Expand Down Expand Up @@ -60,11 +58,11 @@ private void initialize() {
importerTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
importerTable.itemsProperty().bind(viewModel.importersProperty());
EasyBind.bindContent(viewModel.selectedImportersProperty(), importerTable.getSelectionModel().getSelectedItems());
nameColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getName()));
classColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getClassName()));
basePathColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getBasePath().toString()));
new ViewModelTableRowFactory<CustomImporter>()
.withTooltip(CustomImporter::getDescription)
nameColumn.setCellValueFactory(cellData -> cellData.getValue().name());
classColumn.setCellValueFactory(cellData -> cellData.getValue().className());
basePathColumn.setCellValueFactory(cellData -> cellData.getValue().basePath());
new ViewModelTableRowFactory<ImporterViewModel>()
.withTooltip(importer -> importer.getLogic().getDescription())
.install(importerTable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.nio.file.Path;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
Expand All @@ -26,16 +28,23 @@ public class ImportCustomizationDialogViewModel extends AbstractViewModel {

private static final Logger LOGGER = LoggerFactory.getLogger(ImportCustomizationDialogViewModel.class);

private final ListProperty<CustomImporter> importers;
private final ListProperty<CustomImporter> selectedImporters = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ListProperty<ImporterViewModel> importers = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ListProperty<ImporterViewModel> selectedImporters = new SimpleListProperty<>(FXCollections.observableArrayList());

private final PreferencesService preferences;
private final DialogService dialogService;

public ImportCustomizationDialogViewModel(PreferencesService preferences, DialogService dialogService) {
this.preferences = preferences;
this.dialogService = dialogService;
this.importers = new SimpleListProperty<>(FXCollections.observableArrayList(Globals.prefs.customImports));
loadImporters();
}

private void loadImporters() {
Set<CustomImporter> importersLogic = preferences.getCustomImportFormats();
for (CustomImporter importer : importersLogic) {
importers.add(new ImporterViewModel(importer));
}
}

/**
Expand All @@ -61,7 +70,7 @@ public void addImporter() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.CLASS, StandardFileType.JAR, StandardFileType.ZIP)
.withDefaultExtension(StandardFileType.CLASS)
.withInitialDirectory(Globals.prefs.getWorkingDir())
.withInitialDirectory(preferences.getWorkingDir())
.build();

Optional<Path> selectedFile = dialogService.showFileOpenDialog(fileDialogConfiguration);
Expand All @@ -78,7 +87,7 @@ public void addImporter() {
String className = selectedFileInArchive.get().toString().substring(0, selectedFileInArchive.get().toString().lastIndexOf('.')).replace(
"/", ".");
CustomImporter importer = new CustomImporter(selectedFile.get().toAbsolutePath().toString(), className);
importers.add(importer);
importers.add(new ImporterViewModel(importer));
}
} catch (IOException exc) {
LOGGER.error("Could not open ZIP-archive.", exc);
Expand All @@ -98,7 +107,7 @@ public void addImporter() {
String className = pathToClass(basePath, selectedFile.get());
CustomImporter importer = new CustomImporter(basePath, className);

importers.add(importer);
importers.add(new ImporterViewModel(importer));
} catch (Exception exc) {
LOGGER.error("Could not instantiate importer", exc);
dialogService.showErrorDialogAndWait(Localization.lang("Could not instantiate %0", selectedFile.get().toString()), exc);
Expand All @@ -117,19 +126,20 @@ public void removeSelectedImporter() {
}

public void saveToPrefs() {
Globals.prefs.customImports.clear();
Globals.prefs.customImports.addAll(importers);
preferences.storeCustomImportFormats(importers.stream()
.map(ImporterViewModel::getLogic)
.collect(Collectors.toSet()));
Globals.IMPORT_FORMAT_READER.resetImportFormats(
Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXmpPreferences(),
preferences.getImportFormatPreferences(),
preferences.getXmpPreferences(),
Globals.getFileUpdateMonitor());
}

public ListProperty<CustomImporter> selectedImportersProperty() {
public ListProperty<ImporterViewModel> selectedImportersProperty() {
return selectedImporters;
}

public ListProperty<CustomImporter> importersProperty() {
public ListProperty<ImporterViewModel> importersProperty() {
return importers;
}
}
36 changes: 36 additions & 0 deletions src/main/java/org/jabref/gui/importer/ImporterViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jabref.gui.importer;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.logic.importer.fileformat.CustomImporter;

public class ImporterViewModel {
private final CustomImporter importer;
private final StringProperty name = new SimpleStringProperty();
private final StringProperty classname = new SimpleStringProperty();
private final StringProperty basePath = new SimpleStringProperty();

public ImporterViewModel(CustomImporter importer) {
this.importer = importer;
this.name.setValue(importer.getName());
this.classname.setValue(importer.getClassName());
this.basePath.setValue(importer.getBasePath().toString());
}

public CustomImporter getLogic() {
return this.importer;
}

public StringProperty name() {
return this.name;
}

public StringProperty className() {
return this.classname;
}

public StringProperty basePath() {
return this.basePath;
}
}
Loading