Skip to content

Commit

Permalink
Merge remote tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
Fix Conflicts:
	CHANGELOG.md
	src/main/java/net/sf/jabref/shared/DBMSConnectionProperties.java
  • Loading branch information
obraliar committed Sep 22, 2016
2 parents 6cddecc + ee688c4 commit a439c9a
Show file tree
Hide file tree
Showing 69 changed files with 443 additions and 315 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- Prohibit more than one connections to the same shared database. Small Extension for [#970](https://github.com/JabRef/jabref/issues/970).
- Add session restoring functionality for shared database. Related to [#1703](https://github.com/JabRef/jabref/issues/1703)
- Implementation of LiveUpdate for PostgreSQL & Oracle systems. Related to [#970](https://github.com/JabRef/jabref/issues/970).
- Added fetcher for [MathSciNet](http://www.ams.org/mathscinet), [zbMATH](https://www.zbmath.org/) and [Astrophysics Data System](http://www.adsabs.harvard.edu/)
- Improved search:
Expand Down Expand Up @@ -43,6 +43,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Importer for MODS format added
- [#2012](https://github.com/JabRef/jabref/issues/2012) Implemented integrity check for `month` field: Should be an integer or normalized (BibLaTeX), Should be normalized (BibTeX)
- [#1779](https://github.com/JabRef/jabref/issues/1779) Implemented integrity check for `bibtexkey` field: Empty bibtexkey
- Prohibit more than one connections to the same shared database.

### Fixed
- Fixed selecting an entry out of multiple duplicates
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/sf/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.sf.jabref;

import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
Expand All @@ -21,6 +22,8 @@
import net.sf.jabref.gui.importer.ParserResultWarningDialog;
import net.sf.jabref.gui.importer.actions.OpenDatabaseAction;
import net.sf.jabref.gui.importer.worker.AutosaveStartupPrompter;
import net.sf.jabref.gui.shared.OpenSharedDatabaseDialog;
import net.sf.jabref.gui.shared.SharedDatabaseUIManager;
import net.sf.jabref.gui.worker.VersionWorker;
import net.sf.jabref.logic.importer.OpenDatabase;
import net.sf.jabref.logic.importer.ParserResult;
Expand All @@ -30,6 +33,7 @@
import net.sf.jabref.migrations.PreferencesMigrations;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.preferences.VersionPreferences;
import net.sf.jabref.shared.exception.DatabaseNotSupportedException;

import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.theme.SkyBluer;
Expand Down Expand Up @@ -192,6 +196,19 @@ private void openWindow() {
if (!bibDatabases.isEmpty()) {
JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus();
}

boolean isSharedDatabaseEdited = Globals.prefs.getBoolean(JabRefPreferences.SHARED_DATABASE_LAST_EDITED);
if (isSharedDatabaseEdited) {
boolean isFocused = Globals.prefs.getBoolean(JabRefPreferences.SHARED_DATABASE_LAST_FOCUSED);
String keywordSeparator = Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR);

try {
new SharedDatabaseUIManager(mainFrame, keywordSeparator).openLastSharedDatabaseTab(isFocused);
} catch (SQLException | DatabaseNotSupportedException e) {
LOGGER.info("Failed to restore shared database. Use connection dialog to connect.");
new OpenSharedDatabaseDialog(mainFrame).setVisible(true);
}
}
}

private void openLastEditedDatabases() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
import net.sf.jabref.logic.search.DatabaseSearcher;
import net.sf.jabref.logic.search.SearchQuery;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.Defaults;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseContext;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.metadata.MetaData;
import net.sf.jabref.model.strings.StringUtil;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.preferences.SearchPreferences;
import net.sf.jabref.shared.prefs.SharedDatabasePreferences;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/cli/AuxCommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import net.sf.jabref.logic.auxparser.AuxParser;
import net.sf.jabref.logic.auxparser.AuxParserResult;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.strings.StringUtil;

public class AuxCommandLine {
private final String auxFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Map;
import java.util.TreeMap;

import net.sf.jabref.model.util.HTMLUnicodeConversionMaps;
import net.sf.jabref.model.strings.HTMLUnicodeConversionMaps;

public class GenerateCharacterTable {

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public void windowClosing(WindowEvent e) {
} else {
String content = "";
SearchQuery currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if (currentSearchQuery != null && !currentSearchQuery.getQuery().trim().isEmpty()) {
if ((currentSearchQuery != null) && !currentSearchQuery.getQuery().trim().isEmpty()) {
content = currentSearchQuery.getQuery();
}
globalSearchBar.setSearchTerm(content, true);
Expand Down Expand Up @@ -789,6 +789,8 @@ private void tearDownJabRef(List<String> filenames) {
prefs.putStringList(JabRefPreferences.LAST_EDITED, filenames);
File focusedDatabase = getCurrentBasePanel().getBibDatabaseContext().getDatabaseFile().orElse(null);
new LastFocusedTabPreferences(prefs).setLastFocusedTab(focusedDatabase);
prefs.putBoolean(JabRefPreferences.SHARED_DATABASE_LAST_FOCUSED,
getCurrentBasePanel().getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED);
}

}
Expand Down Expand Up @@ -828,6 +830,9 @@ public boolean quit() {
// Ask here if the user really wants to close, if the base
// has not been saved since last save.
boolean close = true;

prefs.putBoolean(JabRefPreferences.SHARED_DATABASE_LAST_EDITED, Boolean.FALSE);

List<String> filenames = new ArrayList<>();
if (tabbedPane.getTabCount() > 0) {
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
Expand Down Expand Up @@ -862,6 +867,7 @@ public boolean quit() {
}
}
} else if (context.getLocation() == DatabaseLocation.SHARED) {
prefs.putBoolean(JabRefPreferences.SHARED_DATABASE_LAST_EDITED, Boolean.TRUE);
context.convertToLocalDatabase();
context.getDBMSSynchronizer().closeSharedDatabase();
context.clearDBMSSynchronizer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import net.sf.jabref.Globals;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.FileField;
import net.sf.jabref.model.strings.StringUtil;
import net.sf.jabref.preferences.JabRefPreferences;

public final class ExternalFileTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.sf.jabref.gui.fieldeditors.FieldEditor;
import net.sf.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.strings.StringUtil;

public class FieldTextMenu implements MouseListener {
private final FieldEditor field;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
import net.sf.jabref.logic.groups.GroupDescriptions;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.search.SearchQuery;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.ParseException;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.groups.AbstractGroup;
import net.sf.jabref.model.groups.ExplicitGroup;
import net.sf.jabref.model.groups.GroupHierarchyType;
import net.sf.jabref.model.groups.KeywordGroup;
import net.sf.jabref.model.groups.SearchGroup;
import net.sf.jabref.model.strings.StringUtil;
import net.sf.jabref.preferences.JabRefPreferences;

import com.jgoodies.forms.builder.ButtonBarBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import javax.swing.border.Border;
import javax.swing.tree.DefaultTreeCellRenderer;

import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.groups.GroupTreeNode;
import net.sf.jabref.model.strings.StringUtil;

/**
* Renders a GroupTreeNode using its group's getName() method, rather that its toString() method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.io.AutoSaveUtil;
import net.sf.jabref.logic.util.io.FileBasedLock;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.migrations.FileLinksUpgradeWarning;
import net.sf.jabref.model.Defaults;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseContext;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.metadata.MetaData;
import net.sf.jabref.model.strings.StringUtil;
import net.sf.jabref.preferences.JabRefPreferences;

import org.apache.commons.logging.Log;
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/net/sf/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,30 +555,39 @@ public boolean isFileColumn(int modelIndex) {
}

private boolean matches(int row, Matcher<BibEntry> m) {
return m.matches(getBibEntry(row));
Optional<BibEntry> bibEntry = getBibEntry(row);

if (bibEntry.isPresent()) {
return m.matches(bibEntry.get());
}
return m.matches(null);
}

private boolean isComplete(int row) {
try {
BibEntry entry = getBibEntry(row);
TypedBibEntry typedEntry = new TypedBibEntry(entry, panel.getBibDatabaseContext());
Optional<BibEntry> bibEntry = getBibEntry(row);

if (bibEntry.isPresent()) {
TypedBibEntry typedEntry = new TypedBibEntry(bibEntry.get(), panel.getBibDatabaseContext());
return typedEntry.hasAllRequiredFields();
} catch (NullPointerException ex) {
return true;
}
return true;
}

private int isMarked(int row) {
try {
BibEntry be = getBibEntry(row);
return EntryMarker.isMarked(be);
} catch (NullPointerException ex) {
return 0;
Optional<BibEntry> bibEntry = getBibEntry(row);

if (bibEntry.isPresent()) {
return EntryMarker.isMarked(bibEntry.get());
}
return 0;
}

private BibEntry getBibEntry(int row) {
return model.getTableRows().get(row);
private Optional<BibEntry> getBibEntry(int row) {
try {
return Optional.of(model.getTableRows().get(row));
} catch (IndexOutOfBoundsException e) {
return Optional.empty();
}
}

public void scrollTo(int y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
import net.sf.jabref.gui.help.HelpAction;
import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.Defaults;
import net.sf.jabref.model.database.BibDatabaseContext;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.database.DatabaseLocation;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.shared.DBMSConnection;
import net.sf.jabref.shared.DBMSConnectionProperties;
Expand Down Expand Up @@ -86,7 +82,6 @@ public class OpenSharedDatabaseDialog extends JDialog {
private final SharedDatabasePreferences prefs = new SharedDatabasePreferences();

private DBMSConnectionProperties connectionProperties;
private BibDatabaseContext bibDatabaseContext;

/**
* @param frame the JabRef Frame
Expand All @@ -113,13 +108,8 @@ public void openSharedDatabase() {
setLoadingConnectButtonText(true);

try {
bibDatabaseContext.getDBMSSynchronizer().openSharedDatabase(connectionProperties);
frame.addTab(bibDatabaseContext, true);
new SharedDatabaseUIManager(frame, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)).openNewSharedDatabaseTab(connectionProperties);
setPreferences();
bibDatabaseContext.getDBMSSynchronizer()
.registerListener(
new SharedDatabaseUIManager(frame, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)));
frame.output(Localization.lang("Connection_to_%0_server_established.", connectionProperties.getType().toString()));
dispose();
return; // setLoadingConnectButtonText(false) should not be reached regularly.
} catch (SQLException exception) {
Expand All @@ -142,10 +132,6 @@ private void setupActions() {
public void actionPerformed(ActionEvent e) {
try {
checkFields();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();

bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode),
DatabaseLocation.SHARED, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR));

connectionProperties = new DBMSConnectionProperties();
connectionProperties.setType((DBMSType) dbmsTypeDropDown.getSelectedItem());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
package net.sf.jabref.gui.shared;

import java.sql.SQLException;

import java.util.Objects;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefGUI;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.entryeditor.EntryEditor;
import net.sf.jabref.gui.undo.UndoableRemoveEntry;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.Defaults;
import net.sf.jabref.model.database.BibDatabaseContext;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.database.DatabaseLocation;
import net.sf.jabref.shared.DBMSConnectionProperties;
import net.sf.jabref.shared.DBMSSynchronizer;
import net.sf.jabref.shared.event.ConnectionLostEvent;
import net.sf.jabref.shared.event.SharedEntryNotPresentEvent;
import net.sf.jabref.shared.event.UpdateRefusedEvent;
import net.sf.jabref.shared.exception.DatabaseNotSupportedException;
import net.sf.jabref.shared.prefs.SharedDatabasePreferences;

import com.google.common.eventbus.Subscribe;

public class SharedDatabaseUIManager {

private final JabRefFrame jabRefFrame;
private final DBMSSynchronizer dbmsSynchronizer;
private final String keywordSeparator;
private DBMSSynchronizer dbmsSynchronizer;

public SharedDatabaseUIManager(JabRefFrame jabRefFrame, String keywordSeparator) {
this.jabRefFrame = jabRefFrame;
this.dbmsSynchronizer = jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getDBMSSynchronizer();
this.keywordSeparator = keywordSeparator;
}

Expand Down Expand Up @@ -82,4 +92,44 @@ public void listen(SharedEntryNotPresentEvent event) {
SwingUtilities.invokeLater(() -> panel.hideBottomComponent());
}
}

/**
* Opens a new shared database tab with the given {@link DBMSConnectionProperties}.
*
* @param dbmsConnectionProperties Connection data
* @param raiseTab If <code>true</code> the new tab gets selected.
*/
private void openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectionProperties, boolean raiseTab)
throws SQLException, DatabaseNotSupportedException {
JabRefFrame frame = JabRefGUI.getMainFrame();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED,
keywordSeparator);

dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer();
dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties);
frame.addTab(bibDatabaseContext, raiseTab);
dbmsSynchronizer.registerListener(this);
frame.output(Localization.lang("Connection_to_%0_server_established.", dbmsConnectionProperties.getType().toString()));
}

/**
* Opens a new shared database tab with the given {@link DBMSConnectionProperties}.
*
* @param dbmsConnectionProperties Connection data
*/
public void openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectionProperties)
throws SQLException, DatabaseNotSupportedException {
openNewSharedDatabaseTab(dbmsConnectionProperties, true);
}

/**
* Opens a new shared database tab with the already set {@link DBMSConnectionProperties}.
*
* @param raiseTab If <code>true</code> the new tab gets selected.
*/
public void openLastSharedDatabaseTab(boolean raiseTab)
throws SQLException, DatabaseNotSupportedException {
openNewSharedDatabaseTab(new DBMSConnectionProperties(new SharedDatabasePreferences()), raiseTab);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.sf.jabref.gui.undo;

import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.strings.StringUtil;

/**
* This class represents the change of type for an entry.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.sf.jabref.gui.undo;

import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.FieldChange;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.strings.StringUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down
Loading

0 comments on commit a439c9a

Please # to comment.