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

Allow addition of an entry by its Id (e.g., DOI, ISBN) - fixes #4183 #550 #5755

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class Globals {
public static ExporterFactory exportFactory;
public static CountingUndoManager undoManager = new CountingUndoManager();
public static BibEntryTypesManager entryTypesManager = new BibEntryTypesManager();

// Key binding preferences
private static KeyBindingRepository keyBindingRepository;
private static DefaultFileUpdateMonitor fileUpdateMonitor;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public void output(String s) {

private void setupActions() {
SaveDatabaseAction saveAction = new SaveDatabaseAction(this, Globals.prefs, Globals.entryTypesManager);

CleanupAction cleanUpAction = new CleanupAction(this, Globals.prefs, Globals.TASK_EXECUTOR);

actions.put(Actions.UNDO, undoAction);
Expand All @@ -259,6 +260,7 @@ private void setupActions() {

actions.put(Actions.SAVE_SELECTED_AS_PLAIN, saveAction::saveSelectedAsPlain);


Copy link
Member

Choose a reason for hiding this comment

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

Please not two empty lines between statements.

// The action for copying selected entries.
actions.put(Actions.COPY, this::copy);

Expand Down
64 changes: 64 additions & 0 deletions src/main/java/org/jabref/gui/EntryFromID.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>


<?import javafx.geometry.Insets?>
<DialogPane xmlns:fx="http://javafx.com/fxml/1" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.171" fx:controller="org.jabref.gui.EntryFromIDView">

<buttonTypes>
<ButtonType fx:id="lookupButton" buttonData="OK_DONE" text="%LookUp"/>
<ButtonType fx:id="generateButton" buttonData="OK_DONE" text="%Generate"/>
<ButtonType fx:constant="CANCEL"/>
</buttonTypes>

<content>
<VBox prefHeight="400.0" prefWidth="850.0">
<children>
<GridPane alignment="CENTER">
<children>
<Label text="%FromID" GridPane.rowIndex="1" />
<TextField fx:id="idTextField" onAction="#runFetcherWorker" prefHeight="30.0" prefWidth="400.0"
GridPane.rowIndex="2"/>

<Label text="%LookUp" GridPane.rowIndex="3" />

<Label fx:id="lookUpField"
GridPane.rowIndex="4"/>

</children>

<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="850.0" minWidth="10.0" prefWidth="850.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="200.0" minWidth="10.0" prefWidth="150.0" />
</columnConstraints>
<opaqueInsets>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</opaqueInsets>
<rowConstraints>
<RowConstraints minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>

</GridPane>
</children>
</VBox>
</content>
</DialogPane>

98 changes: 98 additions & 0 deletions src/main/java/org/jabref/gui/EntryFromIDView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.jabref.gui;

import com.airhacks.afterburner.views.ViewLoader;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.FlowPane;
import org.fxmisc.easybind.EasyBind;
import org.jabref.Globals;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.importer.IdBasedFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions;
import org.jabref.model.entry.types.BibtexEntryTypeDefinitions;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.IEEETranEntryTypeDefinitions;
import org.jabref.preferences.JabRefPreferences;

/**
* Dialog that prompts the user to enter an id for an entry.
* Returns null if canceled.
*/
public class EntryFromIDView extends BaseDialog<EntryType> {

@FXML private ButtonType generateButton;
@FXML private ButtonType lookupButton;
@FXML private TextField idTextField;
@FXML private Label lookUpField;

private final BasePanel basePanel;
private final DialogService dialogService;
private final JabRefPreferences prefs;

private EntryType type;
private EntryFromIDViewModel viewModel;

public EntryFromIDView(BasePanel basePanel, DialogService dialogService, JabRefPreferences preferences) {
this.basePanel = basePanel;
this.dialogService = dialogService;
this.prefs = preferences;

this.setTitle(Localization.lang("Select entry type from ID"));
ViewLoader.view(this)
.load()
.setAsDialogPane(this);

setResultConverter(button -> {
//The buttonType will always be cancel, even if we pressed one of the entry type buttons
return type;
});

ControlHelper.setAction(lookupButton, this.getDialogPane(), event -> viewModel.runFetcherWorkerForLookUp(lookUpField));

Button btnLookUp = (Button) this.getDialogPane().lookupButton(lookupButton);
btnLookUp.textProperty().bind(EasyBind.map(viewModel.searchingProperty(), searching -> (searching) ? Localization.lang("Searching...") : Localization.lang("LookUp")));
btnLookUp.disableProperty().bind(viewModel.searchingProperty());

ControlHelper.setAction(generateButton, this.getDialogPane(), event -> viewModel.runFetcherWorker());

Button btnGenerate = (Button) this.getDialogPane().lookupButton(generateButton);
btnGenerate.textProperty().bind(EasyBind.map(viewModel.searchingProperty(), searching -> (searching) ? Localization.lang("Adding...") : Localization.lang("Generate")));
btnGenerate.disableProperty().bind(viewModel.searchingProperty());

}

@FXML
public void initialize() {
viewModel = new EntryFromIDViewModel(prefs, basePanel, dialogService);

idTextField.textProperty().bindBidirectional(viewModel.idTextProperty());

EasyBind.subscribe(viewModel.getFocusAndSelectAllProperty(), evt -> {
if (evt) {
idTextField.requestFocus();
idTextField.selectAll();
}
});

Platform.runLater(() -> idTextField.requestFocus());
}

@FXML
private void runFetcherWorker(Event event) {
viewModel.runFetcherWorker();
}

@FXML
private void focusTextField(Event event) {
idTextField.requestFocus();
idTextField.selectAll();
}

}
Loading