Skip to content

Commit

Permalink
Refactor FXML and other gui elements to current architecture
Browse files Browse the repository at this point in the history
Make login to overleaf working
Fix test imports
  • Loading branch information
Siedlerchr committed Sep 5, 2020
1 parent ecb2690 commit e320d9b
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 123 deletions.
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 @@ -751,7 +751,7 @@ private MenuBar createMenu() {
factory.createSubMenu(StandardActions.REMOTE_DB,
factory.createMenuItem(StandardActions.CONNECT_TO_SHARED_DB, new ConnectToSharedDatabaseCommand(this)),
factory.createMenuItem(StandardActions.PULL_CHANGES_FROM_SHARED_DB, new PullChangesFromSharedAction(stateManager)),
factory.createMenuItem(StandardActions.SYNCHRONIZE_WITH_SHARELATEX, new SynchronizeWithShareLatexAction(dialogService))
factory.createMenuItem(StandardActions.SYNCHRONIZE_WITH_SHARELATEX, new SynchronizeWithShareLatexAction())
),

new SeparatorMenuItem(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package org.jabref.gui.actions;

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

public class SynchronizeWithShareLatexAction extends SimpleCommand {

private DialogService dialogService;

public SynchronizeWithShareLatexAction(DialogService dialogService) {
super();
this.dialogService = dialogService;
}

@Override
public void execute() {
dialogService.showCustomDialogAndWait(
new ShareLatexLoginDialogView());
new ShareLatexLoginDialogView().showAndWait();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
Expand All @@ -27,22 +28,18 @@
</rowConstraints>
<children>
<Label text="Server Address" />
<TextField id="tbAddress" fx:id="tbAddress" prefHeight="25.0" prefWidth="174.0" text="https://www.sharelatex.com" GridPane.columnIndex="1" />
<TextField id="tbAddress" fx:id="tbAddress" prefHeight="25.0" prefWidth="174.0" text="https://www.overleaf.com" GridPane.columnIndex="1" />
<TextField id="tbUsername" fx:id="tbUsername" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label alignment="CENTER_RIGHT" text="%Username" GridPane.rowIndex="1" />
<Label text="%Password" GridPane.rowIndex="2" />
<PasswordField id="tbPassword" fx:id="tbPassword" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</center>
<bottom>
<ButtonBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<buttons>
<Button id="btnLogin" fx:id="btnLogin" mnemonicParsing="false" onAction="#signIn" text="Login" ButtonBar.buttonData="OK_DONE" />
<Button id="btnCancel" cancelButton="true" mnemonicParsing="false" onAction="#closeDialog" text="%Cancel" ButtonBar.buttonData="CANCEL_CLOSE" />
</buttons>
</ButtonBar>
</bottom>
</center>
</BorderPane>
</content>
<buttonTypes>
<ButtonType fx:constant="CLOSE"/>
<ButtonType fx:id="connectButton" buttonData="OK_DONE" text="%Connect"/>
</buttonTypes>
</DialogPane>
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,46 @@
import javafx.fxml.FXML;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialog;
import org.jabref.gui.Globals;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ControlHelper;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.sharelatex.ShareLatexManager;
import org.jabref.logic.sharelatex.SharelatexConnectionProperties;

import com.airhacks.afterburner.views.ViewLoader;

public class ShareLatexLoginDialogView extends BaseDialog<Void> {

@FXML private TextField tbAddress;
@FXML private TextField tbUsername;
@FXML private PasswordField tbPassword;
@FXML private Button btnLogin;
@FXML private ButtonType connectButton;

private final Button btnLogin;
@Inject private ShareLatexManager manager;
@Inject private DialogService dialogService;

private SharelatexConnectionProperties props;
private ShareLatexLoginDialogViewModel viewModel;

public ShareLatexLoginDialogView() {
ViewLoader.view(this)
.load()
.setAsDialogPane(this);

}
ControlHelper.setAction(connectButton, this.getDialogPane(), event -> signIn());
btnLogin = (Button) this.getDialogPane().lookupButton(connectButton);

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

@FXML
private void closeDialog() {
private void initialize() {
}

@FXML
Expand All @@ -63,19 +69,13 @@ private void signIn() {

ShareLatexProjectDialogView dlgprojects = new ShareLatexProjectDialogView();
dlgprojects.show();
closeDialog();
this.close();

}
} catch (Exception e) {
dialogService.showErrorDialogAndWait(e);
}

}
/*
FXDialog sharelatexProjectDialog = new FXDialog(AlertType.INFORMATION, "Sharelatex Project Dialog");
sharelatexProjectDialog.setDialogPane((DialogPane) this.getView());
sharelatexProjectDialog.setResizable(true);
sharelatexProjectDialog.show();
*/

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>

<DialogPane prefHeight="494.0" prefWidth="397.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.sharelatex.ShareLatexProjectDialogController">
<DialogPane prefHeight="494.0" prefWidth="397.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.sharelatex.ShareLatexProjectDialogView">
<content>
<BorderPane>
<bottom>
<ButtonBar minWidth="-Infinity" BorderPane.alignment="CENTER">
<buttons>
<Button fx:id="btnSync" defaultButton="true" mnemonicParsing="false" onAction="#synchronizeLibrary" text="Synchronize Library" />
<Button fx:id="btnCancel" cancelButton="true" mnemonicParsing="false" onAction="#cancelAndClose" text="Cancel" ButtonBar.buttonData="CANCEL_CLOSE" />
</buttons>
</ButtonBar>
</bottom>
<top>
<TableView fx:id="tblProjects" BorderPane.alignment="CENTER">
<columns>
Expand All @@ -31,4 +24,8 @@
</top>
</BorderPane>
</content>
<buttonTypes>
<ButtonType fx:constant="CLOSE"/>
<ButtonType fx:id="syncButton" buttonData="OK_DONE" text="%Synchronize Library"/>
</buttonTypes>
</DialogPane>
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
import javax.inject.Inject;

import javafx.fxml.FXML;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.CheckBoxTableCell;

import org.jabref.gui.StateManager;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.logic.sharelatex.ShareLatexManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand All @@ -30,6 +33,9 @@ public class ShareLatexProjectDialogView extends BaseDialog<Void> {
@FXML private TableColumn<ShareLatexProjectViewModel, String> colLastName;
@FXML private TableColumn<ShareLatexProjectViewModel, String> colLastModified;
@FXML private TableView<ShareLatexProjectViewModel> tblProjects;

@FXML private ButtonType syncButton;

@Inject private ShareLatexManager manager;
@Inject private StateManager stateManager;
@Inject private PreferencesService preferences;
Expand All @@ -38,6 +44,15 @@ public class ShareLatexProjectDialogView extends BaseDialog<Void> {

@Inject private DefaultFileUpdateMonitor fileMonitor;

public ShareLatexProjectDialogView() {

ViewLoader.view(this)
.load()
.setAsDialogPane(this);

ControlHelper.setAction(syncButton, this.getDialogPane(), event -> synchronizeLibrary());
}

@FXML
private void initialize() {
viewModel = new ShareLatexProjectDialogViewModel(stateManager, manager, preferences.getImportFormatPreferences(), fileMonitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.StateManager;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ParserResult;
Expand All @@ -28,7 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ShareLatexProjectDialogViewModel extends AbstractViewModel {
public class ShareLatexProjectDialogViewModel{

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public class SharelatexConnector {
private final WebSocketClientWrapper client = new WebSocketClientWrapper();

private static final class AccessData {
public final String CsrfToken;
public final String User;
public final String Password;
public final String _csrf;
public final String email;
public final String password;

private AccessData(String csrfToken, String user, String password) {
CsrfToken = csrfToken;
User = user;
Password = password;
_csrf = csrfToken;
email = user;
this.password = password;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ public void onClose(Session session, CloseReason closeReason) {
}
}, cec, webSocketchannelUri);

//TODO: Change Dialog
//TODO: On database change event or on save event send new version
//TODO: When new db content arrived run merge dialog
//TODO: Identfiy active database/Name of database/doc Id (partly done)
// TODO: Change Dialog
// TODO: On database change event or on save event send new version
// TODO: When new db content arrived run merge dialog
// TODO: Identfiy active database/Name of database/doc Id (partly done)

} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.jabref.logic.sharelatex.events;

public class ShareLatexContinueMessageEvent {
//empty
// empty
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/model/sharelatex/Arg.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public void setVersion(int v) {
this.version = v;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jabref.logic.sharelatex;

import java.net.URISyntaxException;
import org.junit.Test;

import org.junit.jupiter.api.Test;

public class ShareLatexManagerTest {

Expand All @@ -12,9 +13,9 @@ public void test() throws URISyntaxException {
try {
ShareLatexManager manager = new ShareLatexManager();
manager.login("http://192.168.1.248", "joe@example.com", "test");
// manager.login("https://www.sharelatex.com", "email ", "password" );
projects = manager.getProjects();
assertFalse(projects.isEmpty());
} catch (IOException e) {
Expand Down
Loading

0 comments on commit e320d9b

Please sign in to comment.