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