Skip to content

Commit

Permalink
Sharelatex Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Aug 12, 2017
1 parent 56577b5 commit 1b545e4
Show file tree
Hide file tree
Showing 37 changed files with 1,897 additions and 16 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dependencies {
compile 'commons-logging:commons-logging:1.2'

compile 'org.jsoup:jsoup:1.10.3'

compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'info.debatty:java-string-similarity:0.24'

Expand All @@ -130,6 +131,12 @@ dependencies {
compile group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '1.0.+'
compile group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '1.0.+'

compile "org.glassfish.tyrus.bundles:tyrus-standalone-client:1.13.1"
compile "org.glassfish.tyrus.ext:tyrus-extension-deflate:1.13.1"

compile "com.google.code.gson:gson:2.8.0"
compile "org.bitbucket.cowwoc:diff-match-patch:1.1"

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.8.47'
testCompile 'com.github.tomakehurst:wiremock:2.7.1'
Expand Down
10 changes: 10 additions & 0 deletions external-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ Project: Flowless
URL: https://github.com/TomasMikula/Flowless
License: BSD-2-Clause

Id: org.glassfish.tyrus.bundles:tyrus-standalone-client
Projekt: Tyrus
URL: https://tyrus.java.net/
Licence: CDDL 1.1 and GPL 2 with CPE

Id: com.google.code.gson:gson
Project: google-gson
URL: https://github.com/google/gson
License: Apache-2.0

Id: org.fxmisc.richtext:richtextfx
Project: RichTextFX
URL: https://github.com/TomasMikula/RichTextFX
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.server.RemoteListenerServerLifecycle;
import org.jabref.logic.sharelatex.ShareLatexManager;
import org.jabref.logic.util.BuildInfo;
import org.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -48,6 +49,8 @@ public class Globals {
* Manager for the state of the GUI.
*/
public static StateManager stateManager = new StateManager();

public static ShareLatexManager shareLatexManager = new ShareLatexManager();
// Key binding preferences
private static KeyBindingRepository keyBindingRepository;
// Background tasks
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.sharelatex.ShareLatexManager;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
Expand Down Expand Up @@ -35,6 +36,8 @@ private static Object createDependency(Class<?> clazz) {
return Globals.journalAbbreviationLoader;
} else if (clazz == StateManager.class) {
return Globals.stateManager;
} else if (clazz == ShareLatexManager.class) {
return Globals.shareLatexManager;
} else {
try {
return clazz.newInstance();
Expand Down
35 changes: 23 additions & 12 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.jabref.gui.actions.Actions;
import org.jabref.gui.actions.AutoLinkFilesAction;
import org.jabref.gui.actions.ConnectToSharedDatabaseAction;
import org.jabref.gui.actions.DisconnectFromSharelatexAction;
import org.jabref.gui.actions.ErrorConsoleAction;
import org.jabref.gui.actions.IntegrityCheckAction;
import org.jabref.gui.actions.LookupIdentifierAction;
Expand All @@ -78,7 +79,9 @@
import org.jabref.gui.actions.NewSubDatabaseAction;
import org.jabref.gui.actions.OpenBrowserAction;
import org.jabref.gui.actions.SearchForUpdateAction;
import org.jabref.gui.actions.SendChangesToShareLatexAction;
import org.jabref.gui.actions.SortTabsAction;
import org.jabref.gui.actions.SynchronizeWithShareLatexAction;
import org.jabref.gui.autosaveandbackup.AutosaveUIManager;
import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog;
import org.jabref.gui.customentrytypes.EntryCustomizationDialog;
Expand Down Expand Up @@ -153,6 +156,7 @@
* The main window of the application.
*/
public class JabRefFrame extends JFrame implements OutputPrinter {

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

// Frame titles.
Expand All @@ -170,13 +174,13 @@ public class JabRefFrame extends JFrame implements OutputPrinter {
private final JLabel statusLine = new JLabel("", SwingConstants.LEFT);
private final JLabel statusLabel = new JLabel(
Localization.lang("Status")
+ ':', SwingConstants.LEFT);
+ ':',
SwingConstants.LEFT);
private final JProgressBar progressBar = new JProgressBar();
private final FileHistoryMenu fileHistory = new FileHistoryMenu(prefs, this);
private final OpenDatabaseAction open = new OpenDatabaseAction(this, true);
private final EditModeAction editModeAction = new EditModeAction();


// Here we instantiate menu/toolbar actions. Actions regarding
// the currently open database are defined as a GeneralAction
// with a unique command string. This causes the appropriate
Expand Down Expand Up @@ -391,6 +395,10 @@ public void actionPerformed(ActionEvent e) {
Localization.lang("Unabbreviate journal names of the selected entries"),
Globals.getKeyPrefs().getKey(KeyBinding.UNABBREVIATE));
private final AbstractAction manageJournals = new ManageJournalsAction();
private final AbstractAction synchronizeWithSharelatex = new SynchronizeWithShareLatexAction();
private final AbstractAction sendChangesToShareLatex = new SendChangesToShareLatexAction();
private final AbstractAction disconnectFromSharelatex = new DisconnectFromSharelatexAction();

private final AbstractAction databaseProperties = new DatabasePropertiesAction();
private final AbstractAction bibtexKeyPattern = new BibtexKeyPatternAction();
private final AbstractAction errorConsole = new ErrorConsoleAction();
Expand Down Expand Up @@ -421,8 +429,7 @@ public void actionPerformed(ActionEvent e) {
private final GeneralAction findUnlinkedFiles = new GeneralAction(
FindUnlinkedFilesDialog.ACTION_COMMAND,
FindUnlinkedFilesDialog.ACTION_MENU_TITLE, FindUnlinkedFilesDialog.ACTION_SHORT_DESCRIPTION,
Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES)
);
Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES));
private final AutoLinkFilesAction autoLinkFile = new AutoLinkFilesAction();
// The action for adding a new entry of unspecified type.
private final NewEntryAction newEntryAction = new NewEntryAction(this, Globals.getKeyPrefs().getKey(KeyBinding.NEW_ENTRY));
Expand Down Expand Up @@ -613,9 +620,7 @@ public void windowClosing(WindowEvent e) {

// Poor-mans binding to global state
// We need to invoke this in the JavaFX thread as all the listeners sit there
Platform.runLater(() ->
Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext()))
);
Platform.runLater(() -> Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext())));
if (new SearchPreferences(Globals.prefs).isGlobalSearch()) {
globalSearchBar.performSearch();
} else {
Expand Down Expand Up @@ -707,7 +712,7 @@ public void setWindowTitle() {
String changeFlag = panel.isModified() && !isAutosaveEnabled ? "*" : "";
String databaseFile = panel.getBibDatabaseContext().getDatabaseFile().map(File::getPath)
.orElse(GUIGlobals.UNTITLED_TITLE);
setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
} else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) {
setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " ["
+ Localization.lang("shared") + "]" + modeInfo);
Expand Down Expand Up @@ -1056,6 +1061,10 @@ private void fillMenu() {
file.addSeparator();
file.add(connectToSharedDatabaseAction);
file.add(pullChangesFromSharedDatabase);
file.addSeparator();
file.add(synchronizeWithSharelatex);
file.add(sendChangesToShareLatex);
file.add(disconnectFromSharelatex);

file.addSeparator();
file.add(databaseProperties);
Expand Down Expand Up @@ -1332,6 +1341,7 @@ private void createToolBar() {
tlb.addAction(cleanupEntries);
tlb.addAction(mergeEntries);
tlb.addAction(pullChangesFromSharedDatabase);
tlb.addAction(synchronizeWithSharelatex);
tlb.addAction(openConsole);

tlb.addSeparator();
Expand Down Expand Up @@ -1582,7 +1592,7 @@ private void trackOpenNewDatabase(BasePanel basePanel) {

Map<String, String> properties = new HashMap<>();
Map<String, Double> measurements = new HashMap<>();
measurements.put("NumberOfEntries", (double)basePanel.getDatabaseContext().getDatabase().getEntryCount());
measurements.put("NumberOfEntries", (double) basePanel.getDatabaseContext().getDatabase().getEntryCount());

Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements));
}
Expand Down Expand Up @@ -1927,6 +1937,7 @@ public GlobalSearchBar getGlobalSearchBar() {
}

private static class MyGlassPane extends JPanel {

public MyGlassPane() {
addKeyListener(new KeyAdapter() {
// Nothing
Expand Down Expand Up @@ -2087,8 +2098,7 @@ private class ChangeTabAction extends MnemonicAwareAction {
private final boolean next;

public ChangeTabAction(boolean next) {
putValue(Action.NAME, next ? Localization.menuTitle("Next tab") :
Localization.menuTitle("Previous tab"));
putValue(Action.NAME, next ? Localization.menuTitle("Next tab") : Localization.menuTitle("Previous tab"));
this.next = next;
putValue(Action.ACCELERATOR_KEY,
next ? Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB) : Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB));
Expand Down Expand Up @@ -2125,7 +2135,8 @@ public EditAction(String command, String menuTitle, String description, KeyStrok
putValue(Action.SHORT_DESCRIPTION, description);
}

@Override public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {

LOGGER.debug(Globals.getFocusListener().getFocused().toString());
JComponent source = Globals.getFocusListener().getFocused();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jabref.gui.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import org.jabref.Globals;

public class DisconnectFromSharelatexAction extends AbstractAction {

public DisconnectFromSharelatexAction() {
super();
putValue(Action.NAME, "Disconnect from ShareLaTeX");

}

@Override
public void actionPerformed(ActionEvent e) {
Globals.shareLatexManager.disconnectAndCloseConnection();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.jabref.gui.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import org.jabref.Globals;
import org.jabref.gui.StateManager;
import org.jabref.logic.sharelatex.ShareLatexManager;

public class SendChangesToShareLatexAction extends AbstractAction {

public SendChangesToShareLatexAction() {
super();
putValue(Action.NAME, "Send changes to ShareLaTeX Server");

}

@Override
public void actionPerformed(ActionEvent e) {

ShareLatexManager manager = Globals.shareLatexManager;
StateManager stateManager = Globals.stateManager;
manager.sendNewDatabaseContent(stateManager.getActiveDatabase().get());
System.out.println("Send changes");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jabref.gui.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import javafx.application.Platform;

import org.jabref.gui.IconTheme;
import org.jabref.gui.sharelatex.ShareLatexLoginDialogView;

public class SynchronizeWithShareLatexAction extends AbstractAction {

public SynchronizeWithShareLatexAction() {
super();
putValue(Action.NAME, "Synchronize with ShareLaTeX");
putValue(Action.SMALL_ICON, IconTheme.getImage("sharelatex"));
putValue(Action.SHORT_DESCRIPTION, "Synchronize with ShareLaTeX");

}

@Override
public void actionPerformed(ActionEvent e) {
Platform.runLater(() -> new ShareLatexLoginDialogView().show());

}
}
4 changes: 1 addition & 3 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ private Node createSourceEditor(BibEntry entry, BibDatabaseMode mode) {
codeArea.setEditable(false);
LOGGER.debug("Incorrect entry", ex);
}

return new VirtualizedScrollPane<>(codeArea);
}

Expand Down Expand Up @@ -206,8 +205,7 @@ private void storeSource() {
Localization.lang("Problem with parsing entry"),
Localization.lang("Error") + ": " + ex.getMessage(),
Localization.lang("Edit"),
Localization.lang("Revert to original source")
);
Localization.lang("Revert to original source"));

if (!keepEditing) {
// Revert
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jabref.gui.sharelatex;

import javax.inject.Inject;

import javafx.fxml.FXML;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import org.jabref.gui.AbstractController;
import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialog;
import org.jabref.gui.FXDialogService;
import org.jabref.logic.sharelatex.ShareLatexManager;

public class ShareLatexLoginDialogController extends AbstractController<ShareLatexLoginDialogViewModel> {

@FXML private TextField tbAddress;
@FXML private TextField tbUsername;
@FXML private PasswordField pfPassword;
@Inject private ShareLatexManager manager;

@FXML
private void initialize() {
viewModel = new ShareLatexLoginDialogViewModel();
}

@FXML
private void closeDialog() {
getStage().close();
}

@FXML
private void signIn() {

try {
String result = manager.login(tbAddress.getText(), tbUsername.getText(), pfPassword.getText());
if (result.contains("incorrect")) {
FXDialog dlg = new FXDialog(AlertType.ERROR);
dlg.setContentText("Your email or password is incorrect. Please try again");
dlg.showAndWait();
} else {
ShareLatexProjectDialogView dlgprojects = new ShareLatexProjectDialogView();
dlgprojects.show();
closeDialog();
}
} catch (Exception e) {
DialogService dlg = new FXDialogService();
dlg.showErrorDialogAndWait(e);

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jabref.gui.sharelatex;

import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.DialogPane;

import org.jabref.gui.AbstractDialogView;
import org.jabref.gui.FXDialog;

public class ShareLatexLoginDialogView extends AbstractDialogView {

@Override
public void show() {
FXDialog sharelatexProjectDialog = new FXDialog(AlertType.INFORMATION, "Sharelatex Project Dialog");
sharelatexProjectDialog.setDialogPane((DialogPane) this.getView());
sharelatexProjectDialog.setResizable(true);
sharelatexProjectDialog.show();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.jabref.gui.sharelatex;

import org.jabref.gui.AbstractViewModel;

public class ShareLatexLoginDialogViewModel extends AbstractViewModel {
//default construtor used
}
Loading

0 comments on commit 1b545e4

Please sign in to comment.