1 package org.kuali.student.lum.program.client.versions; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.kuali.student.r1.common.assembly.data.LookupMetadata; 7 import org.kuali.student.r1.common.assembly.data.Metadata; 8 import org.kuali.student.r1.common.assembly.data.QueryPath; 9 import org.kuali.student.r2.core.search.dto.SearchParamInfo; 10 import org.kuali.student.r2.core.search.dto.SearchRequestInfo; 11 import org.kuali.student.r2.core.search.dto.SortDirection; 12 import org.kuali.student.common.ui.client.application.ViewContext; 13 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; 14 import org.kuali.student.common.ui.client.mvc.Callback; 15 import org.kuali.student.common.ui.client.mvc.DataModel; 16 import org.kuali.student.common.ui.client.mvc.ViewComposite; 17 import org.kuali.student.common.ui.client.mvc.history.HistoryManager; 18 import org.kuali.student.common.ui.client.service.MetadataRpcService; 19 import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync; 20 import org.kuali.student.common.ui.client.widgets.KSButton; 21 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; 22 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout; 23 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout; 24 import org.kuali.student.common.ui.client.widgets.search.SearchResultsTable; 25 import org.kuali.student.lum.common.client.widgets.AppLocations; 26 import org.kuali.student.lum.program.client.ProgramConstants; 27 28 import com.google.gwt.core.client.GWT; 29 import com.google.gwt.event.dom.client.ClickEvent; 30 import com.google.gwt.event.dom.client.ClickHandler; 31 import org.kuali.student.lum.program.client.ProgramRegistry; 32 33 public class ProgramSelectVersionsView extends ViewComposite{ 34 35 private VerticalFieldLayout layout = new VerticalFieldLayout(); 36 private ButtonLayout buttons = new ButtonLayout(); 37 SearchResultsTable table = new SearchResultsTable(); 38 MetadataRpcServiceAsync metadataServiceAsync = GWT.create(MetadataRpcService.class); 39 40 private ProgramVersionsController parent; 41 private DataModel programModel; 42 43 public ProgramSelectVersionsView(DataModel model, ProgramVersionsController controller,String name, Enum<?> viewType) { 44 super(controller, name, viewType); 45 this.initWidget(layout); 46 layout.addStyleName("selectVersions"); 47 layout.addWidget(table); 48 table.setWithMslable(false); 49 layout.addButtonLayout(buttons); 50 parent = controller; 51 this.programModel = model; 52 layout.setLayoutTitle(SectionTitle.generateH2Title("Program Versions")); 53 layout.setInstructions("Select a version to view"); 54 55 table.setMutipleSelect(false); 56 buttons.addButton(new KSButton("Select", new ClickHandler(){ 57 58 @Override 59 public void onClick(ClickEvent event) { 60 if(table.getSelectedIds().size() == 1){ 61 String id = table.getSelectedIds().get(0); 62 ViewContext viewContext = parent.getViewContext(); 63 viewContext.setId(id); 64 navigateToProgramView(viewContext); 65 } 66 } 67 })); 68 69 buttons.addButton(new KSButton("Return to Selected Program", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ 70 71 @Override 72 public void onClick(ClickEvent event) { 73 ViewContext viewContext = parent.getViewContext(); 74 viewContext.setId((String)programModel.get(ProgramConstants.ID)); 75 navigateToProgramView(viewContext); 76 } 77 })); 78 } 79 80 private void navigateToProgramView(ViewContext viewContext){ 81 ProgramRegistry.setCreateNew(true); 82 switch (parent.getType()){ 83 case MAJOR: HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), viewContext); break; 84 case CORE: HistoryManager.navigate(AppLocations.Locations.VIEW_CORE_PROGRAM.getLocation(), viewContext); break; 85 case CREDENTIAL: HistoryManager.navigate(AppLocations.Locations.VIEW_BACC_PROGRAM.getLocation(), viewContext); break; 86 } 87 } 88 89 @Override 90 public void beforeShow(final Callback<Boolean> onReadyCallback) { 91 Metadata searchMetadata = programModel.getDefinition().getMetadata(QueryPath.concat("searchProgramVersions")); 92 LookupMetadata versionSearch = searchMetadata.getInitialLookup(); 93 table.performSearch(generateRequest(versionSearch), versionSearch.getResults(), versionSearch.getResultReturnKey(), false); 94 onReadyCallback.exec(true); 95 } 96 97 private SearchRequestInfo generateRequest(LookupMetadata versionSearch){ 98 SearchRequestInfo sr = new SearchRequestInfo(); 99 List<SearchParamInfo> params = new ArrayList<SearchParamInfo>(); 100 SearchParamInfo param = new SearchParamInfo(); 101 param.setKey("lu.queryParam.cluVersionIndId"); 102 String versionIndId = programModel.get(ProgramConstants.VERSION_IND_ID); 103 versionIndId = (versionIndId == null ? "":versionIndId); 104 param.getValues().add(versionIndId); 105 params.add(param); 106 sr.setSortDirection(SortDirection.DESC); 107 sr.setParams(params); 108 sr.setSearchKey(versionSearch.getSearchTypeId()); 109 if (versionSearch.getResultSortKey() != null) { 110 sr.setSortColumn(versionSearch.getResultSortKey()); 111 } 112 return sr; 113 } 114 115 116 }