1 package org.kuali.student.lum.lu.ui.dependency.client.controllers;
2
3 import java.util.List;
4
5 import org.kuali.student.common.ui.client.application.Application;
6 import org.kuali.student.common.ui.client.configurable.mvc.layouts.BasicLayout;
7 import org.kuali.student.common.ui.client.mvc.Callback;
8 import org.kuali.student.common.ui.client.mvc.DataModel;
9 import org.kuali.student.common.ui.client.security.AuthorizationCallback;
10 import org.kuali.student.common.ui.client.security.RequiresAuthorization;
11 import org.kuali.student.common.ui.client.util.ExportElement;
12 import org.kuali.student.lum.common.client.lu.LUUIPermissions;
13 import org.kuali.student.lum.lu.ui.dependency.client.views.DependencyAnalysisView;
14
15 import com.google.gwt.core.client.GWT;
16
17 public class DependencyAnalysisController extends BasicLayout implements RequiresAuthorization {
18
19 public enum DependencyViews {
20 MAIN
21 };
22
23 public DependencyAnalysisController(String controllerId) {
24 super(controllerId);
25 addView(new DependencyAnalysisView(this));
26 setDefaultView(DependencyViews.MAIN);
27 }
28
29 public void showExport(boolean show) {
30 DependencyAnalysisView dependancyView = (DependencyAnalysisView) viewMap.get(DependencyViews.MAIN);
31 if (dependancyView.getHeader() != null) {
32 dependancyView.getHeader().showExport(isExportButtonActive());
33
34 }
35 }
36
37 @Override
38 public boolean isExportButtonActive() {
39 return true;
40 }
41
42 @Override
43 public DataModel getExportDataModel() {
44
45 return super.getExportDataModel();
46 }
47
48 @Override
49 public List<ExportElement> getExportElementsFromView() {
50 DependencyAnalysisView view = (DependencyAnalysisView) this.getCurrentView();
51 ExportElement element = GWT.create(ExportElement.class);
52 element.setViewName(view.getName());
53 element.setSectionName("");
54 return view.getDepResultPanel().getExportElementSubset(element);
55 }
56
57
58
59
60 @Override
61 public String getExportTemplateName() {
62 return "analysis.template";
63 }
64
65
66
67
68
69
70 @Override
71 public String getName() {
72 String name = super.getName();
73 if ((name == null) && (this.getCurrentView() != null)) {
74 name = this.getCurrentView().getName();
75 }
76 return name;
77 }
78
79 @Override
80 public boolean isAuthorizationRequired() {
81 return true;
82 }
83
84 @Override
85 public void setAuthorizationRequired(boolean required) {
86 throw new UnsupportedOperationException();
87 }
88
89 @Override
90 public void checkAuthorization(final AuthorizationCallback authCallback) {
91 Application.getApplicationContext().getSecurityContext().checkScreenPermission(LUUIPermissions.USE_DEPENDENCY_ANALYSIS_SCREEN, new Callback<Boolean>() {
92 @Override
93 public void exec(Boolean result) {
94
95 final boolean isAuthorized = result;
96
97 if(isAuthorized){
98 authCallback.isAuthorized();
99 }
100 else
101 authCallback.isNotAuthorized("User is not authorized: " + LUUIPermissions.USE_DEPENDENCY_ANALYSIS_SCREEN);
102 }
103 });
104 }
105
106 }