1 package org.kuali.student.lum.program.client.variation;
2
3 import java.util.List;
4
5 import org.kuali.student.common.assembly.data.Data;
6 import org.kuali.student.common.ui.client.application.ViewContext;
7 import org.kuali.student.common.ui.client.mvc.DataModel;
8 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
9 import org.kuali.student.common.ui.client.mvc.history.HistoryManager;
10 import org.kuali.student.lum.common.client.widgets.AppLocations;
11 import org.kuali.student.lum.program.client.ProgramConstants;
12 import org.kuali.student.lum.program.client.ProgramController;
13 import org.kuali.student.lum.program.client.events.ModelLoadedEvent;
14 import org.kuali.student.lum.program.client.major.MajorController;
15 import org.kuali.student.lum.program.client.major.proposal.MajorProposalController;
16 import org.kuali.student.lum.program.client.properties.ProgramProperties;
17 import org.kuali.student.lum.program.client.rpc.AbstractCallback;
18 import org.kuali.student.lum.program.client.widgets.ProgramSideBar;
19
20 import com.google.gwt.event.dom.client.ClickEvent;
21 import com.google.gwt.event.dom.client.ClickHandler;
22 import com.google.gwt.event.shared.HandlerManager;
23 import com.google.gwt.user.client.ui.Anchor;
24 import com.google.gwt.user.client.ui.HorizontalPanel;
25 import com.google.gwt.user.client.ui.Label;
26 import com.google.gwt.user.client.ui.Widget;
27
28
29
30
31 public abstract class VariationController extends ProgramController {
32
33 private String parentName;
34
35 protected MajorController majorController;
36
37
38
39
40
41
42
43 public VariationController(DataModel programModel, ViewContext viewContext, HandlerManager eventBus, MajorController majorController) {
44 super("", programModel, viewContext, eventBus);
45 this.parentName = majorController.getName();
46 this.majorController = majorController;
47 setName(getProgramName());
48 sideBar = new ProgramSideBar(eventBus, ProgramSideBar.Type.MAJOR);
49 sideBar.initialize(majorController);
50 }
51
52 @Override
53 protected void configureView() {
54 setStatus();
55 super.configureView();
56 setContentTitle(getProgramName());
57 addContentWidget(createParentAnchor());
58 addContentWidget(createCommentPanel());
59 }
60
61 private Widget createParentAnchor() {
62 HorizontalPanel anchorPanel = new HorizontalPanel();
63 Anchor anchor = new Anchor(parentName);
64 anchor.addClickHandler(new ClickHandler() {
65 @Override
66 public void onClick(ClickEvent event) {
67 navigateToParent();
68 }
69 });
70 Label parentProgram = new Label(ProgramProperties.get().variation_parentProgram());
71 parentProgram.addStyleName("parentProgram");
72 anchorPanel.add(parentProgram);
73 anchorPanel.add(anchor);
74 return anchorPanel;
75 }
76
77 protected abstract void navigateToParent();
78
79 @Override
80 public String getProgramName() {
81 String name = getStringProperty(ProgramConstants.LONG_TITLE);
82 if (name == null) {
83 return ProgramProperties.get().variation_new();
84 }
85 return ProgramProperties.get().variation_title(name);
86 }
87
88 @Override
89 public void collectBreadcrumbNames(List<String> names) {
90 String appLoc = "";
91
92 if(!(majorController instanceof MajorProposalController))
93 appLoc = AppLocations.Locations.VIEW_PROGRAM.getLocation();
94 else
95 appLoc = AppLocations.Locations.PROGRAM_PROPOSAL.getLocation();
96 names.add(parentName + "@" + HistoryManager.appendContext(appLoc, getViewContext()));
97 super.collectBreadcrumbNames(names);
98 }
99
100
101
102
103
104
105 @Override
106 protected void loadModel(final ModelRequestCallback<DataModel> callback) {
107 programRemoteService.getData(getViewContext().getId(), new AbstractCallback<Data>(ProgramProperties.get().common_retrievingData()) {
108
109 @Override
110 public void onFailure(Throwable caught) {
111 super.onFailure(caught);
112 callback.onRequestFail(caught);
113 }
114
115 @Override
116 public void onSuccess(Data result) {
117 super.onSuccess(result);
118 programModel.setRoot(result);
119 callback.onModelReady(programModel);
120 eventBus.fireEvent(new ModelLoadedEvent(programModel));
121 }
122 });
123 }
124 }