1 package org.kuali.student.lum.program.client.widgets;
2
3 import com.google.gwt.event.shared.HandlerManager;
4
5 import org.kuali.student.r1.common.assembly.data.ModelDefinition;
6 import org.kuali.student.common.ui.client.application.Application;
7 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
8 import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
9 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
10 import org.kuali.student.common.ui.client.mvc.Callback;
11 import org.kuali.student.common.ui.client.widgets.KSLightBox;
12 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations;
13 import org.kuali.student.common.ui.client.widgets.field.layout.button.ActionCancelGroup;
14 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup;
15 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
16 import org.kuali.student.lum.program.client.ProgramConstants;
17 import org.kuali.student.lum.program.client.ProgramController;
18 import org.kuali.student.lum.program.client.ProgramMsgConstants;
19 import org.kuali.student.lum.program.client.events.MetadataLoadedEvent;
20 import org.kuali.student.lum.program.client.events.UpdateEvent;
21
22
23
24
25 class SideBarDialogManager {
26
27 private HandlerManager eventBus;
28
29 private KSLightBox dialog;
30
31 private ButtonGroup<ButtonEnumerations.ButtonEnum> buttonGroup = new ActionCancelGroup(ButtonEnumerations.SaveCancelEnum.SAVE, ButtonEnumerations.SaveCancelEnum.CANCEL);
32
33 private VerticalSectionView dialogView = new VerticalSectionView(DialogView.MAIN, getLabel(ProgramMsgConstants.SIDEBAR_DIALOG_TITLE), ProgramConstants.PROGRAM_MODEL_ID, true);
34
35 private boolean viewConfigured = false;
36
37 public SideBarDialogManager(HandlerManager eventBus) {
38 this.eventBus = eventBus;
39 dialog = new KSLightBox();
40 dialog.setWidget(dialogView.asWidget());
41 dialog.addButtonGroup(buttonGroup);
42 dialog.setSize(300, 190);
43 dialog.setModal(false);
44 bind();
45 }
46
47 private void bind() {
48 buttonGroup.addCallback(new Callback<ButtonEnumerations.ButtonEnum>() {
49 @Override
50 public void exec(ButtonEnumerations.ButtonEnum button) {
51 if (button == ButtonEnumerations.SaveCancelEnum.SAVE) {
52 dialogView.updateModel();
53 eventBus.fireEvent(new UpdateEvent());
54 }
55 dialog.hide();
56
57 }
58 });
59 eventBus.addHandler(MetadataLoadedEvent.TYPE, new MetadataLoadedEvent.Handler() {
60 @Override
61 public void onEvent(MetadataLoadedEvent event) {
62 configureView(event.getModelDefinition(), event.getController());
63 }
64 });
65 }
66
67 public void configureView(ModelDefinition modelDefinition, ProgramController controller) {
68 if (!viewConfigured) {
69 VerticalSection verticalSection = new VerticalSection();
70 verticalSection.addField(new FieldDescriptor(ProgramConstants.SCHEDULED_REVIEW_DATE, new MessageKeyInfo(ProgramMsgConstants.SIDEBAR_FORM_SCHEDULEDREVIEWDATE), modelDefinition.getMetadata(ProgramConstants.SCHEDULED_REVIEW_DATE)));
71 FieldDescriptor reviewDateDescriptor = new FieldDescriptor(ProgramConstants.LAST_REVIEW_DATE, new MessageKeyInfo(ProgramMsgConstants.SIDEBAR_FORM_LASTREVIEWDATE), modelDefinition.getMetadata(ProgramConstants.LAST_REVIEW_DATE));
72 reviewDateDescriptor.setWidgetBinding(new DateBinding());
73 verticalSection.addField(reviewDateDescriptor);
74 dialogView.setLayoutController(controller);
75 dialogView.addSection(verticalSection);
76 viewConfigured = true;
77 }
78 }
79
80 public void show() {
81 dialogView.beforeShow(new Callback<Boolean>() {
82 @Override
83 public void exec(Boolean result) {
84 }
85 });
86 dialogView.updateModel();
87 dialog.show();
88 }
89
90 private static enum DialogView {
91 MAIN
92 }
93
94 private String getLabel(String messageKey) {
95 return Application.getApplicationContext().getUILabel(ProgramMsgConstants.PROGRAM_MSG_GROUP, messageKey);
96 }
97 }