-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Changes from 5 commits
82d7058
5db873a
ff0e145
2194f06
b9267ba
8636916
eb19ac6
269bf4f
2095052
b2c9853
60a08a1
c8383fc
3ad4c2d
98cf063
a3458b5
f0e71e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
|
@@ -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; | ||
} | ||
|
@@ -66,6 +85,8 @@ public EntryTypeDialog(JabRefFrame frame) { | |
// modal dialog | ||
super(frame, true); | ||
|
||
this.frame = frame; | ||
|
||
bibDatabaseContext = frame.getCurrentBasePanel().getBibDatabaseContext(); | ||
biblatexMode = bibDatabaseContext.isBiblatexMode(); | ||
|
||
|
@@ -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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
panel.add(createEntryGroupPanel(Localization.lang("Custom"), CustomEntryTypesManager.ALL)); | ||
} | ||
|
||
panel.add(createIdFetcher("ID based generator")); | ||
} | ||
|
||
return panel; | ||
|
@@ -148,6 +174,91 @@ private JPanel createEntryGroupPanel(String groupTitle, Collection<EntryType> en | |
return panel; | ||
} | ||
|
||
private JPanel createIdFetcher(String groupTitle) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no underscore There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not |
||
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1640,3 +1640,8 @@ last_four_nonpunctuation_characters_should_be_numerals= | |
Remember_password?=Kom_ihåg_lösenord? | ||
|
||
shared=delad | ||
Remember_password?= | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.= |
There was a problem hiding this comment.
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"