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.configuration; |
17 | |
|
18 | |
import com.google.gwt.user.client.ui.Widget; |
19 | |
import org.kuali.student.common.ui.client.application.Application; |
20 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
21 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
22 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView; |
23 | |
import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView; |
24 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
25 | |
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
26 | |
import org.kuali.student.common.ui.client.widgets.KSErrorDialog; |
27 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; |
28 | |
import org.kuali.student.core.assembly.data.Metadata; |
29 | |
import org.kuali.student.core.assembly.data.QueryPath; |
30 | |
import org.kuali.student.lum.lu.ui.tools.client.widgets.KSBrowser; |
31 | |
|
32 | |
|
33 | 0 | public class CatalogBrowserConfigurer { |
34 | |
|
35 | |
public static final String CATALOG_BROWSER_MODEL = "CatalogBrowserModel"; |
36 | |
private DataModelDefinition modelDefinition; |
37 | |
|
38 | 0 | public enum Sections { |
39 | 0 | BROWSE_BY_SUBJECT_AREA, |
40 | 0 | BROWSE_BY_SCHOOL; |
41 | |
} |
42 | |
|
43 | |
public void setModelDefinition (DataModelDefinition modelDefinition) { |
44 | 0 | this.modelDefinition = modelDefinition; |
45 | 0 | } |
46 | |
|
47 | |
private Controller controller; |
48 | |
|
49 | |
public Controller getController () |
50 | |
{ |
51 | 0 | return controller; |
52 | |
} |
53 | |
|
54 | |
public void setController (Controller controller) |
55 | |
{ |
56 | 0 | this.controller = controller; |
57 | 0 | } |
58 | |
|
59 | |
|
60 | |
public void configureCatalogBrowser (CatalogBrowserController layout) |
61 | |
{ |
62 | |
|
63 | 0 | layout.addStyleName("browseCatalog"); |
64 | 0 | layout.setBasicTitle("Browse Course Catalog"); |
65 | 0 | layout.addTab(createBrowseBySubjectAreaSection (), "Browse By Subject Area"); |
66 | 0 | layout.addTab(createBrowseBySchoolSection (), "Browse By School"); |
67 | 0 | layout.setDefaultView(Sections.BROWSE_BY_SUBJECT_AREA); |
68 | 0 | } |
69 | |
|
70 | |
private SectionView createBrowseBySubjectAreaSection () |
71 | |
{ |
72 | 0 | VerticalSectionView nestedSectionView = |
73 | |
new VerticalSectionView (Sections.BROWSE_BY_SUBJECT_AREA, |
74 | |
"", |
75 | |
CATALOG_BROWSER_MODEL); |
76 | 0 | String fieldKey = CatalogBrowserConstants.FULLY_QUALIFIED_BY_SUBJECT_AREA; |
77 | 0 | addField (nestedSectionView, fieldKey, null, configureKSBrowser (fieldKey)); |
78 | 0 | return nestedSectionView; |
79 | |
} |
80 | |
|
81 | |
private SectionView createBrowseBySchoolSection () |
82 | |
{ |
83 | 0 | VerticalSectionView nestedSectionView = |
84 | |
new VerticalSectionView (Sections.BROWSE_BY_SCHOOL, |
85 | |
"", |
86 | |
CATALOG_BROWSER_MODEL); |
87 | 0 | String fieldKey = CatalogBrowserConstants.FULLY_QUALIFIED_BY_SCHOOL_OR_COLLEGE; |
88 | 0 | addField (nestedSectionView, fieldKey, null, configureKSBrowser (fieldKey)); |
89 | 0 | return nestedSectionView; |
90 | |
} |
91 | |
|
92 | |
private String formatMetadata (Metadata md, String fieldKey) { |
93 | 0 | String msg = "metadata for fieldKey=" + fieldKey |
94 | |
|
95 | |
+ "\n LabelKey=" + md.getLabelKey () |
96 | |
+ "\n defaultValuePath=" + md.getDefaultValuePath () |
97 | |
+ "\n LookupContextPath=" + md.getLookupContextPath () |
98 | |
|
99 | |
|
100 | |
+ "\n dataType=" + md.getDataType () |
101 | |
+ "\n defaultValue=" + md.getDefaultValue () |
102 | |
+ "\n WriteAccess=" + md.getWriteAccess () |
103 | |
+ "\n initialLookup=" + md.getInitialLookup () |
104 | |
+ "\n additionalLookups=" + md.getAdditionalLookups () |
105 | |
; |
106 | 0 | if (md.getProperties () != null) { |
107 | 0 | msg += "\n It has " + md.getProperties ().size () + " properties: \n"; |
108 | 0 | for (String fk : md.getProperties ().keySet ()) { |
109 | 0 | msg += "\n" + formatMetadata (md.getProperties ().get (fk), fk); |
110 | |
} |
111 | |
} |
112 | 0 | return msg; |
113 | |
} |
114 | |
|
115 | |
private KSBrowser configureKSBrowser (String fieldKey) |
116 | |
{ |
117 | 0 | QueryPath path = QueryPath.concat (null, fieldKey); |
118 | 0 | Metadata md = modelDefinition.getMetadata (path); |
119 | 0 | if (md == null) { |
120 | 0 | KSErrorDialog.show (new NullPointerException |
121 | |
("Invalid lookup configuration: missing field in metadata." |
122 | |
+ formatMetadata (modelDefinition.getMetadata (), fieldKey))); |
123 | 0 | return null; |
124 | |
} |
125 | 0 | if (md.getInitialLookup () == null) { |
126 | 0 | KSErrorDialog.show (new NullPointerException |
127 | |
("Invalid lookup configuration: missing initial lookup in metadata." |
128 | |
+ formatMetadata (modelDefinition.getMetadata (), fieldKey))); |
129 | 0 | return null; |
130 | |
} |
131 | 0 | KSBrowser browser = new KSBrowser (md.getInitialLookup (), controller); |
132 | 0 | return browser; |
133 | |
} |
134 | |
|
135 | |
private String getLabel (String labelKey) |
136 | |
{ |
137 | |
|
138 | |
|
139 | 0 | return Application.getApplicationContext ().getUILabel ("course", "course", "draft", labelKey); |
140 | |
} |
141 | |
|
142 | |
protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget) { |
143 | 0 | return addField(section, fieldKey, messageKey, widget, null); |
144 | |
} |
145 | |
|
146 | |
protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) { |
147 | 0 | QueryPath path = QueryPath.concat(parentPath, fieldKey); |
148 | 0 | Metadata meta = modelDefinition.getMetadata(path); |
149 | |
|
150 | 0 | FieldDescriptor fd = new FieldDescriptor(path.toString(), messageKey, meta); |
151 | 0 | if (widget != null) { |
152 | 0 | fd.setFieldWidget(widget); |
153 | |
} |
154 | 0 | section.addField(fd); |
155 | 0 | return fd; |
156 | |
} |
157 | |
|
158 | |
} |