View Javadoc

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