Repository navigation
Expand file tree
/
Copy patheditController.java
More file actions
194 lines (157 loc) · 4.58 KB
/
Copy patheditController.java
File metadata and controls
194 lines (157 loc) · 4.58 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package application;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
public class editController implements Initializable{
//DB here
TaskManager tm = new TaskManager("tm");
int index = -1;
@FXML
private TableView<Habit> table;
@FXML
private TableColumn<Habit, String> habitColumn;
@FXML
private TableColumn<Habit, String> daysColumn;
public void initialize(URL url, ResourceBundle rb) {
//set columns
habitColumn.setCellValueFactory(new PropertyValueFactory<Habit, String>("habit"));
daysColumn.setCellValueFactory(new PropertyValueFactory<Habit, String>("goal"));
//load dummy data
table.setItems(getHabits());
}
public ObservableList<Habit> getHabits()
{
ObservableList<Habit> result = FXCollections.observableArrayList(tm.getHabits());
return result;
}
@FXML
private TextField habitE;
@FXML
//if a habit is clicked, it will retrieve the data associated with it
void getSelected(MouseEvent event) {
clear();
Habit select = table.getSelectionModel().selectedItemProperty().get();
if(select == null) return;
if(select.getDays()[0] == true) {
sunE.setSelected(true);
}
if(select.getDays()[1] == true) {
monE.setSelected(true);
}
if(select.getDays()[2] == true) {
tueE.setSelected(true);
}
if(select.getDays()[3] == true) {
wedE.setSelected(true);
}
if(select.getDays()[4] == true) {
thuE.setSelected(true);
}
if(select.getDays()[5] == true) {
friE.setSelected(true);
}
if(select.getDays()[6] == true) {
satE.setSelected(true);
}
index = table.getSelectionModel().getSelectedIndex();
if(index <= -1) {
return;
}
else {
habitE.setText(habitColumn.getCellData(index).toString());
}
}
@FXML
private CheckBox sunE;
@FXML
private CheckBox monE;
@FXML
private CheckBox tueE;
@FXML
private CheckBox wedE;
@FXML
private CheckBox thuE;
@FXML
private CheckBox friE;
@FXML
private CheckBox satE;
@FXML
void sendToEdit(ActionEvent event) {
String getHabit = habitE.getText();
boolean [] week = new boolean [7];
int count = 0;
if(sunE.isSelected()) {
week[0] = true;
count++;
}
if(monE.isSelected()) {
week[1] = true;
count++;
}
if(tueE.isSelected()) {
week[2] = true;
count++;
}
if(wedE.isSelected()) {
week[3] = true;
count++;
}
if(thuE.isSelected()) {
week[4] = true;
count++;
}
if(friE.isSelected()) {
week[5] = true;
count++;
}
if(satE.isSelected()){
week[6] = true;
count++;
}
//if no days are selected
if(count == 0) {
infoBox1("Please choose at least one day", "Alert");
}
//***edit habit in DB
Habit allocate = table.getSelectionModel().selectedItemProperty().get();
tm.updateHabit(allocate, getHabit);
tm.updateDays(allocate, week);
tm.updateGoal(allocate, count);
}
public static void infoBox1(String infoMessage, String titleBar)
{
infoBox2(infoMessage, titleBar, null);
}
public static void infoBox2(String infoMessage, String titleBar, String headerMessage)
{
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(titleBar);
alert.setHeaderText(headerMessage);
alert.setContentText(infoMessage);
alert.showAndWait();
}
private void clear() {
//clears text-fields
habitE.clear();
//clears check-boxes
sunE.setSelected(false);
monE.setSelected(false);
tueE.setSelected(false);
wedE.setSelected(false);
thuE.setSelected(false);
friE.setSelected(false);
satE.setSelected(false);
}
}