View Javadoc

1   package org.kuali.student.lum.lu.ui.course.client.views;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.kuali.student.common.ui.client.application.Application;
7   import org.kuali.student.common.ui.client.application.ViewContext;
8   import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
9   import org.kuali.student.common.ui.client.mvc.Callback;
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.common.ui.shared.IdAttributes.IdType;
20  import org.kuali.student.lum.common.client.lu.LUUIConstants;
21  import org.kuali.student.lum.common.client.widgets.AppLocations;
22  import org.kuali.student.lum.lu.ui.course.client.controllers.VersionsController;
23  import org.kuali.student.r1.common.assembly.data.LookupMetadata;
24  import org.kuali.student.r1.common.assembly.data.Metadata;
25  import org.kuali.student.r1.common.assembly.data.QueryPath;
26  import org.kuali.student.r2.core.search.dto.SearchParamInfo;
27  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
28  import org.kuali.student.r2.core.search.dto.SortDirection;
29  
30  import com.google.gwt.core.client.GWT;
31  import com.google.gwt.event.dom.client.ClickEvent;
32  import com.google.gwt.event.dom.client.ClickHandler;
33  import com.google.gwt.user.client.Window;
34  
35  public class SelectVersionsView extends ViewComposite{
36  
37  
38  	private VerticalFieldLayout layout = new VerticalFieldLayout();
39  	//private KSDocumentHeader header = new KSDocumentHeader();
40  	private ButtonLayout buttons = new ButtonLayout();
41  	SearchResultsTable table = new SearchResultsTable();
42  	MetadataRpcServiceAsync metadataServiceAsync = GWT.create(MetadataRpcService.class);
43  	private String id1;
44  	private String id2;
45  	
46  	private VersionsController parent;
47  
48  	public SelectVersionsView(VersionsController controller, String name,
49  			Enum<?> viewType) {
50  		super(controller, name, viewType);
51  		this.initWidget(layout);
52  		layout.addStyleName("selectVersions");
53  		//layout.add(header);
54  		//header.addStyleName("Lum-DocumentHeader-Spacing");
55  		//header.setTitle(name);
56  		layout.addWidget(table);
57  		layout.addButtonLayout(buttons);
58  		parent = controller;
59  		//layout.addWidget(widget)
60  		layout.setLayoutTitle(SectionTitle.generateH2Title("Select Versions"));
61  		layout.setInstructions("Select two drafts to compare, or select one to view");
62  		buttons.addButton(new KSButton("Show Version(s)", new ClickHandler(){
63  
64  			@Override
65  			public void onClick(ClickEvent event) {
66  				if(table.getSelectedIds().size() == 1){
67  					id1 = table.getSelectedIds().get(0);
68  					id2 = null;
69  					ViewContext context = new ViewContext();
70  					context.setId(id1);
71  					getController().setViewContext(context);
72  					getController().showView(VersionsController.Views.VERSION_VIEW);
73  				}
74  				else if(table.getSelectedIds().size() == 2){
75  					id1 = table.getSelectedIds().get(0);
76  					id2 = table.getSelectedIds().get(1);
77  					ViewContext context = new ViewContext();
78  					context.setId(id1);
79  					context.setAttribute("docId2", id2);
80  					getController().setViewContext(context);
81  					getController().showView(VersionsController.Views.VERSION_COMPARE);
82  				}
83  				else{
84  					Window.alert("Please select either a single version to VIEW or two versions to COMPARE");
85  				}
86  			}
87  		}));
88  		buttons.addButton(new KSButton(Application.getApplicationContext().getUILabel(LUUIConstants.COURSE_GROUP_NAME,
89                  LUUIConstants.VERSION_BACK_BUTTON_LABEL_KEY), ButtonStyle.ANCHOR_LARGE_CENTERED, new ClickHandler() {
90  
91  			@Override
92  			public void onClick(ClickEvent event) {
93  				ViewContext context = new ViewContext();
94  				context.setId(parent.getCurrentVersionId());
95  				context.setIdType(IdType.OBJECT_ID);
96  				HistoryManager.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), context);
97  			}
98  		}));
99  	}
100 
101 	@Override
102 	public void beforeShow(final Callback<Boolean> onReadyCallback) {
103 		
104     	Metadata searchMetadata = parent.getDefinition().getMetadata(QueryPath.concat("searchCourseVersions"));
105     	//List<LookupMetadata> additionalLookups = searchMetadata.getAdditionalLookups();
106     	LookupMetadata versionSearch = searchMetadata.getInitialLookup();
107 /*    	for(int i = 0; i < additionalLookups.size(); i++){
108     		if(additionalLookups.get(i).getWidget() == LookupMetadata.Widget.ADVANCED_LIGHTBOX){
109     			versionSearch = additionalLookups.get(i);
110     			break;
111     		}
112     	}*/
113     	table.performSearch(generateRequest(versionSearch), versionSearch.getResults(), versionSearch.getResultReturnKey(), false);
114 		onReadyCallback.exec(true);
115 
116 	}
117 	
118 	private SearchRequestInfo generateRequest(LookupMetadata versionSearch){
119     	SearchRequestInfo sr = new SearchRequestInfo();
120         List<SearchParamInfo> params = new ArrayList<SearchParamInfo>();
121         SearchParamInfo param = new SearchParamInfo();
122         param.setKey("lu.queryParam.cluVersionIndId");
123         param.getValues().add(parent.getVersionIndId());
124         params.add(param);
125         sr.setSortDirection(SortDirection.DESC);
126         sr.setParams(params);
127         sr.setSearchKey(versionSearch.getSearchTypeId());
128         if (versionSearch.getResultSortKey() != null) {
129             sr.setSortColumn(versionSearch.getResultSortKey());
130         }
131         return sr;
132 	}
133 
134 	
135 	public String getId1() {
136 		return id1;
137 	}
138 
139 	public String getId2() {
140 		return id2;
141 	}
142 }