add AnniversaryTypeNewItemBuilder

This commit is contained in:
liuyuqing 2018-05-29 14:57:01 +08:00
parent ef9af540c7
commit ea163454f0
1 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,107 @@
package org.cutem.cutecalendar.presenter.newitems;
import javafx.fxml.FXML;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import org.cutem.cutecalendar.model.TodoItem;
import org.cutem.cutecalendar.model.TodoItemFactory;
import org.cutem.cutecalendar.util.CalendarUtil;
import org.jetbrains.annotations.Nullable;
import java.util.Calendar;
public class AnniversaryTypeNewItemBuilder extends NewItemBuilder {
public static class Factory implements IFactory {
@Override
public String getTypeName() {
return TYPE_NAME;
}
@Override
public NewItemBuilder construct(@Nullable TodoItem parent) {
return new AnniversaryTypeNewItemBuilder(parent);
}
}
private static final String ANNI_TYPE_LAYOUT = "fxml/newitem_layouts/anniversary_type_layout.fxml";
private static final int TYPE = TodoItem.ANNIVERSARY;
private static final String TYPE_NAME = TodoItem.typeName(TYPE);
@FXML
private TextField dateTimeText;
@FXML
private TextField titleText;
@FXML
private TextField typeText;
@FXML
private TextField descriptionText;
@FXML
private ChoiceBox<String> priorityBox;
@FXML
private ChoiceBox<String> importanceBox;
@FXML
private ChoiceBox<String> alarmMethodBox;
@FXML
private TextField alarmStartText;
@FXML
private TextField alarmIntervalText;
protected AnniversaryTypeNewItemBuilder(TodoItem parent) {
super(parent);
loadLayout(ANNI_TYPE_LAYOUT);
}
@FXML
private void initialize() {
addAutoSet(TodoItem.TITLE, titleText.textProperty(), "请填写描述");
addAutoSet("type", typeText.textProperty(), "请填写纪念日类型");
addAutoSet(TodoItem.DESCRIPTION, descriptionText.textProperty(), "请填写描述");
addAutoSet(TodoItem.ALARM_START, alarmStartText.textProperty(), "提醒的开始时间不合法");
addAutoSet(TodoItem.ALARM_INTERVAL, alarmIntervalText.textProperty(), "提醒的间隔时间不合法");
}
@Override
public String getTypeName() {
return TYPE_NAME;
}
@Override
protected boolean check() {
if (!autoCheck()) {
return false;
}
String date = dateTimeText.getText() + "/0:0";
if (!CalendarUtil.isValidCalendarString(date)) {
showAlert("时间不合法");
return false;
}
return true;
}
@Override
protected Object make() {
TodoItemFactory fac = autoBuild();
String date = dateTimeText.getText() + "/0:0";
Calendar c = CalendarUtil.constructCalendar(date);
String priority = priorityBox.getValue();
String importance = importanceBox.getValue();
String alarmMethod = alarmMethodBox.getValue();
return fac.type(TYPE)
.wholeDay(c)
.stringProperties(TodoItem.PRIORITY, priority)
.stringProperties(TodoItem.IMPORTANCE, importance)
.stringProperties(TodoItem.ALARM_METHOD, alarmMethod)
.build();
}
}