1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.kuali.rice.kns.uif.util; |
12 | |
|
13 | |
import org.apache.commons.lang.StringUtils; |
14 | |
import org.kuali.rice.kns.service.DataDictionaryService; |
15 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
16 | |
import org.kuali.rice.kns.uif.control.RadioGroupControl; |
17 | |
import org.kuali.rice.kns.uif.control.TextControl; |
18 | |
import org.kuali.rice.kns.uif.core.Component; |
19 | |
import org.kuali.rice.kns.uif.field.MessageField; |
20 | |
import org.kuali.rice.kns.web.spring.form.UifFormBase; |
21 | |
|
22 | |
import java.util.HashMap; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class ComponentFactory { |
32 | |
|
33 | 0 | private static final Map<String, Component> componentDefinitions = new HashMap<String, Component>(); |
34 | |
|
35 | |
protected static final String MESSAGE_FIELD = "MessageField"; |
36 | |
protected static final String TEXT_CONTROL = "TextControl"; |
37 | |
protected static final String RADIO_GROUP_CONTROL = "RadioGroupControl"; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public static void addComponentDefinition(String componentDictionaryId, Component component) { |
46 | 0 | componentDefinitions.put(componentDictionaryId, ComponentUtils.copyObject(component)); |
47 | 0 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public static Component getNewComponentInstance(String componentDictionaryId) { |
58 | 0 | if (componentDefinitions.containsKey(componentDictionaryId)) { |
59 | 0 | Component component = componentDefinitions.get(componentDictionaryId); |
60 | |
|
61 | 0 | return ComponentUtils.copyObject(component); |
62 | |
} |
63 | |
|
64 | 0 | return null; |
65 | |
} |
66 | |
|
67 | |
public static MessageField getMessageField() { |
68 | 0 | return (MessageField) getNewComponentInstance(MESSAGE_FIELD); |
69 | |
} |
70 | |
|
71 | |
public static TextControl getTextControl() { |
72 | 0 | return (TextControl) getNewComponentInstance(TEXT_CONTROL); |
73 | |
} |
74 | |
|
75 | |
public static RadioGroupControl getRadioGroupControl() { |
76 | 0 | return (RadioGroupControl) getNewComponentInstance(RADIO_GROUP_CONTROL); |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public static Component getComponentById(UifFormBase form, String id) { |
88 | 0 | String origId = id; |
89 | |
|
90 | 0 | if (id.contains("_")) { |
91 | 0 | id = StringUtils.substringBefore(id, "_"); |
92 | |
} |
93 | 0 | Component component = getNewComponentInstance(id); |
94 | |
|
95 | 0 | form.getView().getViewHelperService().performComponentLifecycle(form, component, origId); |
96 | 0 | form.getView().getViewIndex().indexComponent(component); |
97 | 0 | return component; |
98 | |
} |
99 | |
|
100 | |
protected static DataDictionaryService getDataDictionaryService() { |
101 | 0 | return KNSServiceLocatorWeb.getDataDictionaryService(); |
102 | |
} |
103 | |
} |