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