Skip to content

Commit

Permalink
Added import data facility
Browse files Browse the repository at this point in the history
  • Loading branch information
Guleri24 committed Mar 13, 2022
1 parent fd44871 commit a5fb256
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 34 deletions.
93 changes: 61 additions & 32 deletions src/main/java/com/horizonxe/MainController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.horizonxe;

import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
Expand All @@ -11,45 +12,58 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class MainController {
private static BufferedWriter writer;
private final List<String> projects = new ArrayList<>();
private final List<String> modules = new ArrayList<>();
@FXML
public Button triggerCmd;
@FXML
public ComboBox<String> projectMenu;
@FXML
public ComboBox<String> moduleMenu;
public AnchorPane mainView;
private File file;
private final List<String> projects = new ArrayList<>();
private final List<String> modules = new ArrayList<>();
private File executableFile;
private File dataFile;
private boolean isWindows;

public void initialize() throws IOException, InterruptedException {
file = newFile();
file.getParentFile().mkdir();
file.createNewFile();
file.setExecutable(true);
writer = Files.newBufferedWriter(Paths.get(String.valueOf(file)));
newFile("exec");
writer = Files.newBufferedWriter(Paths.get(String.valueOf(executableFile)));
writer.write("");
writer.flush();
initData();
projectMenu.getItems().addAll(projects);
projectMenu.setValue(""); // empty selection is object and not null
moduleMenu.getItems().addAll(modules);
}

private File newFile() throws IOException, InterruptedException {
private void newFile(String type) throws IOException {
isWindows = System.getProperty("os.name")
.toLowerCase().startsWith("windows");
String username = System.getProperty("user.name");

if (isWindows) {
return new File("C:\\Users\\" + username + "\\FisGlobal\\data.bat");
} else {
return file = new File("/home/" + username + "/FisGlobal/data.sh");
String windowsPath = "C:\\Users\\" + username + "\\FisGlobal\\";
String linuxPath = "/home/" + username + "/FisGlobal/";
switch (type) {
case "exec" -> {
if (isWindows) {
executableFile = new File(windowsPath + "exec.bat");
} else {
executableFile = new File(linuxPath + "exec.sh");
}
executableFile.getParentFile().mkdir();
executableFile.createNewFile();
executableFile.setExecutable(true);
}
case "data" -> {
if (isWindows) {
dataFile = new File(windowsPath + "data.csv");
} else {
dataFile = new File(linuxPath + "data.csv");
}

dataFile.getParentFile().mkdir();
dataFile.createNewFile();
dataFile.setExecutable(true);
}
}
}

Expand All @@ -63,26 +77,27 @@ public void writeData() {
} catch (IOException e) {
e.printStackTrace();
}

}

private void writeData(BufferedWriter writer, String project, String module) throws IOException {
writer.append("mvn -DProj ").append(project).append(" -DMod ").append(module);
}

// Enter the projects and modules here
private void initData() {
projects.add("France");
projects.add("Germany");
projects.add("Switzerland");

modules.add("Paris");
modules.add("Strasbourg");
modules.add("Berlin");
modules.add("Cologne");
modules.add("Munich");
modules.add("Zurich");
private void initData() throws IOException {
newFile("data");
String row;
BufferedReader csvReader = new BufferedReader(new FileReader(dataFile));
while ((row = csvReader.readLine()) != null) {

String[] data = row.split(",");
projects.add(data[0]);
modules.add(data[1]);
}
csvReader.close();

projectMenu.setItems(FXCollections.observableArrayList(projects));
moduleMenu.setItems(FXCollections.observableArrayList(modules));
}

@FXML
Expand All @@ -92,16 +107,30 @@ public void triggerCmd() throws IOException {
writer.close();

if (isWindows) {
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"" + file.getAbsolutePath() + "\"");
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"" + executableFile.getAbsolutePath() + "\"");
stage.close();
} else {
stage.close();
/*
Runtime.getRuntime().exec(System.getenv("TERM") + " -e bash -c " + file.getAbsolutePath() + ";read");
*/
Runtime.getRuntime().exec("alacritty" + " -e bash -c " + file.getAbsolutePath() + ";read");
Runtime.getRuntime().exec("alacritty" + " -e bash -c " + executableFile.getAbsolutePath() + ";read");
}
}

@FXML
public void addData() throws IOException {
Stage stage = (Stage) mainView.getScene().getWindow();
if (isWindows) {
Runtime.getRuntime().exec("cmd /c start excel /K \"" + dataFile.getAbsolutePath() + "\"");
stage.close();
} else {
stage.close();
/*
Runtime.getRuntime().exec(System.getenv("TERM") + " -e bash -c " + file.getAbsolutePath() + ";read");
*/
Runtime.getRuntime().exec("gio " + " open " + dataFile.getAbsolutePath());
}
}
}

4 changes: 2 additions & 2 deletions src/main/resources/com.horizonxe/fis-form.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<Font name="System Bold" size="13.0" />
</font>
</Button>
<Button layoutX="421.0" layoutY="132.0" mnemonicParsing="false" prefHeight="24.0" prefWidth="14.0" style="-fx-background-color: #4bcd3e;" stylesheets="@styles.css" text="+" />
<Button layoutX="421.0" layoutY="192.0" mnemonicParsing="false" prefHeight="24.0" prefWidth="14.0" style="-fx-background-color: #4bcd3e;" stylesheets="@styles.css" text="+" />
<Button layoutX="26.0" layoutY="14.0" mnemonicParsing="false" onAction="#addData" prefHeight="24.0" prefWidth="84.0" style="-fx-background-color: #4bcd3e; -fx-background-radius: 70;" stylesheets="@styles.css" text="Add Data" />
<Button layoutX="120.0" layoutY="14.0" mnemonicParsing="false" prefHeight="24.0" prefWidth="65.0" style="-fx-background-color: #4bcd3e; -fx-background-radius: 70;" stylesheets="@styles.css" text="Help" />
</Pane>
</center>
</BorderPane>
Expand Down

0 comments on commit a5fb256

Please sign in to comment.