1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.lu.ui.tools.client.widgets; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collections; |
20 | |
import java.util.LinkedHashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.kuali.student.common.assembly.data.LookupMetadata; |
25 | |
import org.kuali.student.common.assembly.data.LookupParamMetadata; |
26 | |
import org.kuali.student.common.ui.client.application.Application; |
27 | |
import org.kuali.student.common.ui.client.application.ViewContext; |
28 | |
import org.kuali.student.common.ui.client.configurable.mvc.WidgetConfigInfo; |
29 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
30 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
31 | |
import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; |
32 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
33 | |
|
34 | |
import com.google.gwt.user.client.Window; |
35 | |
import com.google.gwt.user.client.ui.Composite; |
36 | |
|
37 | |
public class KSBrowser extends Composite { |
38 | |
|
39 | |
private List<BrowsePanel> browsePanels; |
40 | |
private LookupMetadata fieldLookup; |
41 | |
private List<LookupMetadata> cascadingLookups; |
42 | |
private List<LookupParamMetadata> cascadingChildParameters; |
43 | |
private WidgetConfigInfo config; |
44 | 0 | private VerticalFlowPanel layout = new VerticalFlowPanel (); |
45 | |
|
46 | |
public KSBrowser (LookupMetadata fieldLookup, Controller controller) |
47 | 0 | { |
48 | 0 | this.fieldLookup = fieldLookup; |
49 | |
|
50 | 0 | if (config == null) |
51 | |
{ |
52 | 0 | config = new WidgetConfigInfo (); |
53 | |
} |
54 | |
|
55 | 0 | browsePanels = new ArrayList<BrowsePanel> (); |
56 | 0 | cascadingLookups = new ArrayList<LookupMetadata> (); |
57 | 0 | cascadingChildParameters = new ArrayList<LookupParamMetadata> (); |
58 | 0 | cascadingLookups.add (this.fieldLookup); |
59 | 0 | this.addChildLookups (this.fieldLookup); |
60 | 0 | Collections.reverse (cascadingChildParameters); |
61 | 0 | Collections.reverse (cascadingLookups); |
62 | |
|
63 | 0 | for (LookupMetadata lookupMetadata : cascadingLookups) |
64 | |
{ |
65 | 0 | BrowsePanel browsePanel = new BrowsePanel (lookupMetadata); |
66 | 0 | browsePanels.add (browsePanel); |
67 | 0 | layout.add (browsePanel); |
68 | 0 | } |
69 | 0 | for (int i = 0; i < browsePanels.size () - 1; i ++) |
70 | |
{ |
71 | 0 | BrowsePanel currentBP = browsePanels.get (i); |
72 | 0 | LookupParamMetadata nextParamMetadata = this.cascadingChildParameters.get (i); |
73 | 0 | BrowsePanel nextBP = browsePanels.get (i + 1); |
74 | 0 | currentBP.setOnSelectectedCallback (new ExecuteNextSearchCallback (nextBP, nextParamMetadata)); |
75 | |
} |
76 | 0 | browsePanels.get (browsePanels.size () - 1).setOnSelectectedCallback (new ViewCourseCallback (controller)); |
77 | |
|
78 | 0 | this.initWidget (layout); |
79 | 0 | browsePanels.get (0).executeSearch (new Callback<Boolean>(){ |
80 | |
public void exec(Boolean result) { |
81 | 0 | } |
82 | |
}); |
83 | 0 | } |
84 | |
|
85 | |
private class ExecuteNextSearchCallback implements BrowsePanel.OnSelectedCallback { |
86 | |
|
87 | |
private BrowsePanel nextBrowsePanel; |
88 | |
private LookupParamMetadata nextParamMetadata; |
89 | |
|
90 | |
public ExecuteNextSearchCallback (BrowsePanel nextBrowsePanel, |
91 | 0 | LookupParamMetadata nextParamMetadata) { |
92 | 0 | this.nextBrowsePanel = nextBrowsePanel; |
93 | 0 | this.nextParamMetadata = nextParamMetadata; |
94 | 0 | } |
95 | |
|
96 | |
@Override |
97 | |
public void selected (List<String> selectedIds) { |
98 | 0 | if (selectedIds.size () == 0) { |
99 | 0 | Window.alert ("Please select a row before clicking"); |
100 | 0 | return; |
101 | |
} |
102 | 0 | Map<String, Object> parameters = new LinkedHashMap<String, Object> (); |
103 | 0 | parameters.put (nextParamMetadata.getKey (), selectedIds.get (0)); |
104 | 0 | nextBrowsePanel.setParameters (parameters); |
105 | 0 | nextBrowsePanel.executeSearch (new Callback<Boolean>(){ |
106 | |
public void exec(Boolean result) { |
107 | 0 | } |
108 | |
}); |
109 | 0 | } |
110 | |
} |
111 | |
|
112 | |
private class ViewCourseCallback implements BrowsePanel.OnSelectedCallback { |
113 | |
|
114 | |
private Controller controller; |
115 | |
|
116 | |
public ViewCourseCallback (Controller controller) |
117 | 0 | { |
118 | 0 | this.controller = controller; |
119 | 0 | } |
120 | |
|
121 | |
@Override |
122 | |
public void selected (List<String> selectedIds) { |
123 | 0 | if (selectedIds.size () == 0) { |
124 | 0 | Window.alert ("Please select a row before clicking"); |
125 | 0 | return; |
126 | |
} |
127 | 0 | ViewContext viewContext = new ViewContext (); |
128 | 0 | viewContext.setId (selectedIds.get (0)); |
129 | 0 | viewContext.setIdType (IdType.OBJECT_ID); |
130 | 0 | Application.navigate("/HOME/CURRICULUM_HOME/VIEW_COURSE", viewContext); |
131 | 0 | } |
132 | |
} |
133 | |
|
134 | |
private void addChildLookups (LookupMetadata current) { |
135 | 0 | for (LookupParamMetadata param : current.getParams ()) { |
136 | 0 | if (param.getChildLookup () != null) { |
137 | 0 | cascadingChildParameters.add (param); |
138 | 0 | cascadingLookups.add (param.getChildLookup ()); |
139 | 0 | addChildLookups (param.getChildLookup ()); |
140 | |
} |
141 | |
} |
142 | 0 | } |
143 | |
|
144 | |
} |