Skip to content

Commit 1b545e4

Browse files
committed
Sharelatex Integration
1 parent 56577b5 commit 1b545e4

37 files changed

+1897
-16
lines changed

build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ dependencies {
111111
compile 'commons-logging:commons-logging:1.2'
112112

113113
compile 'org.jsoup:jsoup:1.10.3'
114+
114115
compile 'com.mashape.unirest:unirest-java:1.4.9'
115116
compile 'info.debatty:java-string-similarity:0.24'
116117

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

134+
compile "org.glassfish.tyrus.bundles:tyrus-standalone-client:1.13.1"
135+
compile "org.glassfish.tyrus.ext:tyrus-extension-deflate:1.13.1"
136+
137+
compile "com.google.code.gson:gson:2.8.0"
138+
compile "org.bitbucket.cowwoc:diff-match-patch:1.1"
139+
133140
testCompile 'junit:junit:4.12'
134141
testCompile 'org.mockito:mockito-core:2.8.47'
135142
testCompile 'com.github.tomakehurst:wiremock:2.7.1'

external-libraries.txt

+10
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ Project: Flowless
143143
URL: https://github.com/TomasMikula/Flowless
144144
License: BSD-2-Clause
145145

146+
Id: org.glassfish.tyrus.bundles:tyrus-standalone-client
147+
Projekt: Tyrus
148+
URL: https://tyrus.java.net/
149+
Licence: CDDL 1.1 and GPL 2 with CPE
150+
151+
Id: com.google.code.gson:gson
152+
Project: google-gson
153+
URL: https://github.com/google/gson
154+
License: Apache-2.0
155+
146156
Id: org.fxmisc.richtext:richtextfx
147157
Project: RichTextFX
148158
URL: https://github.com/TomasMikula/RichTextFX

src/main/java/org/jabref/Globals.java

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jabref.logic.journals.JournalAbbreviationLoader;
1515
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
1616
import org.jabref.logic.remote.server.RemoteListenerServerLifecycle;
17+
import org.jabref.logic.sharelatex.ShareLatexManager;
1718
import org.jabref.logic.util.BuildInfo;
1819
import org.jabref.preferences.JabRefPreferences;
1920

@@ -48,6 +49,8 @@ public class Globals {
4849
* Manager for the state of the GUI.
4950
*/
5051
public static StateManager stateManager = new StateManager();
52+
53+
public static ShareLatexManager shareLatexManager = new ShareLatexManager();
5154
// Key binding preferences
5255
private static KeyBindingRepository keyBindingRepository;
5356
// Background tasks

src/main/java/org/jabref/gui/DefaultInjector.java

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.jabref.gui.keyboard.KeyBindingRepository;
77
import org.jabref.gui.util.TaskExecutor;
88
import org.jabref.logic.journals.JournalAbbreviationLoader;
9+
import org.jabref.logic.sharelatex.ShareLatexManager;
910
import org.jabref.preferences.PreferencesService;
1011

1112
import com.airhacks.afterburner.injection.Injector;
@@ -35,6 +36,8 @@ private static Object createDependency(Class<?> clazz) {
3536
return Globals.journalAbbreviationLoader;
3637
} else if (clazz == StateManager.class) {
3738
return Globals.stateManager;
39+
} else if (clazz == ShareLatexManager.class) {
40+
return Globals.shareLatexManager;
3841
} else {
3942
try {
4043
return clazz.newInstance();

src/main/java/org/jabref/gui/JabRefFrame.java

+23-12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.jabref.gui.actions.Actions;
6868
import org.jabref.gui.actions.AutoLinkFilesAction;
6969
import org.jabref.gui.actions.ConnectToSharedDatabaseAction;
70+
import org.jabref.gui.actions.DisconnectFromSharelatexAction;
7071
import org.jabref.gui.actions.ErrorConsoleAction;
7172
import org.jabref.gui.actions.IntegrityCheckAction;
7273
import org.jabref.gui.actions.LookupIdentifierAction;
@@ -78,7 +79,9 @@
7879
import org.jabref.gui.actions.NewSubDatabaseAction;
7980
import org.jabref.gui.actions.OpenBrowserAction;
8081
import org.jabref.gui.actions.SearchForUpdateAction;
82+
import org.jabref.gui.actions.SendChangesToShareLatexAction;
8183
import org.jabref.gui.actions.SortTabsAction;
84+
import org.jabref.gui.actions.SynchronizeWithShareLatexAction;
8285
import org.jabref.gui.autosaveandbackup.AutosaveUIManager;
8386
import org.jabref.gui.bibtexkeypattern.BibtexKeyPatternDialog;
8487
import org.jabref.gui.customentrytypes.EntryCustomizationDialog;
@@ -153,6 +156,7 @@
153156
* The main window of the application.
154157
*/
155158
public class JabRefFrame extends JFrame implements OutputPrinter {
159+
156160
private static final Log LOGGER = LogFactory.getLog(JabRefFrame.class);
157161

158162
// Frame titles.
@@ -170,13 +174,13 @@ public class JabRefFrame extends JFrame implements OutputPrinter {
170174
private final JLabel statusLine = new JLabel("", SwingConstants.LEFT);
171175
private final JLabel statusLabel = new JLabel(
172176
Localization.lang("Status")
173-
+ ':', SwingConstants.LEFT);
177+
+ ':',
178+
SwingConstants.LEFT);
174179
private final JProgressBar progressBar = new JProgressBar();
175180
private final FileHistoryMenu fileHistory = new FileHistoryMenu(prefs, this);
176181
private final OpenDatabaseAction open = new OpenDatabaseAction(this, true);
177182
private final EditModeAction editModeAction = new EditModeAction();
178183

179-
180184
// Here we instantiate menu/toolbar actions. Actions regarding
181185
// the currently open database are defined as a GeneralAction
182186
// with a unique command string. This causes the appropriate
@@ -391,6 +395,10 @@ public void actionPerformed(ActionEvent e) {
391395
Localization.lang("Unabbreviate journal names of the selected entries"),
392396
Globals.getKeyPrefs().getKey(KeyBinding.UNABBREVIATE));
393397
private final AbstractAction manageJournals = new ManageJournalsAction();
398+
private final AbstractAction synchronizeWithSharelatex = new SynchronizeWithShareLatexAction();
399+
private final AbstractAction sendChangesToShareLatex = new SendChangesToShareLatexAction();
400+
private final AbstractAction disconnectFromSharelatex = new DisconnectFromSharelatexAction();
401+
394402
private final AbstractAction databaseProperties = new DatabasePropertiesAction();
395403
private final AbstractAction bibtexKeyPattern = new BibtexKeyPatternAction();
396404
private final AbstractAction errorConsole = new ErrorConsoleAction();
@@ -421,8 +429,7 @@ public void actionPerformed(ActionEvent e) {
421429
private final GeneralAction findUnlinkedFiles = new GeneralAction(
422430
FindUnlinkedFilesDialog.ACTION_COMMAND,
423431
FindUnlinkedFilesDialog.ACTION_MENU_TITLE, FindUnlinkedFilesDialog.ACTION_SHORT_DESCRIPTION,
424-
Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES)
425-
);
432+
Globals.getKeyPrefs().getKey(KeyBinding.FIND_UNLINKED_FILES));
426433
private final AutoLinkFilesAction autoLinkFile = new AutoLinkFilesAction();
427434
// The action for adding a new entry of unspecified type.
428435
private final NewEntryAction newEntryAction = new NewEntryAction(this, Globals.getKeyPrefs().getKey(KeyBinding.NEW_ENTRY));
@@ -613,9 +620,7 @@ public void windowClosing(WindowEvent e) {
613620

614621
// Poor-mans binding to global state
615622
// We need to invoke this in the JavaFX thread as all the listeners sit there
616-
Platform.runLater(() ->
617-
Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext()))
618-
);
623+
Platform.runLater(() -> Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext())));
619624
if (new SearchPreferences(Globals.prefs).isGlobalSearch()) {
620625
globalSearchBar.performSearch();
621626
} else {
@@ -707,7 +712,7 @@ public void setWindowTitle() {
707712
String changeFlag = panel.isModified() && !isAutosaveEnabled ? "*" : "";
708713
String databaseFile = panel.getBibDatabaseContext().getDatabaseFile().map(File::getPath)
709714
.orElse(GUIGlobals.UNTITLED_TITLE);
710-
setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
715+
setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
711716
} else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) {
712717
setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " ["
713718
+ Localization.lang("shared") + "]" + modeInfo);
@@ -1056,6 +1061,10 @@ private void fillMenu() {
10561061
file.addSeparator();
10571062
file.add(connectToSharedDatabaseAction);
10581063
file.add(pullChangesFromSharedDatabase);
1064+
file.addSeparator();
1065+
file.add(synchronizeWithSharelatex);
1066+
file.add(sendChangesToShareLatex);
1067+
file.add(disconnectFromSharelatex);
10591068

10601069
file.addSeparator();
10611070
file.add(databaseProperties);
@@ -1332,6 +1341,7 @@ private void createToolBar() {
13321341
tlb.addAction(cleanupEntries);
13331342
tlb.addAction(mergeEntries);
13341343
tlb.addAction(pullChangesFromSharedDatabase);
1344+
tlb.addAction(synchronizeWithSharelatex);
13351345
tlb.addAction(openConsole);
13361346

13371347
tlb.addSeparator();
@@ -1582,7 +1592,7 @@ private void trackOpenNewDatabase(BasePanel basePanel) {
15821592

15831593
Map<String, String> properties = new HashMap<>();
15841594
Map<String, Double> measurements = new HashMap<>();
1585-
measurements.put("NumberOfEntries", (double)basePanel.getDatabaseContext().getDatabase().getEntryCount());
1595+
measurements.put("NumberOfEntries", (double) basePanel.getDatabaseContext().getDatabase().getEntryCount());
15861596

15871597
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements));
15881598
}
@@ -1927,6 +1937,7 @@ public GlobalSearchBar getGlobalSearchBar() {
19271937
}
19281938

19291939
private static class MyGlassPane extends JPanel {
1940+
19301941
public MyGlassPane() {
19311942
addKeyListener(new KeyAdapter() {
19321943
// Nothing
@@ -2087,8 +2098,7 @@ private class ChangeTabAction extends MnemonicAwareAction {
20872098
private final boolean next;
20882099

20892100
public ChangeTabAction(boolean next) {
2090-
putValue(Action.NAME, next ? Localization.menuTitle("Next tab") :
2091-
Localization.menuTitle("Previous tab"));
2101+
putValue(Action.NAME, next ? Localization.menuTitle("Next tab") : Localization.menuTitle("Previous tab"));
20922102
this.next = next;
20932103
putValue(Action.ACCELERATOR_KEY,
20942104
next ? Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB) : Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB));
@@ -2125,7 +2135,8 @@ public EditAction(String command, String menuTitle, String description, KeyStrok
21252135
putValue(Action.SHORT_DESCRIPTION, description);
21262136
}
21272137

2128-
@Override public void actionPerformed(ActionEvent e) {
2138+
@Override
2139+
public void actionPerformed(ActionEvent e) {
21292140

21302141
LOGGER.debug(Globals.getFocusListener().getFocused().toString());
21312142
JComponent source = Globals.getFocusListener().getFocused();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.jabref.gui.actions;
2+
3+
import java.awt.event.ActionEvent;
4+
5+
import javax.swing.AbstractAction;
6+
import javax.swing.Action;
7+
8+
import org.jabref.Globals;
9+
10+
public class DisconnectFromSharelatexAction extends AbstractAction {
11+
12+
public DisconnectFromSharelatexAction() {
13+
super();
14+
putValue(Action.NAME, "Disconnect from ShareLaTeX");
15+
16+
}
17+
18+
@Override
19+
public void actionPerformed(ActionEvent e) {
20+
Globals.shareLatexManager.disconnectAndCloseConnection();
21+
}
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.jabref.gui.actions;
2+
3+
import java.awt.event.ActionEvent;
4+
5+
import javax.swing.AbstractAction;
6+
import javax.swing.Action;
7+
8+
import org.jabref.Globals;
9+
import org.jabref.gui.StateManager;
10+
import org.jabref.logic.sharelatex.ShareLatexManager;
11+
12+
public class SendChangesToShareLatexAction extends AbstractAction {
13+
14+
public SendChangesToShareLatexAction() {
15+
super();
16+
putValue(Action.NAME, "Send changes to ShareLaTeX Server");
17+
18+
}
19+
20+
@Override
21+
public void actionPerformed(ActionEvent e) {
22+
23+
ShareLatexManager manager = Globals.shareLatexManager;
24+
StateManager stateManager = Globals.stateManager;
25+
manager.sendNewDatabaseContent(stateManager.getActiveDatabase().get());
26+
System.out.println("Send changes");
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.jabref.gui.actions;
2+
3+
import java.awt.event.ActionEvent;
4+
5+
import javax.swing.AbstractAction;
6+
import javax.swing.Action;
7+
8+
import javafx.application.Platform;
9+
10+
import org.jabref.gui.IconTheme;
11+
import org.jabref.gui.sharelatex.ShareLatexLoginDialogView;
12+
13+
public class SynchronizeWithShareLatexAction extends AbstractAction {
14+
15+
public SynchronizeWithShareLatexAction() {
16+
super();
17+
putValue(Action.NAME, "Synchronize with ShareLaTeX");
18+
putValue(Action.SMALL_ICON, IconTheme.getImage("sharelatex"));
19+
putValue(Action.SHORT_DESCRIPTION, "Synchronize with ShareLaTeX");
20+
21+
}
22+
23+
@Override
24+
public void actionPerformed(ActionEvent e) {
25+
Platform.runLater(() -> new ShareLatexLoginDialogView().show());
26+
27+
}
28+
}

src/main/java/org/jabref/gui/entryeditor/SourceTab.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ private Node createSourceEditor(BibEntry entry, BibDatabaseMode mode) {
9696
codeArea.setEditable(false);
9797
LOGGER.debug("Incorrect entry", ex);
9898
}
99-
10099
return new VirtualizedScrollPane<>(codeArea);
101100
}
102101

@@ -206,8 +205,7 @@ private void storeSource() {
206205
Localization.lang("Problem with parsing entry"),
207206
Localization.lang("Error") + ": " + ex.getMessage(),
208207
Localization.lang("Edit"),
209-
Localization.lang("Revert to original source")
210-
);
208+
Localization.lang("Revert to original source"));
211209

212210
if (!keepEditing) {
213211
// Revert
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.jabref.gui.sharelatex;
2+
3+
import javax.inject.Inject;
4+
5+
import javafx.fxml.FXML;
6+
import javafx.scene.control.Alert.AlertType;
7+
import javafx.scene.control.PasswordField;
8+
import javafx.scene.control.TextField;
9+
10+
import org.jabref.gui.AbstractController;
11+
import org.jabref.gui.DialogService;
12+
import org.jabref.gui.FXDialog;
13+
import org.jabref.gui.FXDialogService;
14+
import org.jabref.logic.sharelatex.ShareLatexManager;
15+
16+
public class ShareLatexLoginDialogController extends AbstractController<ShareLatexLoginDialogViewModel> {
17+
18+
@FXML private TextField tbAddress;
19+
@FXML private TextField tbUsername;
20+
@FXML private PasswordField pfPassword;
21+
@Inject private ShareLatexManager manager;
22+
23+
@FXML
24+
private void initialize() {
25+
viewModel = new ShareLatexLoginDialogViewModel();
26+
}
27+
28+
@FXML
29+
private void closeDialog() {
30+
getStage().close();
31+
}
32+
33+
@FXML
34+
private void signIn() {
35+
36+
try {
37+
String result = manager.login(tbAddress.getText(), tbUsername.getText(), pfPassword.getText());
38+
if (result.contains("incorrect")) {
39+
FXDialog dlg = new FXDialog(AlertType.ERROR);
40+
dlg.setContentText("Your email or password is incorrect. Please try again");
41+
dlg.showAndWait();
42+
} else {
43+
ShareLatexProjectDialogView dlgprojects = new ShareLatexProjectDialogView();
44+
dlgprojects.show();
45+
closeDialog();
46+
}
47+
} catch (Exception e) {
48+
DialogService dlg = new FXDialogService();
49+
dlg.showErrorDialogAndWait(e);
50+
51+
}
52+
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.jabref.gui.sharelatex;
2+
3+
import javafx.scene.control.Alert.AlertType;
4+
import javafx.scene.control.DialogPane;
5+
6+
import org.jabref.gui.AbstractDialogView;
7+
import org.jabref.gui.FXDialog;
8+
9+
public class ShareLatexLoginDialogView extends AbstractDialogView {
10+
11+
@Override
12+
public void show() {
13+
FXDialog sharelatexProjectDialog = new FXDialog(AlertType.INFORMATION, "Sharelatex Project Dialog");
14+
sharelatexProjectDialog.setDialogPane((DialogPane) this.getView());
15+
sharelatexProjectDialog.setResizable(true);
16+
sharelatexProjectDialog.show();
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.jabref.gui.sharelatex;
2+
3+
import org.jabref.gui.AbstractViewModel;
4+
5+
public class ShareLatexLoginDialogViewModel extends AbstractViewModel {
6+
//default construtor used
7+
}

0 commit comments

Comments
 (0)