| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package org.kuali.rice.krad.uif.util; |
| 12 | |
|
| 13 | |
import org.apache.commons.lang.StringUtils; |
| 14 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
| 15 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
| 16 | |
import org.kuali.rice.krad.uif.control.RadioGroupControl; |
| 17 | |
import org.kuali.rice.krad.uif.control.TextControl; |
| 18 | |
import org.kuali.rice.krad.uif.core.Component; |
| 19 | |
import org.kuali.rice.krad.uif.field.MessageField; |
| 20 | |
import org.kuali.rice.krad.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 | |
public static Component getComponentById(String id) { |
| 87 | 0 | if (id.contains("_")) { |
| 88 | 0 | id = StringUtils.substringBefore(id, "_"); |
| 89 | |
} |
| 90 | |
|
| 91 | 0 | Component component = getNewComponentInstance(id); |
| 92 | |
|
| 93 | 0 | return component; |
| 94 | |
} |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
public static Component getComponentByIdWithLifecycle(UifFormBase form, String id) { |
| 105 | 0 | String origId = id; |
| 106 | |
|
| 107 | 0 | Component component = getComponentById(id); |
| 108 | |
|
| 109 | 0 | form.getView().getViewHelperService().performComponentLifecycle(form, component, origId); |
| 110 | 0 | form.getView().getViewIndex().indexComponent(component); |
| 111 | |
|
| 112 | 0 | return component; |
| 113 | |
} |
| 114 | |
|
| 115 | |
protected static DataDictionaryService getDataDictionaryService() { |
| 116 | 0 | return KRADServiceLocatorWeb.getDataDictionaryService(); |
| 117 | |
} |
| 118 | |
} |