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 | 0 | 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 | 0 | super("", programModel, viewContext, eventBus); |
45 | 0 | this.parentName = majorController.getName(); |
46 | 0 | this.majorController = majorController; |
47 | 0 | setName(getProgramName()); |
48 | 0 | sideBar = new ProgramSideBar(eventBus, ProgramSideBar.Type.MAJOR); |
49 | 0 | sideBar.initialize(majorController); |
50 | 0 | } |
51 | |
|
52 | |
@Override |
53 | |
protected void configureView() { |
54 | 0 | setStatus(); |
55 | 0 | super.configureView(); |
56 | 0 | setContentTitle(getProgramName()); |
57 | 0 | addContentWidget(createParentAnchor()); |
58 | 0 | addContentWidget(createCommentPanel()); |
59 | 0 | } |
60 | |
|
61 | |
private Widget createParentAnchor() { |
62 | 0 | HorizontalPanel anchorPanel = new HorizontalPanel(); |
63 | 0 | Anchor anchor = new Anchor(parentName); |
64 | 0 | anchor.addClickHandler(new ClickHandler() { |
65 | |
@Override |
66 | |
public void onClick(ClickEvent event) { |
67 | 0 | navigateToParent(); |
68 | 0 | } |
69 | |
}); |
70 | 0 | Label parentProgram = new Label(ProgramProperties.get().variation_parentProgram()); |
71 | 0 | parentProgram.addStyleName("parentProgram"); |
72 | 0 | anchorPanel.add(parentProgram); |
73 | 0 | anchorPanel.add(anchor); |
74 | 0 | return anchorPanel; |
75 | |
} |
76 | |
|
77 | |
protected abstract void navigateToParent(); |
78 | |
|
79 | |
@Override |
80 | |
public String getProgramName() { |
81 | 0 | String name = getStringProperty(ProgramConstants.LONG_TITLE); |
82 | 0 | if (name == null) { |
83 | 0 | return ProgramProperties.get().variation_new(); |
84 | |
} |
85 | 0 | return ProgramProperties.get().variation_title(name); |
86 | |
} |
87 | |
|
88 | |
@Override |
89 | |
public void collectBreadcrumbNames(List<String> names) { |
90 | 0 | String appLoc = ""; |
91 | |
|
92 | 0 | if(!(majorController instanceof MajorProposalController)) |
93 | 0 | appLoc = AppLocations.Locations.VIEW_PROGRAM.getLocation(); |
94 | |
else |
95 | 0 | appLoc = AppLocations.Locations.PROGRAM_PROPOSAL.getLocation(); |
96 | 0 | names.add(parentName + "@" + HistoryManager.appendContext(appLoc, getViewContext())); |
97 | 0 | super.collectBreadcrumbNames(names); |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
@Override |
106 | |
protected void loadModel(final ModelRequestCallback<DataModel> callback) { |
107 | 0 | programRemoteService.getData(getViewContext().getId(), new AbstractCallback<Data>(ProgramProperties.get().common_retrievingData()) { |
108 | |
|
109 | |
@Override |
110 | |
public void onFailure(Throwable caught) { |
111 | 0 | super.onFailure(caught); |
112 | 0 | callback.onRequestFail(caught); |
113 | 0 | } |
114 | |
|
115 | |
@Override |
116 | |
public void onSuccess(Data result) { |
117 | 0 | super.onSuccess(result); |
118 | 0 | programModel.setRoot(result); |
119 | 0 | callback.onModelReady(programModel); |
120 | 0 | eventBus.fireEvent(new ModelLoadedEvent(programModel)); |
121 | 0 | } |
122 | |
}); |
123 | 0 | } |
124 | |
} |