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 | |
|
22 | |
|
23 | 0 | class SideBarDialogManager { |
24 | |
|
25 | |
private HandlerManager eventBus; |
26 | |
|
27 | |
private KSLightBox dialog; |
28 | |
|
29 | 0 | private ButtonGroup<ButtonEnumerations.ButtonEnum> buttonGroup = new ActionCancelGroup(ButtonEnumerations.SaveCancelEnum.SAVE, ButtonEnumerations.SaveCancelEnum.CANCEL); |
30 | |
|
31 | 0 | private VerticalSectionView dialogView = new VerticalSectionView(DialogView.MAIN, "", ProgramConstants.PROGRAM_MODEL_ID); |
32 | |
|
33 | 0 | private boolean viewConfigured = false; |
34 | |
|
35 | 0 | public SideBarDialogManager(HandlerManager eventBus) { |
36 | 0 | this.eventBus = eventBus; |
37 | 0 | dialog = new KSLightBox(ProgramProperties.get().sideBar_dialog_title()); |
38 | 0 | dialog.setWidget(dialogView.asWidget()); |
39 | 0 | dialog.addButtonGroup(buttonGroup); |
40 | 0 | dialog.setSize(300, 170); |
41 | 0 | dialog.setModal(false); |
42 | 0 | bind(); |
43 | 0 | } |
44 | |
|
45 | |
private void bind() { |
46 | 0 | buttonGroup.addCallback(new Callback<ButtonEnumerations.ButtonEnum>() { |
47 | |
@Override |
48 | |
public void exec(ButtonEnumerations.ButtonEnum button) { |
49 | 0 | if (button == ButtonEnumerations.SaveCancelEnum.SAVE) { |
50 | 0 | dialogView.updateModel(); |
51 | 0 | eventBus.fireEvent(new UpdateEvent()); |
52 | |
} |
53 | 0 | dialog.hide(); |
54 | |
|
55 | 0 | } |
56 | |
}); |
57 | 0 | eventBus.addHandler(MetadataLoadedEvent.TYPE, new MetadataLoadedEvent.Handler() { |
58 | |
@Override |
59 | |
public void onEvent(MetadataLoadedEvent event) { |
60 | 0 | configureView(event.getModelDefinition(), event.getController()); |
61 | 0 | } |
62 | |
}); |
63 | 0 | } |
64 | |
|
65 | |
public void configureView(ModelDefinition modelDefinition, ProgramController controller) { |
66 | 0 | if (!viewConfigured) { |
67 | 0 | VerticalSection verticalSection = new VerticalSection(); |
68 | 0 | verticalSection.addField(new FieldDescriptor(ProgramConstants.SCHEDULED_REVIEW_DATE, new MessageKeyInfo(ProgramProperties.get().sideBar_form_scheduledReviewDate()), modelDefinition.getMetadata(ProgramConstants.SCHEDULED_REVIEW_DATE))); |
69 | 0 | FieldDescriptor reviewDateDescriptor = new FieldDescriptor(ProgramConstants.LAST_REVIEW_DATE, new MessageKeyInfo(ProgramProperties.get().sideBar_lastReviewDate()), modelDefinition.getMetadata(ProgramConstants.LAST_REVIEW_DATE)); |
70 | 0 | reviewDateDescriptor.setWidgetBinding(new DateBinding()); |
71 | 0 | verticalSection.addField(reviewDateDescriptor); |
72 | 0 | dialogView.setLayoutController(controller); |
73 | 0 | dialogView.addSection(verticalSection); |
74 | 0 | viewConfigured = true; |
75 | |
} |
76 | 0 | } |
77 | |
|
78 | |
public void show() { |
79 | 0 | dialogView.beforeShow(new Callback<Boolean>() { |
80 | |
@Override |
81 | |
public void exec(Boolean result) { |
82 | 0 | } |
83 | |
}); |
84 | 0 | dialogView.updateModel(); |
85 | 0 | dialog.show(); |
86 | 0 | } |
87 | |
|
88 | 0 | private static enum DialogView { |
89 | 0 | MAIN |
90 | |
} |
91 | |
} |