001 package org.kuali.student.lum.program.client.widgets; 002 003 import com.google.gwt.event.shared.HandlerManager; 004 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; 005 import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection; 006 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; 007 import org.kuali.student.common.ui.client.mvc.Callback; 008 import org.kuali.student.common.ui.client.widgets.KSLightBox; 009 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations; 010 import org.kuali.student.common.ui.client.widgets.field.layout.button.ActionCancelGroup; 011 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonGroup; 012 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; 013 import org.kuali.student.core.assembly.data.ModelDefinition; 014 import org.kuali.student.lum.program.client.ProgramConstants; 015 import org.kuali.student.lum.program.client.ProgramController; 016 import org.kuali.student.lum.program.client.events.MetadataLoadedEvent; 017 import org.kuali.student.lum.program.client.events.UpdateEvent; 018 import org.kuali.student.lum.program.client.properties.ProgramProperties; 019 020 /** 021 * @author Igor 022 */ 023 class SideBarDialogManager { 024 025 private HandlerManager eventBus; 026 027 private KSLightBox dialog; 028 029 private ButtonGroup<ButtonEnumerations.ButtonEnum> buttonGroup = new ActionCancelGroup(ButtonEnumerations.SaveCancelEnum.SAVE, ButtonEnumerations.SaveCancelEnum.CANCEL); 030 031 private VerticalSectionView dialogView = new VerticalSectionView(DialogView.MAIN, ProgramProperties.get().sideBar_dialog_title(), ProgramConstants.PROGRAM_MODEL_ID, true); 032 033 private boolean viewConfigured = false; 034 035 public SideBarDialogManager(HandlerManager eventBus) { 036 this.eventBus = eventBus; 037 dialog = new KSLightBox(); 038 dialog.setWidget(dialogView.asWidget()); 039 dialog.addButtonGroup(buttonGroup); 040 dialog.setSize(300, 190); 041 dialog.setModal(false); 042 bind(); 043 } 044 045 private void bind() { 046 buttonGroup.addCallback(new Callback<ButtonEnumerations.ButtonEnum>() { 047 @Override 048 public void exec(ButtonEnumerations.ButtonEnum button) { 049 if (button == ButtonEnumerations.SaveCancelEnum.SAVE) { 050 dialogView.updateModel(); 051 eventBus.fireEvent(new UpdateEvent()); 052 } 053 dialog.hide(); 054 055 } 056 }); 057 eventBus.addHandler(MetadataLoadedEvent.TYPE, new MetadataLoadedEvent.Handler() { 058 @Override 059 public void onEvent(MetadataLoadedEvent event) { 060 configureView(event.getModelDefinition(), event.getController()); 061 } 062 }); 063 } 064 065 public void configureView(ModelDefinition modelDefinition, ProgramController controller) { 066 if (!viewConfigured) { 067 VerticalSection verticalSection = new VerticalSection(); 068 verticalSection.addField(new FieldDescriptor(ProgramConstants.SCHEDULED_REVIEW_DATE, new MessageKeyInfo(ProgramProperties.get().sideBar_form_scheduledReviewDate()), modelDefinition.getMetadata(ProgramConstants.SCHEDULED_REVIEW_DATE))); 069 FieldDescriptor reviewDateDescriptor = new FieldDescriptor(ProgramConstants.LAST_REVIEW_DATE, new MessageKeyInfo(ProgramProperties.get().sideBar_lastReviewDate()), modelDefinition.getMetadata(ProgramConstants.LAST_REVIEW_DATE)); 070 reviewDateDescriptor.setWidgetBinding(new DateBinding()); 071 verticalSection.addField(reviewDateDescriptor); 072 dialogView.setLayoutController(controller); 073 dialogView.addSection(verticalSection); 074 viewConfigured = true; 075 } 076 } 077 078 public void show() { 079 dialogView.beforeShow(new Callback<Boolean>() { 080 @Override 081 public void exec(Boolean result) { 082 } 083 }); 084 dialogView.updateModel(); 085 dialog.show(); 086 } 087 088 private static enum DialogView { 089 MAIN 090 } 091 }