-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputDeleteRow.java
More file actions
87 lines (74 loc) · 2.76 KB
/
InputDeleteRow.java
File metadata and controls
87 lines (74 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.geometry.*;
import java.lang.*;
import javafx.scene.control.Button;
import javafx.event.*;
import java.util.*;
class InputDeleteRow {
public static void display(Table table) {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Delete Rows");
window.setMinWidth(250);
VBox layout = new VBox(10);
Label instruction = new Label("Type in records' numbers to delete:" + "\n" +
"(Use , to seperate multiple rows)");
TextField input = new TextField();
input.setPrefWidth(100);
HBox bottomLayout = new HBox(20);
Button confirm = new Button("Confirm");
Button cancel = new Button("Cancel");
confirm.setOnAction(e -> {
String rowinfo = input.getText();
String[] toDelete = rowinfo.split(",");
int total = toDelete.length;
int[] number = new int[total];
// System.out.println(table.getRecords().getRecordsNumber());
for (int i = 0; i < total; i++) {
if (isInteger(toDelete[i])){
number[i] = Integer.parseInt(toDelete[i]);
}
else {
AlertBox.display("Error", "Please type in interger.");
window.close();
}
}
if (!table.deleteRow(sortIntArray(number))) {
AlertBox.display("Error", "Please type in valid row numbers.");
window.close();
}
// table.printTable();
window.close();
});
// System.out.println(table.getRecords().getRecordsNumber());
cancel.setOnAction(e -> window.close());
bottomLayout.getChildren().addAll(confirm, cancel);
bottomLayout.setPadding(new Insets(20,0,0,0));
layout.getChildren().addAll(instruction, input, bottomLayout);
layout.setPadding(new Insets(30,20,30,20));
Scene scene = new Scene(layout, 300, 200);
window.setScene(scene);
window.showAndWait();
}
static boolean isInteger(String s) {
if(s.isEmpty()) return false;
for (int i = 0; i < s.length(); i++) {
if(Character.digit(s.charAt(i),10) < 0)
return false;
}
return true;
}
static int[] sortIntArray(int... number) {
int length = number.length;
int[] sorted = new int[length];
Arrays.sort(number);
for (int i = length - 1; i >=0; i--) {
sorted[length - i - 1] = number[i];
// System.out.println(number[i]);
}
return sorted;
}
}