lBorderPane.setCenter(lMenuVBox);
// time
lMenuVBox.getChildren().add(new Text("Time:"));
// start
final CalendarTextField lStartCalendarTextField = new CalendarTextField().withDateFormat(SimpleDateFormat.getDateTimeInstance());
lStartCalendarTextField.setLocale(getSkinnable().getLocale());
lStartCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getStartTime());
lMenuVBox.getChildren().add(lStartCalendarTextField);
// end
final CalendarTextField lEndCalendarTextField = new CalendarTextField().withDateFormat(SimpleDateFormat.getDateTimeInstance());
lEndCalendarTextField.setLocale(getSkinnable().getLocale());
lEndCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getEndTime());
lMenuVBox.getChildren().add(lEndCalendarTextField);
lEndCalendarTextField.calendarProperty().addListener(new ChangeListener<Calendar>()
{
@Override
public void changed(ObservableValue<? extends Calendar> arg0, Calendar oldValue, Calendar newValue)
{
abstractAppointmentPane.appointment.setEndTime(newValue);
// refresh is done upon popup close
}
});
lEndCalendarTextField.setVisible(abstractAppointmentPane.appointment.getEndTime() != null);
// wholeday
if ((abstractAppointmentPane.appointment.isWholeDay() != null && abstractAppointmentPane.appointment.isWholeDay() == true) || abstractAppointmentPane.appointment.getEndTime() != null)
{
final CheckBox lWholedayCheckBox = new CheckBox("Wholeday");
lWholedayCheckBox.setId("wholeday-checkbox");
lWholedayCheckBox.selectedProperty().set(abstractAppointmentPane.appointment.isWholeDay());
lMenuVBox.getChildren().add(lWholedayCheckBox);
lWholedayCheckBox.selectedProperty().addListener(new ChangeListener<Boolean>()
{
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldValue, Boolean newValue)
{
abstractAppointmentPane.appointment.setWholeDay(newValue);
if (newValue == true)
{
abstractAppointmentPane.appointment.setEndTime(null);
}
else
{
Calendar lEndTime = (Calendar)abstractAppointmentPane.appointment.getStartTime().clone();
lEndTime.add(Calendar.MINUTE, 30);
abstractAppointmentPane.appointment.setEndTime(lEndTime);
lEndCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getEndTime());
}
lEndCalendarTextField.setVisible(abstractAppointmentPane.appointment.getEndTime() != null);
// refresh is done upon popup close
}
});
}
// event handling
lStartCalendarTextField.calendarProperty().addListener(new ChangeListener<Calendar>()
{
@Override
public void changed(ObservableValue<? extends Calendar> arg0, Calendar oldValue, Calendar newValue)
{
// enddate
if (abstractAppointmentPane.appointment.isWholeDay())
{
abstractAppointmentPane.appointment.setStartTime(newValue);
}
else
{
// remember
Calendar lOldStart = abstractAppointmentPane.appointment.getStartTime();
// set
abstractAppointmentPane.appointment.setStartTime(newValue);
// end date
if (abstractAppointmentPane.appointment.getEndTime() != null)
{
long lDurationInMS = abstractAppointmentPane.appointment.getEndTime().getTimeInMillis() - lOldStart.getTimeInMillis();
Calendar lEndCalendar = (Calendar)abstractAppointmentPane.appointment.getStartTime().clone();
lEndCalendar.add(Calendar.MILLISECOND, (int)lDurationInMS);
abstractAppointmentPane.appointment.setEndTime(lEndCalendar);
// update field
lEndCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getEndTime());
}
// refresh is done upon popup close
}
}