Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Nov 9, 2023
1 parent c95d0e8 commit 8af920d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import javafx.scene.control.TableView;
import javafx.scene.control.cell.CheckBoxTableCell;

import org.jabref.gui.Globals;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
import org.jabref.gui.util.BindingsHelper;
Expand All @@ -36,6 +36,7 @@ public class ProtectedTermsTab extends AbstractPreferenceTabView<ProtectedTermsT
@FXML private TableColumn<ProtectedTermsListItemModel, Boolean> filesTableDeleteColumn;

@Inject private ProtectedTermsLoader termsLoader;
@Inject private KeyBindingRepository keyBindingRepository;

public ProtectedTermsTab() {
ViewLoader.view(this)
Expand Down Expand Up @@ -87,7 +88,7 @@ public void initialize() {
}

private ContextMenu createContextMenu(ProtectedTermsListItemModel file) {
ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
ActionFactory factory = new ActionFactory(keyBindingRepository);
ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.EDIT_LIST, new ProtectedTermsTab.ContextAction(StandardActions.EDIT_LIST, file)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<Label styleClass="sectionHeader" text="%Catalogues used for 'Search Selected'"/>
<TableView
fx:id="catalogTable"
HBox.hgrow="ALWAYS"
VBox.vgrow="ALWAYS"
editable="true">
<columns>
<TableColumn
<TableColumn minWidth="90" prefWidth="70"
fx:id="catalogEnabledColumn"
text="%Enabled"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

import kong.unirest.UnirestException;

public class WebSearchTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty enableWebSearchProperty = new SimpleBooleanProperty();
private final BooleanProperty generateKeyOnImportProperty = new SimpleBooleanProperty();
Expand Down Expand Up @@ -114,7 +116,11 @@ public void storeSettings() {
grobidPreferences.setGrobidURL(grobidURLProperty.getValue());
doiPreferences.setUseCustom(useCustomDOIProperty.get());
doiPreferences.setDefaultBaseURI(useCustomDOINameProperty.getValue().trim());
importerPreferences.setCatalogs(FXCollections.observableList(catalogs.stream().filter(StudyCatalogItem::isEnabled).map(StudyCatalogItem::getName).collect(Collectors.toList())));
importerPreferences.setCatalogs(
FXCollections.observableList(catalogs.stream()
.filter(StudyCatalogItem::isEnabled)
.map(StudyCatalogItem::getName)
.collect(Collectors.toList())));
importerPreferences.setPersistCustomKeys(apikeyPersistProperty.get());
preferencesService.getImporterPreferences().getApiKeys().clear();
if (apikeyPersistAvailableProperty.get()) {
Expand Down Expand Up @@ -215,7 +221,7 @@ public void checkCustomApiKey() {
keyValid = (statusCode >= 200) && (statusCode < 300);

URLDownload.setSSLVerification(defaultSslSocketFactory, defaultHostnameVerifier);
} catch (IOException | kong.unirest.UnirestException e) {
} catch (IOException | UnirestException e) {
keyValid = false;
}
} else {
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/org/jabref/logic/importer/ImporterPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import java.util.Set;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand All @@ -27,7 +25,7 @@ public class ImporterPreferences {
private final ObservableSet<FetcherApiKey> apiKeys;
private final ObservableSet<CustomImporter> customImporters;
private final BooleanProperty persistCustomKeys;
private final ListProperty<String> catalogs;
private final ObservableList<String> catalogs;
public ImporterPreferences(boolean importerEnabled,
boolean generateNewKeyOnImport,
Path importWorkingDirectory,
Expand All @@ -43,7 +41,7 @@ public ImporterPreferences(boolean importerEnabled,
this.customImporters = FXCollections.observableSet(customImporters);
this.apiKeys = FXCollections.observableSet(apiKeys);
this.persistCustomKeys = new SimpleBooleanProperty(persistCustomKeys);
this.catalogs = new SimpleListProperty<>(FXCollections.observableArrayList(catalogs));
this.catalogs = FXCollections.observableArrayList(catalogs);
}

public boolean areImporterEnabled() {
Expand Down Expand Up @@ -127,18 +125,12 @@ public Optional<String> getApiKey(String name) {
.map(FetcherApiKey::getKey);
}

public void setCatalogs(ObservableList<String> catalogs) {
this.catalogs.set(catalogs);
public void setCatalogs(List<String> catalogs) {
this.catalogs.clear();
this.catalogs.addAll(catalogs);
}

public ObservableList<String> getCatalogs() {
if (catalogs.get() == null) {
catalogs.set(FXCollections.observableArrayList());
}
return catalogs.get();
}

public ListProperty<String> catalogsProperty() {
return catalogs;
return catalogs;
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ public static Set<CustomizableKeyFetcher> getCustomizableKeyFetchers(ImportForma
}
}

// Place "Search Selected" to the first of the set
/**
* Places "Search Selected" to the first of the set
*/
class CompositeSearchFirstComparator implements Comparator<SearchBasedFetcher> {
@Override
public int compare(SearchBasedFetcher s1, SearchBasedFetcher s2) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.stream.Stream;

import javafx.beans.InvalidationListener;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.SetChangeListener;
Expand Down Expand Up @@ -2822,7 +2821,7 @@ public ImporterPreferences getImporterPreferences() {
getCustomImportFormats(),
getFetcherKeys(),
getBoolean(FETCHER_CUSTOM_KEY_PERSIST),
FXCollections.observableList(getStringList(SEARCH_CATALOGS)));
getStringList(SEARCH_CATALOGS));

EasyBind.listen(importerPreferences.importerEnabledProperty(), (obs, oldValue, newValue) -> putBoolean(IMPORTERS_ENABLED, newValue));
EasyBind.listen(importerPreferences.generateNewKeyOnImportProperty(), (obs, oldValue, newValue) -> putBoolean(GENERATE_KEY_ON_IMPORT, newValue));
Expand All @@ -2831,7 +2830,7 @@ public ImporterPreferences getImporterPreferences() {
EasyBind.listen(importerPreferences.persistCustomKeysProperty(), (obs, oldValue, newValue) -> putBoolean(FETCHER_CUSTOM_KEY_PERSIST, newValue));
importerPreferences.getApiKeys().addListener((InvalidationListener) c -> storeFetcherKeys(importerPreferences.getApiKeys()));
importerPreferences.getCustomImporters().addListener((InvalidationListener) c -> storeCustomImportFormats(importerPreferences.getCustomImporters()));
EasyBind.listen(importerPreferences.catalogsProperty(), (obs, oldValue, newValue) -> putStringList(SEARCH_CATALOGS, importerPreferences.catalogsProperty()));
importerPreferences.getCatalogs().addListener((InvalidationListener) c -> putStringList(SEARCH_CATALOGS, importerPreferences.getCatalogs()));

return importerPreferences;
}
Expand Down

0 comments on commit 8af920d

Please sign in to comment.