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

Convert the "Custom API key" list to a table [#10926] #10936

Merged
merged 11 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We converted the "Custom API key" list to a table to be more accessible. [#10926](https://github.com/JabRef/jabref/issues/10926)
- We added a "refresh" button for the LaTeX citations tab in the entry editor. [#10584](https://github.com/JabRef/jabref/issues/10584)
- We added the possibility to show the BibTeX source in the [web search](https://docs.jabref.org/collect/import-using-online-bibliographic-database) import screen. [#560](https://github.com/koppor/jabref/issues/560)
- We added a fetcher for [ISIDORE](https://isidore.science/), simply paste in the link into the text field or the last 6 digits in the link that identify that paper. [#10423](https://github.com/JabRef/jabref/issues/10423)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TableColumn?>
Expand Down Expand Up @@ -55,12 +54,28 @@
</HBox>

<Label styleClass="sectionHeader" text="%Custom API key"/>
<HBox alignment="CENTER_LEFT" spacing="10.0">
<ComboBox fx:id="apiKeySelector" prefWidth="200.0" GridPane.columnIndex="1"/>
<TextField fx:id="customApiKey" HBox.hgrow="ALWAYS"/>
<CheckBox fx:id="useCustomApiKey" text="%Custom">
</CheckBox>
</HBox>
<TableView
fx:id="apiKeySelectorTable"
VBox.vgrow="ALWAYS"
editable="true">
<columns>
<TableColumn minWidth="120"
fx:id="apiKeyName"
text="%Catalog"
/>
<TableColumn minWidth="120"
fx:id="customApiKey"
text="Key"/>

<TableColumn minWidth="120" prefWidth="120"
fx:id="useCustomApiKey"
text="Use Custom Key"/>
</columns>
<columnResizePolicy>
<TableView
fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>

<HBox alignment="CENTER_LEFT" spacing="10.0">
<Button fx:id="testCustomApiKey" text="%Check connection" onAction="#checkCustomApiKey"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
Expand All @@ -17,7 +16,6 @@
import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
import org.jabref.gui.slr.StudyCatalogItem;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preferences.FetcherApiKey;
Expand All @@ -38,9 +36,10 @@ public class WebSearchTab extends AbstractPreferenceTabView<WebSearchTabViewMode
@FXML private CheckBox grobidEnabled;
@FXML private TextField grobidURL;

@FXML private ComboBox<FetcherApiKey> apiKeySelector;
@FXML private TextField customApiKey;
@FXML private CheckBox useCustomApiKey;
@FXML private TableView<FetcherApiKey> apiKeySelectorTable;
@FXML private TableColumn<FetcherApiKey, String> apiKeyName;
@FXML private TableColumn<FetcherApiKey, String> customApiKey;
@FXML private TableColumn<FetcherApiKey, Boolean> useCustomApiKey;
@FXML private Button testCustomApiKey;

@FXML private CheckBox persistApiKeys;
Expand Down Expand Up @@ -96,22 +95,37 @@ public void initialize() {
catalogColumn.setCellValueFactory(param -> param.getValue().nameProperty());
catalogTable.setItems(viewModel.getCatalogs());

new ViewModelListCellFactory<FetcherApiKey>()
.withText(FetcherApiKey::getName)
.install(apiKeySelector);
apiKeySelector.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
testCustomApiKey.setDisable(true);

new ViewModelTableRowFactory<FetcherApiKey>()
.install(apiKeySelectorTable);

apiKeySelectorTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (oldValue != null) {
updateFetcherApiKey(oldValue);
}
if (newValue != null) {
useCustomApiKey.setSelected(newValue.shouldUse());
customApiKey.setText(newValue.getKey());
viewModel.selectedApiKeyProperty().setValue(newValue);
testCustomApiKey.disableProperty().bind(newValue.useProperty().not());
}
});
customApiKey.textProperty().addListener(listener -> updateFetcherApiKey(apiKeySelector.valueProperty().get()));

customApiKey.disableProperty().bind(useCustomApiKey.selectedProperty().not());
testCustomApiKey.disableProperty().bind(useCustomApiKey.selectedProperty().not());
apiKeyName.setCellValueFactory(param -> param.getValue().nameProperty());
apiKeyName.setCellFactory(TextFieldTableCell.forTableColumn());
apiKeyName.setReorderable(false);
apiKeyName.setEditable(false);

customApiKey.setCellValueFactory(param -> param.getValue().keyProperty());
customApiKey.setCellFactory(TextFieldTableCell.forTableColumn());
customApiKey.setReorderable(false);
customApiKey.setResizable(true);
customApiKey.setEditable(true);

useCustomApiKey.setCellValueFactory(param -> param.getValue().useProperty());
useCustomApiKey.setCellFactory(CheckBoxTableCell.forTableColumn(useCustomApiKey));
useCustomApiKey.setEditable(true);
useCustomApiKey.setResizable(true);
useCustomApiKey.setReorderable(false);

persistApiKeys.selectedProperty().bindBidirectional(viewModel.getApikeyPersistProperty());
persistApiKeys.disableProperty().bind(viewModel.apiKeyPersistAvailable().not());
Expand All @@ -123,17 +137,15 @@ public void initialize() {
}
});

apiKeySelector.setItems(viewModel.fetcherApiKeys());
viewModel.selectedApiKeyProperty().bind(apiKeySelector.valueProperty());
apiKeySelectorTable.setItems(viewModel.fetcherApiKeys());

// Content is set later
viewModel.fetcherApiKeys().addListener((InvalidationListener) change -> apiKeySelector.getSelectionModel().selectFirst());
viewModel.fetcherApiKeys().addListener((InvalidationListener) change -> apiKeySelectorTable.getSelectionModel().selectFirst());
}

private void updateFetcherApiKey(FetcherApiKey apiKey) {
if (apiKey != null) {
apiKey.setUse(useCustomApiKey.isSelected());
apiKey.setKey(customApiKey.getText().trim());
apiKey.setKey(customApiKey.getCellData(apiKey).trim());
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/logic/preferences/FetcherApiKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public String getName() {
return name.getValue();
}

public StringProperty nameProperty() {
return name;
}

public boolean shouldUse() {
return use.getValue();
}
Expand Down
Loading