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