Skip to content

Instantly share code, notes, and snippets.

@MakerTim
Created November 2, 2016 23:52
Show Gist options
  • Save MakerTim/f9fa39608a23d195d6105ca8039bfb71 to your computer and use it in GitHub Desktop.
Save MakerTim/f9fa39608a23d195d6105ca8039bfb71 to your computer and use it in GitHub Desktop.
package nl.group7.narwall.view.agenda;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Optional;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import jfxtras.scene.control.CalendarTimePicker;
import nl.group7.narwall.controller.AgendaController;
import nl.group7.narwall.database.key.UUIDKey;
import nl.group7.narwall.util.element.AlignmentPane;
import nl.group7.narwall.util.element.NarwallButton;
import nl.group7.narwall.util.element.NarwallLabel;
import nl.group7.narwall.util.element.NarwallTextArea;
import nl.group7.narwall.view.BaseView;
import nl.group7.narwall.view.View;
import nl.group7.narwall.view.elements.AddressElement;
import nl.group7.narwall.view.elements.AppointmentPersonElement;
/**
* @author Tim Biesenbeek
*/
public class AppointmentView extends GridPane {
private AgendaController controller;
private LocalDateTime startTime;
private LocalDateTime endTime;
private Optional<UUIDKey> existingKey;
protected TextArea aboutText;
protected DatePicker datePicker;
protected CalendarTimePicker timeSPicker;
protected CalendarTimePicker timeEPicker;
protected AddressElement addressElement;
protected AppointmentPersonElement personElement;
protected AlignmentPane buttonRow;
protected AppointmentView(LocalDateTime startTime, LocalDateTime endTime, UUIDKey existingKey) {
this.existingKey = Optional.ofNullable(existingKey);
this.startTime = startTime;
this.endTime = endTime;
setup();
setPadding(new Insets(5, 10, 20, 10));
}
private void setup() {
setPrefWidth(Short.MAX_VALUE);
setHgap(6);
Label header = new NarwallLabel(existingKey.isPresent() ? "Bewerken afspraak" : "Nieuwe afspraak");
header.setFont(new Font(BaseView.FONT.getName(), 20));
Label aboutLabel = new NarwallLabel("Beschrijving");
aboutLabel.setMinWidth(100);
aboutText = new NarwallTextArea();
aboutText.setPrefHeight(50);
aboutText.setPromptText("bijv.: Afspraak met meneer Biesenbeek.");
aboutText.setPrefWidth(Short.MAX_VALUE);
Label dayLabel = new NarwallLabel("Dag");
datePicker = new DatePicker(startTime.toLocalDate());
datePicker.getStyleClass().add("ubuntu");
datePicker.setShowWeekNumbers(true);
datePicker.setPrefWidth(Short.MAX_VALUE);
Label timeSLabel = new NarwallLabel("Start tijd");
timeSPicker = new CalendarTimePicker();
// timeSPicker.setHourStep(1);
timeSPicker.setMinuteStep(1);
timeSPicker.setSecondStep(1);
timeSPicker.setPadding(new Insets(5));
Calendar calendarS = Calendar.getInstance();
calendarS.set(0, 0, 0, startTime.getHour(), startTime.getMinute(), startTime.getSecond());
timeSPicker.setCalendar(calendarS);
Label timeELabel = new NarwallLabel("Eind tijd");
timeEPicker = new CalendarTimePicker();
// timeEPicker.setHourStep(1);
timeEPicker.setMinuteStep(1);
timeEPicker.setSecondStep(1);
timeEPicker.setPadding(new Insets(5));
Calendar calendarE = Calendar.getInstance();
calendarE.set(0, 0, 0, endTime.getHour(), endTime.getMinute(), endTime.getSecond());
timeEPicker.setCalendar(calendarE);
timeSPicker.setValueValidationCallback(
newValue -> newValue.getTime().getTime() < timeEPicker.getCalendar().getTime().getTime());
timeEPicker.setValueValidationCallback(
newValue -> newValue.getTime().getTime() >= timeSPicker.getCalendar().getTime().getTime());
addressElement = new AddressElement();
Button saveButton = new NarwallButton("Opslaan");
saveButton.setOnAction(click -> {
if (existingKey.isPresent()) {
controller.updateAppointment(existingKey.get(), datePicker.getValue(),
timeSPicker.getCalendar().getTime(), timeEPicker.getCalendar().getTime(), aboutText.getText(),
addressElement.getAddress());
} else {
controller.newAppointment(datePicker.getValue(), timeSPicker.getCalendar().getTime(),
timeEPicker.getCalendar().getTime(), aboutText.getText(), addressElement.getAddress(),
getPersonElement().getPersons());
}
});
Button cancelButton = new NarwallButton("Annuleren");
cancelButton.setOnAction(click -> controller.getView().closeNewAppointment());
buttonRow = new AlignmentPane(Pos.CENTER_RIGHT, 6, cancelButton, saveButton);
add(header, 0, 0, 2, 1);
add(aboutLabel, 0, 1);
add(aboutText, 1, 1);
add(dayLabel, 0, 2);
add(datePicker, 1, 2);
add(timeSLabel, 0, 3);
add(timeSPicker, 1, 3);
add(timeELabel, 0, 4);
add(timeEPicker, 1, 4);
add(addressElement, 0, 5, 2, 1);
add(buttonRow, 0, 7, 2, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment