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.io.File;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -24,53 +25,113 @@ import java.util.ResourceBundle;
public class Controller implements Initializable { 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 @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
Text end = new Text("end");
end.setId("end");
Button newCollectionButton = new Button("New Collection"); Button newCollectionButton = new Button("New Collection");
newCollectionButton.setId("newCollectionButton"); newCollectionButton.setId("newCollectionButton");
newCollectionButton.setOnAction(event -> { this.newCollection();}); 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(); TextField addDirectoryTextField = new TextField();
addDirectoryTextField.setId("addDirectoryTextField"); addDirectoryTextField.setId("addDirectoryTextField-" + collectionName);
Button addDirectoryButton = new Button("Add Directory"); Button addDirectoryButton = new Button("Add Directory");
addDirectoryButton.setId("addDirectoryButton"); addDirectoryButton.setId("addDirectoryButton-" + collectionName);
addDirectoryButton.setOnAction(event -> { this.addDirectory();}); 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(){ @FXML
/* protected GridPane gridPane;
TODO copy old init here, redraw.
*/ 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(); Window stage = gridPane.getScene().getWindow();
final DirectoryChooser directoryChooser = new DirectoryChooser(); final DirectoryChooser directoryChooser = new DirectoryChooser();
@ -83,14 +144,16 @@ public class Controller implements Initializable {
TextField directoryPathTextField = new TextField(); TextField directoryPathTextField = new TextField();
directoryPathTextField.setText(dir.getAbsolutePath()); directoryPathTextField.setText(dir.getAbsolutePath());
directoryPathTextField.setDisable(true); directoryPathTextField.setDisable(true);
directoryPathTextField.setId("directoryPathTextField-" + dir.getAbsolutePath());
// TODO for now there is only one SyncMap "test". // 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(); TextField directoryStateTextField = new TextField();
directoryStateTextField.setText("STATE"); directoryStateTextField.setText("STATE");
directoryStateTextField.setStyle("-fx-text-fill: green"); directoryStateTextField.setStyle("-fx-text-fill: green");
directoryStateTextField.setDisable(true); directoryStateTextField.setDisable(true);
directoryStateTextField.setId("directoryStateTextField-" + dir.getAbsolutePath());
Button removeDirectoryButton = new Button("Remove"); Button removeDirectoryButton = new Button("Remove");
removeDirectoryButton.setId("removeDirectoryButton-" + dir.getAbsolutePath()); removeDirectoryButton.setId("removeDirectoryButton-" + dir.getAbsolutePath());
@ -98,53 +161,52 @@ public class Controller implements Initializable {
List<Node> nodeList = new ArrayList<>(gridPane.getChildren()); 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); redraw(gridPane, nodeList);
} }
} }
/** /**
* Find the addDirectoryTextField. * Find the Node with @param id.
* Insert the cells of the new row starting from the last cell. * Insert the contents of the @param payload starting from the last.
* This pushes the addDirectoryTextField forward. * 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) { for (Node node : nodeList) {
if (node.getId() != null && node.getId().equals("addDirectoryTextField")) { if (node.getId() != null && node.getId().equals(id)) {
int i = nodeList.indexOf(node); int i = nodeList.indexOf(node) + offset;
nodeList.add(i, button); for (int j = payload.size() - 1; j >= 0; j--) {
nodeList.add(i, new Text("")); nodeList.add(i, payload.get(j));
nodeList.add(i, state); }
nodeList.add(i, new Text(""));
nodeList.add(i, path);
break; break;
} }
} }
} }
/** /**
* Clear the gridPane and redraw it with contents of nodeList. * 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(); gridPane.getChildren().clear();
int col = 0; int col = 0;
int row = 0; int row = 0;
for (Node node : nodeList) { for (Node node : nodeList) {
if ((nodeList.indexOf(node) + 0) % COLUMN_COUNT == 0) {
gridPane.add(node, col, row);
col++;
if (nodeList.indexOf(node) % 5 == 4) {
row++; row++;
col = 0; col = 0;
} }
gridPane.add(node, col, row);
col++;
} }
} }
@ -160,7 +222,7 @@ public class Controller implements Initializable {
for (Node node : nodeList) { for (Node node : nodeList) {
if (node.getId() != null && node.getId().equals(id)) { 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++) { for (int j = 0; j < 5; j++) {
nodeList.remove(i); nodeList.remove(i);
} }
@ -168,29 +230,15 @@ public class Controller implements Initializable {
} }
} }
gridPane.getChildren().clear(); redraw(gridPane,nodeList);
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;
}
}
/*
String path = id.replace("removeButton", ""); String path = id.replace("removeButton", "");
while(true){ while (true) {
if (Main.flowThread.getState().equals(Thread.State.TIMED_WAITING)){ if (Main.flowThread.getState().equals(Thread.State.TIMED_WAITING)) {
try { try {
Main.flowThread.wait(); Main.flowThread.wait();
} catch (InterruptedException e){ } catch (InterruptedException e) {
Main.SYNC.get("test").removeDirectory(path); Main.SYNC.get("test").removeDirectory(path);
Main.flowThread.notify(); Main.flowThread.notify();
break; 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