Skip to content

Commit

Permalink
Dropbox Tests
Browse files Browse the repository at this point in the history
* Add Dropbox Controller
* Add Dropbox tests
* Add Dropbox menu item
  • Loading branch information
brp14005 committed Feb 26, 2016
1 parent 0c8b7ac commit d09c959
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 25 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ out/
.gradletasknamecache
.gradle/
build/

# dropbox credentials
dropbox.json

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies {
compile group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '2.0-beta-7'
compile group: 'org.json', name: 'json', version: '20160212'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package directory;
package launcher;

import directory.FolderViewManager;
import directory.IronFile;
import javafx.fxml.FXML;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TreeView;
import com.dropbox.core.*;
import com.dropbox.core.v2.*;
import webapp.DropboxController;

import java.util.ResourceBundle;

Expand All @@ -12,13 +17,22 @@ public class Controller{
@FXML private MenuItem fileTag;
@FXML private MenuItem fileExit;
@FXML private MenuItem editPreferences;
@FXML private MenuItem fileDropboxSignin;
@FXML private TreeView<IronFile> dirTree;
@FXML private ResourceBundle resources;



@FXML private void initialize() {
FolderViewManager manager = new FolderViewManager(dirTree); // 2 statements in 1 line is best
IronFile[] hardDrives = IronFile.listRoots(); // an array of hard drives
manager.setRootDirectory(hardDrives);
DropboxController dbManager = new DropboxController();
try {
dbManager.test();
} catch (DbxException e) {
e.printStackTrace();
}
// directory.IronFile homeDir = new directory.IronFile(System.getProperty("user.home")); // use this for specific directory
// manager.setRootDirectory(homeDir);
}
Expand Down
54 changes: 45 additions & 9 deletions src/main/java/webapp/Dropbox.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,64 @@
package webapp;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileNotFoundException;
import java.io.File;
import java.io.FileReader;
import java.net.URL;

/**
* Dropbox API specific
*/
public class Dropbox {
// retrieve private credentials from Dropbox Developers app
static {
try {
FileReader readCred = new FileReader("dropbox.json");
JSONObject dropCred = new JSONObject(readCred);
final String key = dropCred.getString("key");
final String secret = dropCred.getString("secret");
final String token = dropCred.getString("token");
private String key;
private String secret;
private String token;

public Dropbox() {
readSetCredentials();
}
public Dropbox(String key, String secret) {
this.key = key;
this.secret = secret;
}
public Dropbox(String key, String secret, String token) {
this.key = key;
this.secret = secret;
this.token = token;
}

private void readSetCredentials() {
try {
URL url = getClass().getResource("/services/dropbox.json");
FileReader readCred = new FileReader(url.getPath());
JSONObject dropCred = new JSONObject(url.getPath());
key = dropCred.getString("key");
secret = dropCred.getString("secret");
token = dropCred.getString("token");
} catch (Exception e) {
e.printStackTrace();
}
}

public String getKey() {
return key;
}
public String getSecret() {
return secret;
}
public String getToken() {
return token;
}
public void setKey(String key) {
this.key = key;
}
public void setSecret(String secret) {
this.secret = secret;
}
public void setToken(String token) {
this.token = token;
}


}
29 changes: 29 additions & 0 deletions src/main/java/webapp/DropboxController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package webapp;

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.users.FullAccount;

/**
* This class controls the Dropbox application logic.
*/
public class DropboxController {
private static Dropbox dropbox;
private DbxClientV2 client;
private DbxRequestConfig config;

public DropboxController() {
initialize();
}

private void initialize() {
dropbox = new Dropbox(); // uses default json file credentials
config = new DbxRequestConfig("dropbox/IronGate", "en_US");
client = new DbxClientV2(config, dropbox.getToken());
}

public void test() throws DbxException{
FullAccount account = client.users.getCurrentAccount();
}
}
5 changes: 0 additions & 5 deletions src/main/java/webapp/dropbox.json

This file was deleted.

27 changes: 19 additions & 8 deletions src/main/resources/StartPage.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@

<!--suppress JavaFxDefaultTag, JavaFxDefaultTag, JavaFxDefaultTag, JavaFxDefaultTag, JavaFxDefaultTag, JavaFxDefaultTag -->

<?import javafx.scene.effect.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="directory.Controller">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="launcher.Controller">
<top>
<MenuBar id="menubar-pane" BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="fileDropboxSignin" mnemonicParsing="false" text="Sign in to Dropbox" />
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
Expand Down

0 comments on commit d09c959

Please sign in to comment.