New Todo Item Stage
This commit is contained in:
parent
a0f002e8bc
commit
fbdd18bb0c
|
@ -0,0 +1,110 @@
|
|||
package org.cutem.cutecalendar.presenter;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.stage.Stage;
|
||||
import org.cutem.cutecalendar.model.TodoItem;
|
||||
import org.cutem.cutecalendar.model.TodoItemFactory;
|
||||
import org.cutem.cutecalendar.util.CalendarUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class NewTodoItemStage implements Initializable {
|
||||
@FXML
|
||||
private ChoiceBox typeChoicebox;
|
||||
private TextField titleInput;
|
||||
private TextField bgnInput;
|
||||
private TextField endInput;
|
||||
private TextField locationInput;
|
||||
private TextField personnelInput;
|
||||
private TextArea descriptionInput;
|
||||
private Button finish;
|
||||
private Button cancel;
|
||||
|
||||
private static final String FXML_FILE = "res/addTodoItemStage.fxml";
|
||||
private ClassLoader mClassLoader = getClass().getClassLoader();
|
||||
|
||||
@Override
|
||||
public void initialize(URL theLocation, ResourceBundle resources) {
|
||||
Parent root = null;
|
||||
try {
|
||||
root = FXMLLoader.load(mClassLoader.getResource(FXML_FILE));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Scene scene = new Scene(root, 400, 345);
|
||||
Stage addStage = new Stage();
|
||||
addStage.setScene(scene);
|
||||
addStage.setTitle("Add a Todo Item");
|
||||
|
||||
ObservableList<String> ways = FXCollections.observableArrayList();
|
||||
ways.add("Conference");
|
||||
ways.add("Dates");
|
||||
ways.add("Others");
|
||||
typeChoicebox = (ChoiceBox) root.lookup("#typeChoicebox");
|
||||
typeChoicebox.setItems(ways);
|
||||
typeChoicebox.setValue("Conference");
|
||||
|
||||
titleInput = (TextField) root.lookup("#titleInput");
|
||||
bgnInput = (TextField) root.lookup("#bgnInput");
|
||||
endInput = (TextField) root.lookup("#endInput");
|
||||
locationInput = (TextField) root.lookup("#locationInput");
|
||||
personnelInput = (TextField) root.lookup("#personnelInput");
|
||||
descriptionInput = (TextArea) root.lookup("#descriptionInput");
|
||||
|
||||
finish = (Button) root.lookup("#finish");
|
||||
cancel = (Button) root.lookup("#cancel");
|
||||
|
||||
finish = (Button) root.lookup("#finish");
|
||||
finish.setOnAction(e -> {
|
||||
String title = titleInput.getText(), bgn = bgnInput.getText(), end = endInput.getText(), location = locationInput.getText(), personnel = personnelInput.getText(), description = descriptionInput.getText();
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
if (title.equals("") || location.equals("") || personnel.equals("") || description.equals("")) {
|
||||
alert.setContentText("Fail:You have some empty inputs.");
|
||||
alert.show();
|
||||
} else if (!CalendarUtil.isValidCalendarString(bgn) || !CalendarUtil.isValidCalendarString(end)) {
|
||||
alert.setContentText("Fail:Your CalendarString input is not vaild.");
|
||||
alert.show();
|
||||
}
|
||||
|
||||
TodoItemFactory factory = new TodoItemFactory();
|
||||
|
||||
int type = typeChoicebox.getValue().equals("Conference") ? 1 : typeChoicebox.getValue().equals("Dates") ? 2 : 3;
|
||||
String[] persons = personnel.split(",");
|
||||
for (int i = 0; i < persons.length; i++)
|
||||
factory.personnel(persons[i]);
|
||||
factory.title(title);
|
||||
factory.beginTime(CalendarUtil.constructCalendar(bgn));
|
||||
factory.endTime(CalendarUtil.constructCalendar(end));
|
||||
factory.type(type);
|
||||
factory.location(location);
|
||||
factory.description(description);
|
||||
TodoItem newItem;
|
||||
try {
|
||||
newItem = factory.build();
|
||||
// Presenter.addTodoItem(newItem);
|
||||
alert.setContentText("Succeed");
|
||||
alert.show();
|
||||
addStage.close();
|
||||
} catch (IllegalStateException ex) {
|
||||
alert.setContentText("Fail" + ex.toString());
|
||||
alert.show();
|
||||
}
|
||||
});
|
||||
|
||||
cancel = (Button) root.lookup("#cancel");
|
||||
cancel.setOnAction(e -> {
|
||||
addStage.close();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="459.0" prefWidth="433.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="212.0" minWidth="10.0" prefWidth="124.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="319.0" minWidth="10.0" prefWidth="309.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="46.0" minHeight="10.0" prefHeight="26.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="75.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="104.0" minHeight="10.0" prefHeight="36.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="107.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="94.0" minHeight="0.0" prefHeight="43.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="185.0" minHeight="10.0" prefHeight="151.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="94.0" minHeight="10.0" prefHeight="70.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="Title" GridPane.halignment="CENTER" />
|
||||
<Label text="Begin" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
|
||||
<Label text="End" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
|
||||
<Label text="Type" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
||||
<Label text="Location" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||
<Label text="Personnel" GridPane.halignment="CENTER" GridPane.rowIndex="5" />
|
||||
<Label text="Description" GridPane.halignment="CENTER" GridPane.rowIndex="6" GridPane.valignment="TOP" />
|
||||
<TextField fx:id="titleInput" prefHeight="23.0" prefWidth="274.0" promptText="titile of the item" GridPane.columnIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="bgnInput" promptText="YYYY-MM-DD/HH:MM" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="endInput" promptText="YYYY-MM-DD/HH:MM" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="personnelInput" promptText="XX,XXX,.....,XXX" GridPane.columnIndex="1" GridPane.rowIndex="5">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<TextField fx:id="locationInput" promptText="the location of the todo Item" GridPane.columnIndex="1" GridPane.rowIndex="4">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<TextArea fx:id="descriptionInput" prefHeight="89.0" prefWidth="309.0" promptText="the description of the todo item" GridPane.columnIndex="1" GridPane.rowIndex="6">
|
||||
<GridPane.margin>
|
||||
<Insets right="20.0" />
|
||||
</GridPane.margin>
|
||||
</TextArea>
|
||||
<ChoiceBox fx:id="typeChoicebox" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||
<Button fx:id="finish" mnemonicParsing="false" text="Finish" GridPane.columnIndex="1" GridPane.rowIndex="7" />
|
||||
<Button fx:id="cancel" mnemonicParsing="false" text="Cancel" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="7" />
|
||||
</children>
|
||||
</GridPane>
|
Loading…
Reference in New Issue