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 5 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 @@ -18,6 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- [#1813](https://github.com/JabRef/jabref/issues/1813) Import/Export preferences dialog default directory set to working directory
- [#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`
- Add ID Fetcher in EntryTypeDialog
Copy link
Member

Choose a reason for hiding this comment

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

We decided for "ID-based_entry_generator". Thus, this term should be used here. Further, I don't believe it's called "EntryTypeDialog` on the user's side (see http://help.jabref.org/en/BaseFrameHelp). Maybe phrase it "Support entry generation based on IDs in the dialog for choosing the type for a new entry" or "The dialog for choosing new entries additionally supports ID-based entry generation"



### Fixed
Expand Down
117 changes: 114 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,52 @@
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;

import static net.sf.jabref.gui.importer.fetcher.EntryFetchers.getIdFetchers;
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer if you don't import this as static.


/**
* 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 JabRefFrame frame;
private static final int COLUMN = 3;
private final boolean biblatexMode;

Expand All @@ -47,7 +66,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 +85,8 @@ public EntryTypeDialog(JabRefFrame frame) {
// modal dialog
super(frame, true);

this.frame = frame;

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

Expand All @@ -91,12 +112,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(createIdFetcher("ID based generator"));
}

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

private JPanel createIdFetcher(String groupTitle) {
Copy link
Member

Choose a reason for hiding this comment

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

Rename to "createIdFetcherPanel" and remove parameter. Just pass it directly to the method below and use Localization.lang to have the title translated into other languages.

JButton searchButton = new JButton(Localization.lang("Search"));
JTextField idTextField = new JTextField("");
JComboBox<String> comboBox = new JComboBox<>();
getIdFetchers().forEach(n -> comboBox.addItem(n.getName()));
Copy link
Member

Choose a reason for hiding this comment

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

rename n -> fetcher

JLabel fetcherLabel = new JLabel("ID type"), idLabel = new JLabel("ID");

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

@Override
protected Optional<BibEntry> doInBackground() throws Exception {
searchID = idTextField.getText();
if (!searchID.isEmpty()) {
fetcher = EntryFetchers.getIdFetchers().get(comboBox.getSelectedIndex());
try {
bibEntry = fetcher.performSearchById(searchID);
dispose();
} catch (FetcherException e) {
LOGGER.error(Localization.lang("Error_fetching_from_'%0'.", fetcher.getName()), e);
JOptionPane.showMessageDialog(null, Localization.lang("Error_fetching_from_'%0'.", fetcher.getName()), Localization.lang("Error_ while_fetching."), JOptionPane.ERROR_MESSAGE);
}
}
return bibEntry;
}

@Override
protected void done() {
if (isCancelled()) {
return;
}

try {
Optional<BibEntry> result = get();
if (result.isPresent()) {
frame.getCurrentBasePanel().insertEntry(result.get());
} else {
JOptionPane.showMessageDialog(null, Localization.lang("No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.", searchID, fetcher.getName()), Localization.lang("No_files_found."), JOptionPane.WARNING_MESSAGE);
Copy link
Member

Choose a reason for hiding this comment

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

no underscore

Copy link
Member

Choose a reason for hiding this comment

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

fetcher could be null I think (select a fetcher in the dialog but let the id empty -> click search)

}
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

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

Proper logging

}
}
};

searchButton.addActionListener(n -> 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(searchButton);

jPanel.add(buttons, constraints);
jPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), groupTitle));


Copy link
Member

Choose a reason for hiding this comment

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

Please remove line, so that one empty line is remaining.

return jPanel;
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof TypeButton) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 +31,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 List<IdBasedFetcher> getIdFetchers() {
List<IdBasedFetcher> list = new LinkedList<>();
Copy link
Member

Choose a reason for hiding this comment

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

Why not ArrayList? It is faster at sorting.

list.add(new IsbnFetcher(Globals.prefs.getImportFormatPreferences()));
list.add(new DiVA(Globals.prefs.getImportFormatPreferences()));
list.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
return list;
}
}
4 changes: 3 additions & 1 deletion src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,6 @@ See_what_has_been_changed_in_the_JabRef_versions=
Referenced_BibTeX_key_does_not_exist=


Finished_downloading_full_text_document_for_entry_%0.=
Full_text_document_download_failed_for_entry_%0.=
Look_up_full_text_documents=
You_are_about_to_look_up_full_text_documents_for_%0_entries.=
Expand All @@ -1778,3 +1777,6 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
Finished_downloading_full_text_document_for_entry_%0.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2490,3 +2490,4 @@ last_four_nonpunctuation_characters_should_be_numerals=Die letzten vier Nichtint
Remember_password?=Passwort_merken?

shared=geteilt
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=Kein_Eintrag_mit_der_ID_'%0'_für_fetcher_'%1'_wurde_gefunden.
Copy link
Member

@koppor koppor Sep 12, 2016

Choose a reason for hiding this comment

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

We also updated this when we met. Why is our new String lost?

The current translation is not good. For instance, all nouns are written in capital letters in German.

1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2306,3 +2306,4 @@ Look_up_full_text_documents=Look_up_full_text_documents
You_are_about_to_look_up_full_text_documents_for_%0_entries.=You_are_about_to_look_up_full_text_documents_for_%0_entries.
last_four_nonpunctuation_characters_should_be_numerals=last_four_nonpunctuation_characters_should_be_numerals
shared=shared
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1679,3 +1679,4 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2459,3 +2459,4 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1726,3 +1726,5 @@ last_four_nonpunctuation_characters_should_be_numerals=Les_4_derniers_caractère
Remember_password?=

shared=
last_four_nonpunctuation_characters_should_be_numerals=
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1695,3 +1695,4 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1796,3 +1796,4 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2436,3 +2436,4 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2468,3 +2468,4 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2860,3 +2860,6 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_was_found.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1692,3 +1692,6 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_was_found.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2437,3 +2437,6 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_was_found.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1640,3 +1640,8 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=Kom_ihåg_lösenord?

shared=delad
Remember_password?=
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate. :-)


No_entry_with_id_'%0'_was_found.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1713,3 +1713,6 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_was_found.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2463,3 +2463,6 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_was_found.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1704,3 +1704,6 @@ last_four_nonpunctuation_characters_should_be_numerals=
Remember_password?=

shared=
No_entry_with_id_'%0'_was_found.=

No_entry_with_id_'%0'_for_fetcher_'%1'_was_found.=