Skip to content

Commit

Permalink
Add new model class for project, use ModelView as wrapper around mode…
Browse files Browse the repository at this point in the history
…l class

Show error dialog if user/password incorrect
  • Loading branch information
Siedlerchr committed May 28, 2017
1 parent 1997bb8 commit 1d0e706
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
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.FXDialog;
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 ShareLatexManager manager;
@Inject private ShareLatexManager manager;

@FXML
private void initialize() {
Expand All @@ -34,10 +36,14 @@ private void signIn() {
System.out.println(pfPassword.getText());

String result = manager.login(tbAddress.getText(), tbUsername.getText(), pfPassword.getText());
System.out.println(result);

ShareLatexProjectDialogView dlgprojects = new ShareLatexProjectDialogView();
dlgprojects.show();
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();
}

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

import org.jabref.gui.AbstractController;
import org.jabref.logic.sharelatex.ShareLatexManager;

import javax.inject.Inject;

import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;

import org.jabref.gui.AbstractController;
import org.jabref.logic.sharelatex.ShareLatexManager;

public class ShareLatexProjectDialogController extends AbstractController<ShareLatexProjectDialogViewModel> {

@FXML TableColumn<ShareLatexProjectViewModel, String> colTitle;
@FXML TableColumn<ShareLatexProjectViewModel, String> colOwner;
@FXML TableColumn<ShareLatexProjectViewModel, String> colLastModified;
@FXML TableView<ShareLatexProjectViewModel> tblProjects;
@Inject ShareLatexManager manager;
@FXML private TableColumn<ShareLatexProjectViewModel, String> colTitle;
@FXML private TableColumn<ShareLatexProjectViewModel, String> colOwner;
@FXML private TableColumn<ShareLatexProjectViewModel, String> colLastModified;
@FXML private TableView<ShareLatexProjectViewModel> tblProjects;
@Inject private ShareLatexManager manager;

@FXML
private void initialize() {

viewModel = new ShareLatexProjectDialogViewModel(manager.getProjects());
viewModel = new ShareLatexProjectDialogViewModel();
viewModel.addProjects(manager.getProjects());

colTitle.setCellValueFactory(cellData -> cellData.getValue().getProjectTitle());
colOwner.setCellValueFactory(cellData -> cellData.getValue().getOwner());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package org.jabref.gui.sharelatex;

import java.util.List;
import java.util.stream.Collectors;

import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;

import org.jabref.gui.AbstractViewModel;
import org.jabref.model.sharelatex.ShareLatexProject;

public class ShareLatexProjectDialogViewModel extends AbstractViewModel {

private final SimpleListProperty<ShareLatexProjectViewModel> projects = new SimpleListProperty<>(
FXCollections.observableArrayList());

public ShareLatexProjectDialogViewModel(List<ShareLatexProjectViewModel> projects) {
this.projects.addAll(projects);
public void addProjects(List<ShareLatexProject> projectsToAdd) {
this.projects.addAll(projectsToAdd.stream().map(ShareLatexProjectViewModel::new).collect(Collectors.toList()));
}

public SimpleListProperty<ShareLatexProjectViewModel> projectsProperty() {
return this.projects;
}

public ShareLatexProjectDialogViewModel() {
// TODO Auto-generated constructor stub
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.model.sharelatex.ShareLatexProject;

/**
* Data class
* @author CS
Expand All @@ -15,12 +17,12 @@ public class ShareLatexProjectViewModel {
private final StringProperty owner;
private final StringProperty lastUpdated;

public ShareLatexProjectViewModel(String projectId, String projectTitle, String owner, String lastUpdated) {
public ShareLatexProjectViewModel(ShareLatexProject project) {

this.projectId = projectId;
this.projectTitle = new SimpleStringProperty(projectTitle);
this.owner = new SimpleStringProperty(owner);
this.lastUpdated = new SimpleStringProperty(lastUpdated);
this.projectId = project.getProjectId();
this.projectTitle = new SimpleStringProperty(project.getProjectTitle());
this.owner = new SimpleStringProperty(project.getOwner());
this.lastUpdated = new SimpleStringProperty(project.getLastUpdated());

}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/logic/sharelatex/ShareLatexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
import java.util.ArrayList;
import java.util.List;

import org.jabref.gui.sharelatex.ShareLatexProjectViewModel;
import org.jabref.model.sharelatex.ShareLatexProject;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;

public class ShareLatexManager {

private final SharelatexConnector connector = new SharelatexConnector();
private final List<ShareLatexProjectViewModel> projects = new ArrayList<>();
private final List<ShareLatexProject> projects = new ArrayList<>();

public String login(String server, String username, String password) {
return connector.connectToServer(server, username, password);
}

public List<ShareLatexProjectViewModel> getProjects() {
public List<ShareLatexProject> getProjects() {
try {
connector.getProjects().ifPresent(jsonResponse -> {
if (jsonResponse.has("projects")) {
Expand All @@ -38,8 +38,8 @@ public List<ShareLatexProjectViewModel> getProjects() {
System.out.println("LastUpdated " + lastUpdated);
System.out.println("Owner" + owner);

ShareLatexProjectViewModel model = new ShareLatexProjectViewModel(id, name, owner, lastUpdated);
projects.add(model);
ShareLatexProject project = new ShareLatexProject(id, name, owner, lastUpdated);
projects.add(project);
//TODO: How do I pass this projectLIst to the other view?
}

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/jabref/model/sharelatex/ShareLatexProject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jabref.model.sharelatex;

public class ShareLatexProject {

private final String projectId;
private final String projectTitle;
private final String owner;
private final String lastUpdated;

public ShareLatexProject(String projectId, String projectTitle, String owner, String lastUpdated) {
this.projectId = projectId;
this.projectTitle = projectTitle;
this.lastUpdated = lastUpdated;
this.owner = owner;
}

public String getLastUpdated() {
return lastUpdated;
}

public String getProjectId() {
return projectId;
}

public String getProjectTitle() {
return projectTitle;
}

public String getOwner() {
return owner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import org.jabref.gui.sharelatex.ShareLatexProjectViewModel;
import org.jabref.model.sharelatex.ShareLatexProject;

import org.junit.Test;

Expand All @@ -15,7 +15,7 @@ public void test() {
ShareLatexManager manager = new ShareLatexManager();
manager.login("http://192.168.1.248", "joe@example.com", "test");

List<ShareLatexProjectViewModel> projects = manager.getProjects();
List<ShareLatexProject> projects = manager.getProjects();
assertFalse(projects.isEmpty());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import org.junit.Test;


public class SharelatexConnectorTest {

@Test
public void test() {

SharelatexConnector connector = new SharelatexConnector();
connector.connectToServer("http://192.168.1.248", "joe@example.com", "test");

}

}

0 comments on commit 1d0e706

Please sign in to comment.