pull/1/head
Ivan Olexyn 5 years ago
parent 87595d99a4
commit 0f7610dd52

@ -15,6 +15,7 @@ import javafx.stage.Window;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
@ -24,53 +25,113 @@ import java.util.ResourceBundle;
public class Controller implements Initializable {
final static int COLUMN_COUNT = 5; // How many columns should the GridPane have? Adjust if necessary.
final static Text SPACE = new Text(""); // Placeholder
int collection_count = 0;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
Text end = new Text("end");
end.setId("end");
Button newCollectionButton = new Button("New Collection");
newCollectionButton.setId("newCollectionButton");
newCollectionButton.setOnAction(event -> { this.newCollection();});
gridPane.add(end, 0, 0);
List<Node> nodeList = new ArrayList<>(gridPane.getChildren());
List<Node> payload = Arrays.asList(new Text(""), new Text(""), new Text(""), new Text(""), newCollectionButton);
insertPayload(nodeList, payload, "", 0);
redraw(gridPane, nodeList);
}
private void newCollection() {
String collectionName = "name" + collection_count++;
TextField collectionStateTextField = new TextField();
collectionStateTextField.setText("STATE");
collectionStateTextField.setStyle("-fx-text-fill: green");
collectionStateTextField.setDisable(true);
collectionStateTextField.setId("collectionStateTextField-" + collectionName);
Button removeCollectionButton = new Button("Remove Collection");
removeCollectionButton.setId("removeCollectionButton-" + collectionName);
removeCollectionButton.setOnAction(event -> { this.removeCollection(collectionName);});
TextField addDirectoryTextField = new TextField();
addDirectoryTextField.setId("addDirectoryTextField");
addDirectoryTextField.setId("addDirectoryTextField-" + collectionName);
Button addDirectoryButton = new Button("Add Directory");
addDirectoryButton.setId("addDirectoryButton");
addDirectoryButton.setOnAction(event -> { this.addDirectory();});
addDirectoryButton.setId("addDirectoryButton-" + collectionName);
addDirectoryButton.setOnAction(event -> { this.addDirectory(collectionName);});
gridPane.add(addDirectoryTextField, 0, 0);
gridPane.add(new Text(""), 1, 0);
gridPane.add(new Text(""), 2, 0);
gridPane.add(new Text(""), 3, 0);
gridPane.add(addDirectoryButton, 4, 0);
List<Node> nodeList = new ArrayList<>(gridPane.getChildren());
List<Node> payload = new ArrayList<>();
payload.addAll(Arrays.asList(new Text(""), new Text(""), collectionStateTextField, new Text(""), removeCollectionButton));
payload.addAll(Arrays.asList(addDirectoryTextField, new Text(""), new Text(""), new Text(""), addDirectoryButton));
insertPayload(nodeList, payload, "newCollectionButton", -4);
redraw(gridPane, nodeList);
}
private void newCollection(){
/*
TODO copy old init here, redraw.
*/
@FXML
protected GridPane gridPane;
private void removeCollection(String collectionName) {
List<Node> nodeList = new ArrayList<>(gridPane.getChildren());
here : for (Node node : nodeList) {
if (node.getId() != null && node.getId().equals("removeCollectionButton-" + collectionName)) {
int i = nodeList.indexOf(node) - 4;
while (i<nodeList.size()) {
nodeList.remove(i);
if (nodeList.get(i).getId() != null && nodeList.get(i).getId().equals("addDirectoryButton-" + collectionName)){
nodeList.remove(i);
break here;
}
}
}
}
redraw(gridPane,nodeList);
}
@FXML
protected GridPane gridPane;
private List<Node> fillBlanks() {
List<Node> out = new ArrayList<>();
return out;
}
/**
*
*/
private void addDirectory() {
private void addDirectory(String collectionName) {
// TODO throw error if other collection already contains absollutepath
Window stage = gridPane.getScene().getWindow();
final DirectoryChooser directoryChooser = new DirectoryChooser();
@ -83,14 +144,16 @@ public class Controller implements Initializable {
TextField directoryPathTextField = new TextField();
directoryPathTextField.setText(dir.getAbsolutePath());
directoryPathTextField.setDisable(true);
directoryPathTextField.setId("directoryPathTextField-" + dir.getAbsolutePath());
// TODO for now there is only one SyncMap "test".
Main.SYNC.get("test").addDirectory(dir.getAbsolutePath());
// Main.SYNC.get("test").addDirectory(dir.getAbsolutePath());
TextField directoryStateTextField = new TextField();
directoryStateTextField.setText("STATE");
directoryStateTextField.setStyle("-fx-text-fill: green");
directoryStateTextField.setDisable(true);
directoryStateTextField.setId("directoryStateTextField-" + dir.getAbsolutePath());
Button removeDirectoryButton = new Button("Remove");
removeDirectoryButton.setId("removeDirectoryButton-" + dir.getAbsolutePath());
@ -98,53 +161,52 @@ public class Controller implements Initializable {
List<Node> nodeList = new ArrayList<>(gridPane.getChildren());
insertRow(nodeList, directoryPathTextField, directoryStateTextField, removeDirectoryButton);
List<Node> payload = Arrays.asList(directoryPathTextField, new Text(""), directoryStateTextField, new Text(""), removeDirectoryButton);
insertPayload(nodeList, payload, "addDirectoryTextField-" + collectionName, 0);
redraw(gridPane, nodeList);
}
}
/**
* Find the addDirectoryTextField.
* Insert the cells of the new row starting from the last cell.
* This pushes the addDirectoryTextField forward.
* Find the Node with @param id.
* Insert the contents of the @param payload starting from the last.
* This pushes the Node with @param id forward.
*/
private void insertRow(List<Node> nodeList, TextField path , TextField state, Button button){
private void insertPayload(List<Node> nodeList, List<Node> payload, String id, int offset) {
for (Node node : nodeList) {
if (node.getId() != null && node.getId().equals("addDirectoryTextField")) {
int i = nodeList.indexOf(node);
if (node.getId() != null && node.getId().equals(id)) {
int i = nodeList.indexOf(node) + offset;
nodeList.add(i, button);
nodeList.add(i, new Text(""));
nodeList.add(i, state);
nodeList.add(i, new Text(""));
nodeList.add(i, path);
for (int j = payload.size() - 1; j >= 0; j--) {
nodeList.add(i, payload.get(j));
}
break;
}
}
}
/**
* Clear the gridPane and redraw it with contents of nodeList.
*/
private void redraw(GridPane gridPane, List<Node> nodeList){
private void redraw(GridPane gridPane, List<Node> nodeList) {
gridPane.getChildren().clear();
int col = 0;
int row = 0;
for (Node node : nodeList) {
gridPane.add(node, col, row);
col++;
if (nodeList.indexOf(node) % 5 == 4) {
if ((nodeList.indexOf(node) + 0) % COLUMN_COUNT == 0) {
row++;
col = 0;
}
gridPane.add(node, col, row);
col++;
}
}
@ -160,7 +222,7 @@ public class Controller implements Initializable {
for (Node node : nodeList) {
if (node.getId() != null && node.getId().equals(id)) {
int i = nodeList.indexOf(node) - 5;
int i = nodeList.indexOf(node) - 4;
for (int j = 0; j < 5; j++) {
nodeList.remove(i);
}
@ -168,29 +230,15 @@ public class Controller implements Initializable {
}
}
gridPane.getChildren().clear();
int col = 0;
int row = 0;
for (Node node : nodeList) {
gridPane.add(node, col, row);
col++;
if (nodeList.indexOf(node) % 5 == 4) {
row++;
col = 0;
}
}
redraw(gridPane,nodeList);
/*
String path = id.replace("removeButton", "");
while(true){
if (Main.flowThread.getState().equals(Thread.State.TIMED_WAITING)){
while (true) {
if (Main.flowThread.getState().equals(Thread.State.TIMED_WAITING)) {
try {
Main.flowThread.wait();
} catch (InterruptedException e){
} catch (InterruptedException e) {
Main.SYNC.get("test").removeDirectory(path);
Main.flowThread.notify();
break;
@ -198,8 +246,22 @@ public class Controller implements Initializable {
}
}
*/
}
}
class Placeholder extends Text{
static int count =0;
Placeholder(String label, String name){
super(label);
this.setId("placeholder-"+name+"-"+count++);
}
}

Loading…
Cancel
Save