Skip to content

Commit

Permalink
Fixes #326 - Show the list of jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Jul 28, 2024
1 parent 99e0497 commit 739e8c1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dependency-reduced-pom.xml
nbactions.xml
nbproject/
target/
*.iml
19 changes: 0 additions & 19 deletions desktop/nb-configuration.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class DesktopApplication extends Application {

@Override
public void start(Stage stage) throws IOException {
Scene scene = new Scene(new AutomationListWindow(), 640, 480);
Scene scene = new Scene(new JobListWindow(), 640, 480);
stage.setScene(scene);
stage.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
package com.manorrock.sphynx.desktop;

/**
* An automation.
* A job.
*
* @author Manfred Riem (mriem@manorrock.com)
*/
public class Automation {
public class Job {

/**
* Stores the id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
*/
package com.manorrock.sphynx.desktop;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
Expand All @@ -37,74 +39,86 @@
import javafx.scene.layout.BorderPane;

/**
* The Automations Window.
*
* The "Job List" Window.
*
* @author Manfred Riem (mriem@manorrock.com)
*/
public class AutomationListWindow extends BorderPane {

public class JobListWindow extends BorderPane {

/**
* Stores the base directory.
*/
protected File baseDirectory = new File(System.getProperty("user.home") + "/.manorrock/sphynx");

/**
* Stores the automation TableView.
* Stores the jobs TableView.
*/
@FXML
private TableView automationTableView;
private TableView jobsTableView;

/**
* Constructor.
*/
public AutomationListWindow() {
public JobListWindow() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setRoot(this);
loader.setController(this);
loader.load(getClass().getResourceAsStream(
"/com/manorrock/sphynx/desktop/AutomationListWindow.fxml"));
"/com/manorrock/sphynx/desktop/JobListWindow.fxml"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}

/**
* Initialize the component.
*/
@FXML
public void initialize() {
TableColumn idTableColumn = new TableColumn("Id");
idTableColumn.setCellValueFactory(
new PropertyValueFactory<Automation, Long>("id")
);
automationTableView.getColumns().add(idTableColumn);
TableColumn nameTableColumn = new TableColumn("Name");
nameTableColumn.setCellValueFactory(
new PropertyValueFactory<Automation, String>("name")
new PropertyValueFactory<Job, String>("name")
);
automationTableView.getColumns().add(nameTableColumn);
jobsTableView.getColumns().add(nameTableColumn);

File jobsDirectory = new File(baseDirectory, "jobs");
if (jobsDirectory.exists()) {
ArrayList<Job> list = new ArrayList<>();
String[] names = jobsDirectory.list();
for (String name : names) {
Job job = new Job();
job.setName(name);
list.add(job);
}
jobsTableView.getItems().addAll(list);
}
}

/**
* Handle 'Add' button click.
*
*
* @param event the event.
*/
@FXML
public void onAdd(ActionEvent event) {
Automation automation = new Automation();
Job automation = new Job();
automation.setId(System.currentTimeMillis());
automation.setName("Untitled - " + System.currentTimeMillis());
automationTableView.getItems().add(automation);
jobsTableView.getItems().add(automation);
}

/**
* Handle 'Delete' button click.
*
*
* @param event the event.
*/
@FXML
public void onDelete(ActionEvent event) {
if (!automationTableView.getSelectionModel().isEmpty()) {
Automation automation = (Automation) automationTableView
if (!jobsTableView.getSelectionModel().isEmpty()) {
Job automation = (Job) jobsTableView
.getSelectionModel().getSelectedItem();
automationTableView.getItems().remove(automation);
jobsTableView.getItems().remove(automation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</ButtonBar>
</top>
<center>
<TableView fx:id="automationTableView" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
<TableView fx:id="jobsTableView" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</center>
</fx:root>

0 comments on commit 739e8c1

Please sign in to comment.