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.common.ui.client.application.ViewContext; 7 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; 8 import org.kuali.student.common.ui.client.mvc.Callback; 9 import org.kuali.student.common.ui.client.mvc.DataModel; 10 import org.kuali.student.common.ui.client.mvc.ViewComposite; 11 import org.kuali.student.common.ui.client.mvc.history.HistoryManager; 12 import org.kuali.student.common.ui.client.service.MetadataRpcService; 13 import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync; 14 import org.kuali.student.common.ui.client.widgets.KSButton; 15 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; 16 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout; 17 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout; 18 import org.kuali.student.common.ui.client.widgets.search.SearchResultsTable; 19 import org.kuali.student.core.assembly.data.LookupMetadata; 20 import org.kuali.student.core.assembly.data.Metadata; 21 import org.kuali.student.core.assembly.data.QueryPath; 22 import org.kuali.student.core.search.dto.SearchParam; 23 import org.kuali.student.core.search.dto.SearchRequest; 24 import org.kuali.student.core.search.dto.SortDirection; 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 layout.addButtonLayout(buttons); 49 parent = controller; 50 this.programModel = model; 51 layout.setLayoutTitle(SectionTitle.generateH2Title("Program Versions")); 52 layout.setInstructions("Select a version to view"); 53 54 table.setMutipleSelect(false); 55 buttons.addButton(new KSButton("Select", new ClickHandler(){ 56 57 @Override 58 public void onClick(ClickEvent event) { 59 if(table.getSelectedIds().size() == 1){ 60 String id = table.getSelectedIds().get(0); 61 ViewContext viewContext = parent.getViewContext(); 62 viewContext.setId(id); 63 navigateToProgramView(viewContext); 64 } 65 } 66 })); 67 68 buttons.addButton(new KSButton("Return to Selected Program", ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler(){ 69 70 @Override 71 public void onClick(ClickEvent event) { 72 ViewContext viewContext = parent.getViewContext(); 73 viewContext.setId((String)programModel.get(ProgramConstants.ID)); 74 navigateToProgramView(viewContext); 75 } 76 })); 77 } 78 79 private void navigateToProgramView(ViewContext viewContext){ 80 ProgramRegistry.setCreateNew(true); 81 switch (parent.getType()){ 82 case MAJOR: HistoryManager.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), viewContext); break; 83 case CORE: HistoryManager.navigate(AppLocations.Locations.VIEW_CORE_PROGRAM.getLocation(), viewContext); break; 84 case CREDENTIAL: HistoryManager.navigate(AppLocations.Locations.VIEW_BACC_PROGRAM.getLocation(), viewContext); break; 85 } 86 } 87 88 @Override 89 public void beforeShow(final Callback<Boolean> onReadyCallback) { 90 Metadata searchMetadata = programModel.getDefinition().getMetadata(QueryPath.concat("searchProgramVersions")); 91 LookupMetadata versionSearch = searchMetadata.getInitialLookup(); 92 table.performSearch(generateRequest(versionSearch), versionSearch.getResults(), versionSearch.getResultReturnKey(), false); 93 onReadyCallback.exec(true); 94 } 95 96 private SearchRequest generateRequest(LookupMetadata versionSearch){ 97 SearchRequest sr = new SearchRequest(); 98 List<SearchParam> params = new ArrayList<SearchParam>(); 99 SearchParam param = new SearchParam(); 100 param.setKey("lu.queryParam.cluVersionIndId"); 101 String versionIndId = programModel.get(ProgramConstants.VERSION_IND_ID); 102 versionIndId = (versionIndId == null ? "":versionIndId); 103 param.setValue(versionIndId); 104 params.add(param); 105 sr.setSortDirection(SortDirection.DESC); 106 sr.setParams(params); 107 sr.setSearchKey(versionSearch.getSearchTypeId()); 108 if (versionSearch.getResultSortKey() != null) { 109 sr.setSortColumn(versionSearch.getResultSortKey()); 110 } 111 return sr; 112 } 113 114 115 }