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

Add ID Fetcher in Entrytypedialog #1925

Merged
merged 16 commits into from
Sep 12, 2016
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- [#1897](https://github.com/JabRef/jabref/issues/1897) Implemented integrity check for `year` field: Last four nonpunctuation characters should be numerals
- Address in MS-Office 2007 xml format is now imported as `location`
- [#1912](https://github.com/JabRef/jabref/issues/1912) Implemented integrity check for `edition` field: Should have the first letter capitalized (BibTeX), Should contain an integer or a literal (BibLaTeX)
- The dialog for choosing new entries additionally supports ID-based entry generation
- `number` field is now exported as `number` field in MS-Office 2007 xml format, if no `issue` field is present and the entry type is not `patent`
- `note` field is now exported as `comments` field in MS-Office 2007 xml format
- `comments` field in MS-Office 2007 xml format is now imported as `note` field
Expand Down
115 changes: 112 additions & 3 deletions src/main/java/net/sf/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,51 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.ExecutionException;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingWorker;

import net.sf.jabref.BibDatabaseContext;
import net.sf.jabref.Globals;
import net.sf.jabref.gui.importer.fetcher.EntryFetchers;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.logic.CustomEntryTypesManager;
import net.sf.jabref.logic.importer.FetcherException;
import net.sf.jabref.logic.importer.IdBasedFetcher;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.BibtexEntryTypes;
import net.sf.jabref.model.entry.EntryType;
import net.sf.jabref.model.entry.IEEETranEntryTypes;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.VerticalLayout;

/**
* Dialog that prompts the user to choose a type for an entry.
* Returns null if canceled.
*/
public class EntryTypeDialog extends JDialog implements ActionListener {

private static final Log LOGGER = LogFactory.getLog(EntryTypeDialog.class);

private EntryType type;
private SwingWorker<Optional<BibEntry>, Void> fetcherWorker;
private JabRefFrame frame;
private static final int COLUMN = 3;
private final boolean biblatexMode;

Expand All @@ -47,7 +65,7 @@ static class TypeButton extends JButton implements Comparable<TypeButton> {
private final EntryType type;


public TypeButton(String label, EntryType type) {
TypeButton(String label, EntryType type) {
super(label);
this.type = type;
}
Expand All @@ -66,6 +84,8 @@ public EntryTypeDialog(JabRefFrame frame) {
// modal dialog
super(frame, true);

this.frame = frame;

bibDatabaseContext = frame.getCurrentBasePanel().getBibDatabaseContext();
biblatexMode = bibDatabaseContext.isBiblatexMode();

Expand All @@ -91,12 +111,17 @@ private JPanel createEntryGroupsPanel() {
JPanel panel = new JPanel();
panel.setLayout(new VerticalLayout());

if(biblatexMode) {
if (biblatexMode) {
panel.add(createEntryGroupPanel("BibLateX", EntryTypes.getAllValues(bibDatabaseContext.getMode())));
} else {
panel.add(createEntryGroupPanel("BibTeX", BibtexEntryTypes.ALL));
panel.add(createEntryGroupPanel("IEEETran", IEEETranEntryTypes.ALL));
panel.add(createEntryGroupPanel(Localization.lang("Custom"), CustomEntryTypesManager.ALL));

if (!CustomEntryTypesManager.ALL.isEmpty()) {
Copy link
Member

@tobiasdiez tobiasdiez Sep 7, 2016

Choose a reason for hiding this comment

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

The custom entry types are not displayed in BibLatexMode. Is this by design? @JabRef/developers

Copy link
Member

Choose a reason for hiding this comment

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

No, they are already displayed (even in biblatex mode) but they are mixed with the others:

jabrefmycustomentrytype

panel.add(createEntryGroupPanel(Localization.lang("Custom"), CustomEntryTypesManager.ALL));
}

panel.add(createIdFetcherPanel());
}

return panel;
Expand Down Expand Up @@ -148,6 +173,89 @@ private JPanel createEntryGroupPanel(String groupTitle, Collection<EntryType> en
return panel;
}

private JPanel createIdFetcherPanel() {
JButton generateButton = new JButton(Localization.lang("Generate"));
JTextField idTextField = new JTextField("");
JComboBox<String> comboBox = new JComboBox<>();
EntryFetchers.getIdFetchers().forEach(fetcher -> comboBox.addItem(fetcher.getName()));
JLabel fetcherLabel = new JLabel(Localization.lang("ID type"));
JLabel idLabel = new JLabel(Localization.lang("ID"));

fetcherWorker = new SwingWorker<Optional<BibEntry>, Void>() {
Optional<BibEntry> bibEntry = Optional.empty();
IdBasedFetcher fetcher = null;
String searchID = "";

@Override
protected Optional<BibEntry> doInBackground() throws Exception {
generateButton.setEnabled(false);
generateButton.setText(Localization.lang("Searching..."));
searchID = idTextField.getText().trim();
fetcher = EntryFetchers.getIdFetchers().get(comboBox.getSelectedIndex());
if (!searchID.isEmpty()) {
try {
bibEntry = fetcher.performSearchById(searchID);
} catch (FetcherException e) {
LOGGER.error("Error fetching from " + fetcher.getName(), e);
JOptionPane.showMessageDialog(null, Localization.lang("Error while fetching from %0", fetcher.getName()), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
}
}
dispose();
return bibEntry;
}

@Override
protected void done() {
try {
Optional<BibEntry> result = get();
if (result.isPresent()) {
frame.getCurrentBasePanel().insertEntry(result.get());
} else {
JOptionPane.showMessageDialog(null, Localization.lang("Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.", fetcher.getName(), searchID), Localization.lang("No files found."), JOptionPane.WARNING_MESSAGE);
}
} catch (ExecutionException | InterruptedException e) {
LOGGER.error(String.format("Exception during fetching when using fetcher '%s' with entry id '%s'.", searchID, fetcher.getName()), e);
}
}
};

generateButton.addActionListener(action -> fetcherWorker.execute());

JPanel jPanel = new JPanel();

GridBagConstraints constraints = new GridBagConstraints();

GridBagLayout layout = new GridBagLayout();
jPanel.setLayout(layout);
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1;
jPanel.add(fetcherLabel, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
constraints.weightx = 2;
jPanel.add(comboBox, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.weightx = 1;
jPanel.add(idLabel, constraints);
constraints.gridx = 1;
constraints.gridy = 1;
constraints.weightx = 2;
jPanel.add(idTextField, constraints);

constraints.gridy = 2;
JPanel buttons = new JPanel();
ButtonBarBuilder bb = new ButtonBarBuilder(buttons);
bb.addButton(generateButton);

jPanel.add(buttons, constraints);
jPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localization.lang("ID-based_entry_generator")));

return jPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof TypeButton) {
Expand All @@ -168,6 +276,7 @@ public CancelAction() {

@Override
public void actionPerformed(ActionEvent e) {
fetcherWorker.cancel(true);
dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package net.sf.jabref.gui.importer.fetcher;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.IdBasedFetcher;
import net.sf.jabref.logic.importer.fetcher.ArXiv;
import net.sf.jabref.logic.importer.fetcher.DiVA;
import net.sf.jabref.logic.importer.fetcher.GvkFetcher;
Expand All @@ -30,13 +32,19 @@ public EntryFetchers(JournalAbbreviationLoader abbreviationLoader) {
entryFetchers.add(new DOAJFetcher());
entryFetchers.add(new SpringerFetcher());

entryFetchers.add(new IdBasedEntryFetcher(new DiVA(Globals.prefs.getImportFormatPreferences())));
entryFetchers.add(new IdBasedEntryFetcher(new IsbnFetcher(Globals.prefs.getImportFormatPreferences())));
entryFetchers.add(new SearchBasedEntryFetcher(new ArXiv()));
entryFetchers.add(new SearchBasedEntryFetcher(new GvkFetcher()));
}

public List<EntryFetcher> getEntryFetchers() {
return Collections.unmodifiableList(this.entryFetchers);
}

public static ArrayList<IdBasedFetcher> getIdFetchers() {
ArrayList<IdBasedFetcher> list = new ArrayList<>();
list.add(new IsbnFetcher(Globals.prefs.getImportFormatPreferences()));
list.add(new DiVA(Globals.prefs.getImportFormatPreferences()));
list.sort((fetcher1, fetcher2) -> fetcher1.getName().compareTo(fetcher2.getName()));
return list;
}
}
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=

BibTeX_key=
Message=

Decryption_not_supported.=

Cleared_'%0'_for_%1_entries=
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=
ID_type=
ID-based_entry_generator=
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=Version_in_die_Zwischenablage_kopiert

BibTeX_key=BibTeX-Key
Message=Nachricht

Decryption_not_supported.=Entschlüsselung_wird_nicht_unterstützt.

Cleared_'%0'_for_%1_entries='%0'_für_%1_Einträge_entfernt
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=Die letzten vier Nichtint
shared=geteilt
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=ID
ID_type=ID_typ
ID-based_entry_generator=ID_basierter_Eintragsgenerator
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=Der_Fetcher_%0_hat_keinen_Eintrag_für_die_ID_%1_gefunden.
8 changes: 6 additions & 2 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=Copied_version_to_clipboard

BibTeX_key=BibTeX_key
Message=Message

Decryption_not_supported.=Decryption_not_supported.

Cleared_'%0'_for_%1_entries=Cleared_'%0'_for_%1_entries
Expand Down Expand Up @@ -2296,4 +2295,9 @@ You_are_about_to_look_up_full_text_documents_for_%0_entries.=You_are_about_to_lo
last_four_nonpunctuation_characters_should_be_numerals=last_four_nonpunctuation_characters_should_be_numerals
shared=shared
should_contain_an_integer_or_a_literal=should_contain_an_integer_or_a_literal
should_have_the_first_letter_capitalized=should_have_the_first_letter_capitalized
should_have_the_first_letter_capitalized=should_have_the_first_letter_capitalized

ID=ID
ID_type=ID_type
ID-based_entry_generator=ID-based_entry_generator
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=

BibTeX_key=
Message=

Decryption_not_supported.=

Cleared_'%0'_for_%1_entries=Ajustes_de_'%0'_para_%1_entradas
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=
ID_type=
ID-based_entry_generator=
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=

BibTeX_key=
Message=

Decryption_not_supported.=

Cleared_'%0'_for_%1_entries=
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=
ID_type=
ID-based_entry_generator=
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=Version_copiée_dans_le_presse-papiers

BibTeX_key=Clef_BibTeX
Message=Message

Decryption_not_supported.=Déchiffrement_non_supporté.

Cleared_'%0'_for_%1_entries=Réinitialisés_'%0'_pour_%1_entrées
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=Les_4_derniers_caractère
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=
ID_type=
ID-based_entry_generator=
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=

BibTeX_key=
Message=

Decryption_not_supported.=

Cleared_'%0'_for_%1_entries=
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=
ID_type=
ID-based_entry_generator=
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=

BibTeX_key=
Message=

Decryption_not_supported.=

Cleared_'%0'_for_%1_entries=Reinizializzati_'%0'_per_%1_voce/i
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=
ID_type=
ID-based_entry_generator=
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=
6 changes: 5 additions & 1 deletion src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,6 @@ Copied_version_to_clipboard=クリップボードにコピーされたバージ

BibTeX_key=BibTeX鍵
Message=メッセージ

Decryption_not_supported.=

Cleared_'%0'_for_%1_entries=
Expand Down Expand Up @@ -2297,3 +2296,8 @@ last_four_nonpunctuation_characters_should_be_numerals=
shared=
should_contain_an_integer_or_a_literal=
should_have_the_first_letter_capitalized=

ID=
ID_type=
ID-based_entry_generator=
Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.=
Loading