Skip to content
Snippets Groups Projects
Commit ee53cdf9 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Delete action in UI

parent b5751e85
Branches
No related merge requests found
...@@ -4,6 +4,7 @@ import java.util.Collection; ...@@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import javafx.application.Application; import javafx.application.Application;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
...@@ -13,6 +14,7 @@ import javafx.scene.Group; ...@@ -13,6 +14,7 @@ import javafx.scene.Group;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent; import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
...@@ -50,8 +52,8 @@ public class TableViewSample extends Application { ...@@ -50,8 +52,8 @@ public class TableViewSample extends Application {
@Override @Override
public void start(Stage stage) { public void start(Stage stage) {
Scene scene = new Scene(new Group()); Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample"); stage.setTitle("RESTfull Webservice - Course Book");
stage.setWidth(450); stage.setWidth(500);
stage.setHeight(550); stage.setHeight(550);
final Label label = new Label("Course Book"); final Label label = new Label("Course Book");
...@@ -68,8 +70,30 @@ public class TableViewSample extends Application { ...@@ -68,8 +70,30 @@ public class TableViewSample extends Application {
"credits", this::handleOnEditCommitCredits); "credits", this::handleOnEditCommitCredits);
TableColumn<Course, String> semesterCol = constructColumn("Semester", TableColumn<Course, String> semesterCol = constructColumn("Semester",
"semester", this::handleOnEditCommitSemester); "semester", this::handleOnEditCommitSemester);
TableColumn<Course, Course> actionCol = new TableColumn<>("");
actionCol.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(
param.getValue()));
actionCol.setCellFactory(param -> new TableCell<>() {
private final Button deleteButton = new Button("Delete");
@Override
protected void updateItem(Course course, boolean empty) {
super.updateItem(course, empty);
if (course == null) {
setGraphic(null);
return;
}
setGraphic(deleteButton);
deleteButton.setOnAction(event -> handleOnDelete(event, course));
}
});
table.getColumns().addAll(nameCol, desriptionCol, creditsCol, table.getColumns().addAll(nameCol, desriptionCol, creditsCol,
semesterCol); semesterCol, actionCol);
addName = constructTextField(nameCol, "Name"); addName = constructTextField(nameCol, "Name");
...@@ -115,7 +139,7 @@ public class TableViewSample extends Application { ...@@ -115,7 +139,7 @@ public class TableViewSample extends Application {
return col; return col;
} }
private void handleOnAdd(ActionEvent e) { private void handleOnAdd(@SuppressWarnings("unused") ActionEvent e) {
Course p = new Course(); Course p = new Course();
p.setName(addName.getText()); p.setName(addName.getText());
p.setDescription(addDescription.getText()); p.setDescription(addDescription.getText());
...@@ -129,6 +153,13 @@ public class TableViewSample extends Application { ...@@ -129,6 +153,13 @@ public class TableViewSample extends Application {
addSemester.clear(); addSemester.clear();
} }
private void handleOnDelete(@SuppressWarnings("unused") ActionEvent event,
Course course)
{
data.remove(course);
removeCourse(course);
}
private void handleOnEditCommitName(CellEditEvent<Course, String> t) { private void handleOnEditCommitName(CellEditEvent<Course, String> t) {
Course p = t.getTableView().getItems().get(t.getTablePosition().getRow()); Course p = t.getTableView().getItems().get(t.getTablePosition().getRow());
p.setName(t.getNewValue()); p.setName(t.getNewValue());
...@@ -162,13 +193,15 @@ public class TableViewSample extends Application { ...@@ -162,13 +193,15 @@ public class TableViewSample extends Application {
return Collections.emptyList(); return Collections.emptyList();
} }
private void createCourse(Course p) { private void createCourse(Course course) {
// TODO Auto-generated method stub // TODO
} }
private void updateCourse(Course p) { private void updateCourse(Course course) {
// TODO Auto-generated method stub // TODO
}
private void removeCourse(Course course) {
// TODO
} }
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment