Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into selectFilesDlg
Browse files Browse the repository at this point in the history
* upstream/master:
  Refactor shared package into the architecture (#3523)
  • Loading branch information
Siedlerchr committed Jan 2, 2018
2 parents d4aed9b + c751715 commit e71181a
Show file tree
Hide file tree
Showing 44 changed files with 243 additions and 164 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.Version;
import org.jabref.model.database.shared.DatabaseNotSupportedException;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.shared.exception.DatabaseNotSupportedException;
import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.shared.exception.NotASharedDatabaseException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.jabref.logic.net.URLDownload;
import org.jabref.logic.search.DatabaseSearcher;
import org.jabref.logic.search.SearchQuery;
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.logic.util.OS;
import org.jabref.model.Defaults;
import org.jabref.model.EntryTypes;
Expand All @@ -49,7 +50,6 @@
import org.jabref.model.metadata.MetaData;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.SearchPreferences;
import org.jabref.shared.prefs.SharedDatabasePreferences;

import com.google.common.base.Throwables;
import org.apache.commons.logging.Log;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@
import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.DatabaseLocation;
import org.jabref.model.database.KeyCollisionException;
import org.jabref.model.database.event.BibDatabaseContextChangedEvent;
import org.jabref.model.database.event.CoarseChangeFilter;
import org.jabref.model.database.event.EntryAddedEvent;
import org.jabref.model.database.event.EntryRemovedEvent;
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.database.shared.DatabaseSynchronizer;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.EntryType;
import org.jabref.model.entry.FieldName;
Expand All @@ -141,7 +142,6 @@
import org.jabref.model.entry.specialfields.SpecialFieldValue;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreviewPreferences;
import org.jabref.shared.DBMSSynchronizer;

import com.google.common.eventbus.Subscribe;
import com.jgoodies.forms.builder.FormBuilder;
Expand Down Expand Up @@ -591,7 +591,7 @@ public void update() {
.openConsole(frame.getCurrentBasePanel().getBibDatabaseContext().getDatabaseFile().orElse(null)));

actions.put(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, (BaseAction) () -> {
DBMSSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel().getBibDatabaseContext()
DatabaseSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel().getBibDatabaseContext()
.getDBMSSynchronizer();
dbmsSynchronizer.pullChanges();
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.database.DatabaseLocation;
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibtexEntryTypes;
import org.jabref.model.entry.EntryType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Encodings;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.DatabaseLocation;
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.metadata.MetaData;
import org.jabref.model.metadata.SaveOrderConfig;
import org.jabref.preferences.JabRefPreferences;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
import org.jabref.logic.exporter.SaveSession;
import org.jabref.logic.l10n.Encodings;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.logic.util.FileExtensions;
import org.jabref.logic.util.io.FileBasedLock;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.DatabaseLocation;
import org.jabref.model.database.event.ChangePropagation;
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.shared.DBMSConnectionProperties;
import org.jabref.shared.prefs.SharedDatabasePreferences;

import com.jgoodies.forms.builder.FormBuilder;
import com.jgoodies.forms.layout.FormLayout;
Expand Down Expand Up @@ -318,10 +317,9 @@ public void saveAs(File file) throws Exception {

if (context.getLocation() == DatabaseLocation.SHARED) {
// Save all properties dependent on the ID. This makes it possible to restore them.
DBMSConnectionProperties properties = context.getDBMSSynchronizer().getDBProcessor()
.getDBMSConnectionProperties();
new SharedDatabasePreferences(context.getDatabase().generateSharedDatabaseID())
.putAllDBMSConnectionProperties(properties);
.putAllDBMSConnectionProperties(context.getDBMSSynchronizer().getConnectionProperties());

}

context.setDatabaseFile(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
import org.jabref.logic.importer.OpenDatabase;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
import org.jabref.logic.util.FileExtensions;
import org.jabref.logic.util.io.FileBasedLock;
import org.jabref.migrations.FileLinksUpgradeWarning;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.shared.DatabaseNotSupportedException;
import org.jabref.model.strings.StringUtil;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.shared.exception.DatabaseNotSupportedException;
import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.shared.exception.NotASharedDatabaseException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.logic.util.FileExtensions;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.JabRefPreferencesFilter;
import org.jabref.shared.prefs.SharedDatabasePreferences;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import org.apache.commons.logging.Log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.DBMSConnection;
import org.jabref.logic.shared.DBMSConnectionProperties;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.logic.shared.security.Password;
import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.DatabaseLocation;
import org.jabref.model.database.shared.DBMSType;
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.database.shared.DatabaseNotSupportedException;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.shared.DBMSConnection;
import org.jabref.shared.DBMSConnectionProperties;
import org.jabref.shared.DBMSType;
import org.jabref.shared.exception.DatabaseNotSupportedException;
import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.shared.prefs.SharedDatabasePreferences;
import org.jabref.shared.security.Password;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -461,9 +461,9 @@ private boolean isSharedDatabaseAlreadyPresent() {
List<BasePanel> panels = JabRefGUI.getMainFrame().getBasePanelList();
return panels.parallelStream().anyMatch(panel -> {
BibDatabaseContext context = panel.getBibDatabaseContext();

return ((context.getLocation() == DatabaseLocation.SHARED) &&
this.connectionProperties.equals(context.getDBMSSynchronizer()
.getDBProcessor().getDBMSConnectionProperties()));
this.connectionProperties.equals(context.getDBMSSynchronizer().getConnectionProperties()));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
import org.jabref.gui.mergeentries.MergeEntries;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.database.shared.DatabaseSynchronizer;
import org.jabref.model.entry.BibEntry;
import org.jabref.shared.DBMSSynchronizer;

public class MergeSharedEntryDialog {

private final JabRefFrame jabRefFrame;
private final DBMSSynchronizer dbmsSynchronizer;
private final DatabaseSynchronizer dbmsSynchronizer;
private final BibEntry localBibEntry;
private final BibEntry sharedBibEntry;
private final JDialog mergeDialog;
private final MergeEntries mergeEntries;


public MergeSharedEntryDialog(JabRefFrame jabRefFrame, DBMSSynchronizer dbmsSynchronizer, BibEntry localBibEntry,
BibEntry sharedBibEntry, BibDatabaseMode bibDatabaseMode) {
public MergeSharedEntryDialog(JabRefFrame jabRefFrame, DatabaseSynchronizer dbmsSynchronizer, BibEntry localBibEntry,
BibEntry sharedBibEntry, BibDatabaseMode bibDatabaseMode) {
this.jabRefFrame = jabRefFrame;
this.dbmsSynchronizer = dbmsSynchronizer;
this.localBibEntry = localBibEntry;
Expand Down
37 changes: 20 additions & 17 deletions src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@
import org.jabref.gui.undo.UndoableRemoveEntry;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.DBMSConnection;
import org.jabref.logic.shared.DBMSConnectionProperties;
import org.jabref.logic.shared.DBMSSynchronizer;
import org.jabref.logic.shared.event.ConnectionLostEvent;
import org.jabref.logic.shared.event.SharedEntryNotPresentEvent;
import org.jabref.logic.shared.event.UpdateRefusedEvent;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
import org.jabref.logic.shared.prefs.SharedDatabasePreferences;
import org.jabref.model.Defaults;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.database.DatabaseLocation;
import org.jabref.shared.DBMSConnectionProperties;
import org.jabref.shared.DBMSSynchronizer;
import org.jabref.shared.event.ConnectionLostEvent;
import org.jabref.shared.event.SharedEntryNotPresentEvent;
import org.jabref.shared.event.UpdateRefusedEvent;
import org.jabref.shared.exception.DatabaseNotSupportedException;
import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.shared.exception.NotASharedDatabaseException;
import org.jabref.shared.prefs.SharedDatabasePreferences;
import org.jabref.model.database.shared.DatabaseNotSupportedException;
import org.jabref.model.database.shared.DatabaseSynchronizer;

import com.google.common.eventbus.Subscribe;

public class SharedDatabaseUIManager {

private final JabRefFrame jabRefFrame;
private DBMSSynchronizer dbmsSynchronizer;
private DatabaseSynchronizer dbmsSynchronizer;

public SharedDatabaseUIManager(JabRefFrame jabRefFrame) {
this.jabRefFrame = jabRefFrame;
Expand Down Expand Up @@ -105,11 +106,12 @@ public BasePanel openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectio
throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException {
JabRefFrame frame = JabRefGUI.getMainFrame();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED,
Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode));
DBMSSynchronizer synchronizer = new DBMSSynchronizer(bibDatabaseContext, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
bibDatabaseContext.convertToSharedDatabase(synchronizer);

dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer();
dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties);
dbmsSynchronizer.openSharedDatabase(new DBMSConnection(dbmsConnectionProperties));
dbmsSynchronizer.registerListener(this);
frame.output(Localization.lang("Connection to %0 server established.", dbmsConnectionProperties.getType().toString()));
return frame.addTab(bibDatabaseContext, true);
Expand All @@ -130,14 +132,15 @@ public void openSharedDatabaseFromParserResult(ParserResult parserResult)

JabRefFrame frame = JabRefGUI.getMainFrame();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED,
Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode));
DBMSSynchronizer synchronizer = new DBMSSynchronizer(bibDatabaseContext, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
bibDatabaseContext.convertToSharedDatabase(synchronizer);

bibDatabaseContext.getDatabase().setSharedDatabaseID(sharedDatabaseID);
bibDatabaseContext.setDatabaseFile(parserResult.getDatabaseContext().getDatabaseFile().orElse(null));

dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer();
dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties);
dbmsSynchronizer.openSharedDatabase(new DBMSConnection(dbmsConnectionProperties));
dbmsSynchronizer.registerListener(this);
parserResult.setDatabaseContext(bibDatabaseContext);
frame.output(Localization.lang("Connection to %0 server established.", dbmsConnectionProperties.getType().toString()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.shared;
package org.jabref.logic.shared;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -7,12 +7,14 @@
import java.util.Set;

import org.jabref.logic.l10n.Localization;
import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.model.database.shared.DBMSType;
import org.jabref.model.database.shared.DatabaseConnection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DBMSConnection {
public class DBMSConnection implements DatabaseConnection {

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

Expand Down Expand Up @@ -45,10 +47,12 @@ public DBMSConnection(DBMSConnectionProperties properties) throws SQLException,
}
}

@Override
public Connection getConnection() {
return this.connection;
}

@Override
public DBMSConnectionProperties getProperties() {
return this.properties;
}
Expand Down
Loading

0 comments on commit e71181a

Please sign in to comment.