Skip to content

Commit

Permalink
Fix #1476 NPE when importing from SQL DB because of missing DatabaseM…
Browse files Browse the repository at this point in the history
…ode (#1477)
  • Loading branch information
stefan-kolb committed Jun 6, 2016
1 parent 956abf0 commit 241b336
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
### Fixed
- Fixed [#405](https://github.com/JabRef/jabref/issues/405): Added more {} around capital letters in Unicode/HTML to LaTeX conversion to preserve them
- Alleviate multiuser concurrency issue when near simultaneous saves occur to a shared database file

- Fixed [#1476](https://github.com/JabRef/jabref/issues/1476): NPE when importing from SQL DB because of missing DatabaseMode

### Removed

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import net.sf.jabref.logic.remote.RemotePreferences;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.CustomEntryType;
import net.sf.jabref.model.entry.EntryUtil;
import net.sf.jabref.model.entry.InternalBibtexFields;
Expand Down Expand Up @@ -1037,6 +1038,19 @@ public Color getDefaultColor(String key) {
return new Color(rgb[0], rgb[1], rgb[2]);
}

/**
* Returns the default BibDatabase mode, which can be either BIBTEX or BIBLATEX.
*
* @return the default BibDatabaseMode
*/
public BibDatabaseMode getDefaultBibDatabaseMode() {
if (getBoolean(BIBLATEX_DEFAULT_MODE)) {
return BibDatabaseMode.BIBLATEX;
} else {
return BibDatabaseMode.BIBTEX;
}
}

/**
* Set the default value for a key. This is useful for plugins that need to add default values for the prefs keys
* they use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,11 @@ private void buildGUI() {
// check mode of currently used DB
if (panel != null) {
mode = panel.getBibDatabaseContext().getMode();
} else { // use preferences value if no DB is open
if (Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)) {
mode = BibDatabaseMode.BIBLATEX;
} else {
mode = BibDatabaseMode.BIBTEX;
}
} else {
// use preferences value if no DB is open
mode = Globals.prefs.getDefaultBibDatabaseMode();
}

for (EntryType type : EntryTypes.getAllValues(mode)) {
textFields.put(type.getName().toLowerCase(), addEntryType(pan, type, y));
y++;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/net/sf/jabref/sql/importer/DbImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.swing.JOptionPane;

import net.sf.jabref.BibDatabaseContext;
import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.MnemonicAwareAction;
Expand Down Expand Up @@ -69,11 +70,8 @@ public AbstractAction getAction() {
}

class DbImpAction extends MnemonicAwareAction {

public DbImpAction() {
super();
putValue(Action.NAME, Localization.menuTitle("Import from external SQL database"));

}

@Override
Expand Down Expand Up @@ -151,14 +149,14 @@ private void performImport() {
Localization.lang("There are no available databases to be imported"),
Localization.lang("Import from SQL database"), JOptionPane.INFORMATION_MESSAGE);
} else {
DBImportExportDialog dialogo = new DBImportExportDialog(frame, matrix,
DBImportExportDialog.DialogType.IMPORTER);
DBImportExportDialog dialogo = new DBImportExportDialog(frame, matrix, DBImportExportDialog.DialogType.IMPORTER);
if (dialogo.removeAction) {
String dbName = dialogo.selectedDB;
DatabaseUtil.removeDB(dialogo, dbName, conn, databaseContext);
performImport();
} else if (dialogo.moreThanOne) {
databases = importer.performImport(dbs, dialogo.listOfDBs, frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
// use default DB mode for import
databases = importer.performImport(dbs, dialogo.listOfDBs, Globals.prefs.getDefaultBibDatabaseMode());
for (DBImporterResult res : databases) {
databaseContext = res.getDatabaseContext();
dbs.isConfigValid(true);
Expand Down

0 comments on commit 241b336

Please sign in to comment.