complete ShowTodoItemDetailStrategy

This commit is contained in:
hlq07 2018-05-12 14:13:46 +08:00
parent 5e1f894e6d
commit b2d232b7ff
1 changed files with 118 additions and 0 deletions

View File

@ -1,12 +1,130 @@
package org.cutem.cutecalendar.presenter;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import org.cutem.cutecalendar.model.TodoItem;
import org.cutem.cutecalendar.util.CalendarUtil;
import org.jetbrains.annotations.NotNull;
public class ShowTodoItemDetailStrategy {
private Stage mStage;
private BorderPane mPane = new BorderPane();
private Text mText = new Text();
private Button delBtn = new Button("delete");
private Button close = new Button("close");
private Presenter mPresenter;
private TodoItem mNowItem;
public ShowTodoItemDetailStrategy(
@NotNull Stage stage
) {
mStage = stage;
initialize();
}
public ShowTodoItemDetailStrategy(
@NotNull Stage stage,
@NotNull Presenter presenter
) {
this(stage);
attachPresenter(presenter);
}
public void attachPresenter(@NotNull Presenter presenter) {
mPresenter = presenter;
}
private void initialize() {
mStage.setScene(new Scene(mPane));
mPane.setCenter(mText);
mPane.setBottom(new HBox(delBtn, close));
delBtn.setOnAction(e -> onClickDelete());
close.setOnAction(e -> onClickClose());
}
public void showTodoItemDetail(@NotNull TodoItem item) {
mNowItem = item;
StringBuilder builder = new StringBuilder();
builder.append("id: ").append(Long.toString(item.getId()));
if (item.getTitle() != null) {
builder.append('\n').append("title: ").append(item.getTitle());
}
builder.append("\nfrom:\t")
.append(CalendarUtil.toString(item.getBgn()))
.append("\nto:\t")
.append(CalendarUtil.toString(item.getEnd()));
builder.append("\ntype: ");
switch (item.getType()) {
case TodoItem.CONFERENCE: {
builder.append("conference");
}
case TodoItem.DATE: {
builder.append("date");
}
case TodoItem.OTHERS: {
builder.append("others");
}
default: {
builder.append("unknown");
}
}
if (item.getTitle() != null) {
builder.append("\ntitle: ")
.append(item.getTitle());
}
if (item.getLocation() != null) {
builder.append("\nlocation: ")
.append(item.getLocation());
}
if (item.getDescription() != null) {
builder.append("\ndescription: ")
.append(item.getDescription());
}
String[] ps = item.getPersonnel();
if (ps.length > 0) {
builder.append("\npeople:");
for (String p : ps) {
builder.append("\n\t").append(p);
}
}
mText.setText(builder.toString());
}
private void onClickDelete() {
if (mNowItem != null) {
mPresenter.removeTodoItem(mNowItem);
}
onClickClose();
}
private void onClickClose() {
mNowItem = null;
mStage.close();
}
}