Skip to content

Commit

Permalink
Update Preview Panel on Generate BibtexKey
Browse files Browse the repository at this point in the history
Fix for JabRef#1353
Fixed some missing unlocks
Some formatting
  • Loading branch information
Siedlerchr committed May 8, 2016
1 parent f968736 commit daf4437
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Fixed [#1271](https://github.com/JabRef/jabref/issues/1271): Authors with compound first names are displayed properly
- Fixed: Selecting invalid jstyle causes NPE and prevents opening of style selection dialog
- Fixed: Move linked files to default directory works again
- Fixed [#1353](https://github.com/JabRef/jabref/issues/1353): Fetch-Preview did not display updated BibTeX-Key after clicking on `Generate Now`

### Removed
- Removed possibility to export entries/databases to an `.sql` file, as the logic cannot easily use the correct escape logic
Expand Down
85 changes: 41 additions & 44 deletions src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2003-2015 JabRef contributors.
/* Copyright (C) 2003-2016 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
Expand Down Expand Up @@ -142,6 +142,7 @@
* receiving this call).
*/
public class ImportInspectionDialog extends JDialog implements ImportInspector, OutputPrinter {

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

private BasePanel panel;
Expand Down Expand Up @@ -284,8 +285,7 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam
bb.addGlue();
bb.addButton(ok);
bb.addButton(stop);
JButton cancel = new JButton(
Localization.lang("Cancel"));
JButton cancel = new JButton(Localization.lang("Cancel"));
bb.addButton(cancel);
bb.addRelatedGap();
JButton help = new HelpAction(HelpFiles.IMPORT_INSPECTION).getHelpButton();
Expand Down Expand Up @@ -341,8 +341,8 @@ public ImportInspectionDialog(JabRefFrame frame, BasePanel panel, String undoNam
getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);

// Remember and default to last size:
setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH), Globals.prefs
.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT)));
setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_WIDTH),
Globals.prefs.getInt(JabRefPreferences.IMPORT_INSPECTION_DIALOG_HEIGHT)));
addWindowListener(new WindowAdapter() {

@Override
Expand Down Expand Up @@ -438,7 +438,6 @@ private Optional<BibEntry> internalDuplicate(Collection<BibEntry> entriesDupe, B
return Optional.empty();
}


/* (non-Javadoc)
* @see net.sf.jabref.gui.ImportInspection#entryListComplete()
*/
Expand All @@ -458,7 +457,6 @@ public void entryListComplete() {
}
}


/**
* Generate key for the selected entry only.
*/
Expand Down Expand Up @@ -492,7 +490,7 @@ private void generateKeySelectedEntry() {
// make sure the key was unique:
database.removeEntry(entry);

entries.getReadWriteLock().writeLock().lock();
entries.getReadWriteLock().writeLock().unlock();
glTable.repaint();
}

Expand Down Expand Up @@ -529,6 +527,9 @@ private void generateKeys() {
// Add the generated key to our list:
keys.add(entry.getCiteKey());
}

preview.update();
preview.repaint();
// Remove the entries from the database again, since they are not
// supposed to
// added yet. They only needed to be in it while we generated the keys,
Expand All @@ -537,7 +538,7 @@ private void generateKeys() {
for (BibEntry entry : entries) {
database.removeEntry(entry);
}
entries.getReadWriteLock().writeLock().lock();
entries.getReadWriteLock().writeLock().unlock();
glTable.repaint();
}

Expand Down Expand Up @@ -580,6 +581,7 @@ private AbstractAction getAction(GroupTreeNode node) {
return action;
}


/**
* Stores the information about the selected entries being scheduled for
* addition to this group. The entries are *not* added to the group at this
Expand All @@ -590,6 +592,7 @@ class AddToGroupAction extends AbstractAction {

private final GroupTreeNode node;


public AddToGroupAction(GroupTreeNode node) {
super(node.getName());
this.node = node;
Expand All @@ -615,10 +618,12 @@ public void actionPerformed(ActionEvent event) {
}
}


public void addCallBack(CallBack cb) {
callBacks.add(cb);
}


private class OkListener implements ActionListener {

@Override
Expand All @@ -642,10 +647,11 @@ public void actionPerformed(ActionEvent event) {
// is indicated by the entry's group hit status:
if (entry.isGroupHit()) {
CheckBoxMessage cbm = new CheckBoxMessage(
Localization.lang("There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"),
Localization.lang(
"There are possible duplicates (marked with an icon) that haven't been resolved. Continue?"),
Localization.lang("Disable this confirmation dialog"), false);
int answer = JOptionPane.showConfirmDialog(ImportInspectionDialog.this,
cbm, Localization.lang("Duplicates found"), JOptionPane.YES_NO_OPTION);
int answer = JOptionPane.showConfirmDialog(ImportInspectionDialog.this, cbm,
Localization.lang("Duplicates found"), JOptionPane.YES_NO_OPTION);
if (cbm.isSelected()) {
Globals.prefs.putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, false);
}
Expand Down Expand Up @@ -707,7 +713,8 @@ private void removeEntriesToDelete(NamedCompound ce) {
private void addSelectedEntries(NamedCompound ce, final List<BibEntry> selected) {
if (newDatabase) {
// Create a new BasePanel for the entries:
Defaults defaults = new Defaults(BibDatabaseMode.fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)));
Defaults defaults = new Defaults(BibDatabaseMode
.fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)));
panel = new BasePanel(frame, new BibDatabaseContext(defaults), Globals.prefs.getDefaultEncoding());
}

Expand Down Expand Up @@ -741,7 +748,6 @@ private void addSelectedEntries(NamedCompound ce, final List<BibEntry> selected)
groupingCanceled = addToGroups(ce, entry, groups);
}


entry.setId(IdGenerator.next());
panel.getDatabase().insertEntry(entry);
ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), entry, panel));
Expand All @@ -760,11 +766,9 @@ private boolean addToGroups(NamedCompound ce, BibEntry entry, Set<GroupTreeNode>
// The best course of action is probably to ask the
// user if a key should be generated
// immediately.
int answer = JOptionPane
.showConfirmDialog(
ImportInspectionDialog.this,
Localization.lang("Cannot add entries to group without generating keys. Generate keys now?"),
Localization.lang("Add to group"), JOptionPane.YES_NO_OPTION);
int answer = JOptionPane.showConfirmDialog(ImportInspectionDialog.this,
Localization.lang("Cannot add entries to group without generating keys. Generate keys now?"),
Localization.lang("Add to group"), JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) {
generateKeys();
} else {
Expand Down Expand Up @@ -808,6 +812,7 @@ private List<BibEntry> getSelectedEntries() {

}


private void signalStopFetching() {
callBacks.forEach(c -> c.stopFetching());
}
Expand All @@ -830,6 +835,7 @@ private void setWidths() {
}
}


private class DeleteListener extends AbstractAction {

public DeleteListener() {
Expand Down Expand Up @@ -866,6 +872,7 @@ private class SelectionButton implements ActionListener {

private final Boolean enable;


public SelectionButton(boolean enable) {
this.enable = enable;
}
Expand Down Expand Up @@ -916,9 +923,8 @@ public void mouseClicked(MouseEvent e) {
return;
}
FileListEntry fl = tableModel.getEntry(0);
(new ExternalFileMenuItem(frame, entry, "", fl.link, null,
panel.getBibDatabaseContext(), fl.type))
.actionPerformed(null);
(new ExternalFileMenuItem(frame, entry, "", fl.link, null, panel.getBibDatabaseContext(),
fl.type)).actionPerformed(null);
}
} else { // Must be URL_COL
openExternalLink(URL_FIELD, e);
Expand Down Expand Up @@ -1029,7 +1035,8 @@ public void mousePressed(MouseEvent e) {
// Is this the duplicate icon column, and is there an icon?
if ((col == DUPL_COL) && (glTable.getValueAt(row, col) != null)) {
BibEntry first = sortedList.get(row);
Optional<BibEntry> other = DuplicateCheck.containsDuplicate(panel.getDatabase(), first, panel.getBibDatabaseContext().getMode());
Optional<BibEntry> other = DuplicateCheck.containsDuplicate(panel.getDatabase(), first,
panel.getBibDatabaseContext().getMode());
if (other.isPresent()) {
// This will be true if the duplicate is in the existing
// database.
Expand Down Expand Up @@ -1134,11 +1141,11 @@ public void actionPerformed(ActionEvent event) {
}
}

class DownloadFile extends JMenuItem implements ActionListener,
DownloadExternalFile.DownloadCallback {
class DownloadFile extends JMenuItem implements ActionListener, DownloadExternalFile.DownloadCallback {

private BibEntry entry;


public DownloadFile() {
super(Localization.lang("Download file"));
addActionListener(this);
Expand All @@ -1154,8 +1161,7 @@ public void actionPerformed(ActionEvent actionEvent) {
if (bibtexKey == null) {
int answer = JOptionPane.showConfirmDialog(frame,
Localization.lang("This entry has no BibTeX key. Generate key now?"),
Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (answer == JOptionPane.OK_OPTION) {
generateKeySelectedEntry();
bibtexKey = entry.getCiteKey();
Expand Down Expand Up @@ -1198,8 +1204,7 @@ public void actionPerformed(ActionEvent actionEvent) {
if (entry.getCiteKey() == null) {
int answer = JOptionPane.showConfirmDialog(frame,
Localization.lang("This entry has no BibTeX key. Generate key now?"),
Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
Localization.lang("Download file"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (answer == JOptionPane.OK_OPTION) {
generateKeySelectedEntry();
} else {
Expand All @@ -1219,16 +1224,16 @@ public void actionPerformed(ActionEvent actionEvent) {
entries.getReadWriteLock().writeLock().unlock();
glTable.repaint();
}
} , diag));
}, diag));

}
}

private class LinkLocalFile extends JMenuItem implements ActionListener,
DownloadExternalFile.DownloadCallback {
private class LinkLocalFile extends JMenuItem implements ActionListener, DownloadExternalFile.DownloadCallback {

private BibEntry entry;


public LinkLocalFile() {
super(Localization.lang("Link local file"));
addActionListener(this);
Expand Down Expand Up @@ -1267,6 +1272,7 @@ public void downloadComplete(FileListEntry file) {
}
}


private void setupComparatorChooser() {
// First column:

Expand Down Expand Up @@ -1294,16 +1300,6 @@ private void setupComparatorChooser() {
comparators.add(new FieldComparator(INSPECTION_FIELDS.get(i - PAD)));
}

// Set initial sort columns:

/*
* // Default sort order: String[] sortFields = new String[]
* {Globals.prefs.get(JabRefPreferences.PRIMARY_SORT_FIELD), Globals.prefs.get(JabRefPreferences.SECONDARY_SORT_FIELD),
* Globals.prefs.get(JabRefPreferences.TERTIARY_SORT_FIELD)}; boolean[] sortDirections = new
* boolean[] {Globals.prefs.getBoolean(JabRefPreferences.PRIMARY_SORT_DESCENDING),
* Globals.prefs.getBoolean(JabRefPreferences.SECONDARY_SORT_DESCENDING),
* Globals.prefs.getBoolean(JabRefPreferences.TERTIARY_SORT_DESCENDING)}; // descending
*/
sortedList.getReadWriteLock().writeLock().lock();
comparatorChooser.appendComparator(PAD, 0, false);
sortedList.getReadWriteLock().writeLock().unlock();
Expand Down Expand Up @@ -1338,6 +1334,7 @@ class EntryTable extends JTable {

private final GeneralRenderer renderer = new GeneralRenderer(Color.white);


public EntryTable(TableModel model) {
super(model);
getTableHeader().setReorderingAllowed(false);
Expand Down Expand Up @@ -1426,8 +1423,7 @@ public Object getColumnValue(BibEntry entry, int i) {
} else {
String field = INSPECTION_FIELDS.get(i - PAD);
if (InternalBibtexFields.getFieldExtras(field).contains(FieldProperties.PERSON_NAMES)) {
return entry.getFieldOptional(field).map(AuthorList::fixAuthorNatbib)
.orElse("");
return entry.getFieldOptional(field).map(AuthorList::fixAuthorNatbib).orElse("");
} else {
return entry.getField(field);
}
Expand All @@ -1436,6 +1432,7 @@ public Object getColumnValue(BibEntry entry, int i) {

}


@Override
public void setStatus(String s) {
frame.setStatus(s);
Expand Down

0 comments on commit daf4437

Please sign in to comment.