| 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.uif.container.CollectionGroup; |
| 15 | |
import org.kuali.rice.krad.uif.container.Group; |
| 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.AttributeField; |
| 20 | |
import org.kuali.rice.krad.uif.field.Field; |
| 21 | |
import org.kuali.rice.krad.uif.field.GroupField; |
| 22 | |
import org.kuali.rice.krad.uif.field.LabelField; |
| 23 | |
import org.kuali.rice.krad.uif.field.MessageField; |
| 24 | |
import org.kuali.rice.krad.web.form.UifFormBase; |
| 25 | |
|
| 26 | |
import java.util.HashMap; |
| 27 | |
import java.util.List; |
| 28 | |
import java.util.Map; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 0 | public class ComponentFactory { |
| 37 | |
|
| 38 | 0 | private static final Map<String, Component> componentDefinitions = new HashMap<String, Component>(); |
| 39 | |
|
| 40 | |
protected static final String LABEL_FIELD = "LabelField"; |
| 41 | |
protected static final String MESSAGE_FIELD = "MessageField"; |
| 42 | |
protected static final String TEXT_CONTROL = "TextControl"; |
| 43 | |
protected static final String RADIO_GROUP_CONTROL = "RadioGroupControl"; |
| 44 | |
protected static final String RADIO_GROUP_CONTROL_HORIZONTAL = "RadioGroupControlHorizontal"; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
public static void addComponentDefinition(String componentDictionaryId, Component component) { |
| 53 | 0 | componentDefinitions.put(componentDictionaryId, ComponentUtils.copyObject(component)); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
public static Component getNewComponentInstance(String componentDictionaryId) { |
| 65 | 0 | if (componentDefinitions.containsKey(componentDictionaryId)) { |
| 66 | 0 | Component component = componentDefinitions.get(componentDictionaryId); |
| 67 | |
|
| 68 | 0 | return ComponentUtils.copyObject(component); |
| 69 | |
} |
| 70 | |
|
| 71 | 0 | return null; |
| 72 | |
} |
| 73 | |
|
| 74 | |
public static LabelField getLabelField() { |
| 75 | 0 | return (LabelField) getNewComponentInstance(LABEL_FIELD); |
| 76 | |
} |
| 77 | |
|
| 78 | |
public static MessageField getMessageField() { |
| 79 | 0 | return (MessageField) getNewComponentInstance(MESSAGE_FIELD); |
| 80 | |
} |
| 81 | |
|
| 82 | |
public static TextControl getTextControl() { |
| 83 | 0 | return (TextControl) getNewComponentInstance(TEXT_CONTROL); |
| 84 | |
} |
| 85 | |
|
| 86 | |
public static RadioGroupControl getRadioGroupControl() { |
| 87 | 0 | return (RadioGroupControl) getNewComponentInstance(RADIO_GROUP_CONTROL); |
| 88 | |
} |
| 89 | |
|
| 90 | |
public static RadioGroupControl getRadioGroupControlHorizontal() { |
| 91 | 0 | return (RadioGroupControl) getNewComponentInstance(RADIO_GROUP_CONTROL_HORIZONTAL); |
| 92 | |
} |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public static Component getComponentById(UifFormBase form, String id) { |
| 102 | 0 | Component origComponent = form.getView().getViewIndex().getComponentById(id); |
| 103 | 0 | Component component = getNewComponentInstance(origComponent.getBaseId()); |
| 104 | |
|
| 105 | 0 | return component; |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
public static Component getComponentByIdWithLifecycle(UifFormBase form, String id) { |
| 117 | 0 | Component origComponent = form.getView().getViewIndex().getComponentById(id); |
| 118 | 0 | Component component = getComponentById(form, id); |
| 119 | |
|
| 120 | 0 | form.getView().getViewHelperService().performComponentLifecycle(form, component, id); |
| 121 | |
|
| 122 | 0 | if (component instanceof Field) { |
| 123 | 0 | ((Field) component).setLabelFieldRendered(((Field) origComponent).isLabelFieldRendered()); |
| 124 | |
} |
| 125 | |
|
| 126 | 0 | if (component instanceof AttributeField) { |
| 127 | 0 | ((AttributeField) component).setBindingInfo(((AttributeField) origComponent).getBindingInfo()); |
| 128 | |
} |
| 129 | |
|
| 130 | 0 | if (component instanceof CollectionGroup) { |
| 131 | 0 | ((CollectionGroup) component).setBindingInfo(((CollectionGroup) origComponent).getBindingInfo()); |
| 132 | |
} |
| 133 | |
|
| 134 | 0 | if (component instanceof Group || component instanceof GroupField) { |
| 135 | 0 | List<AttributeField> fields = ComponentUtils.getComponentsOfTypeDeep(component, AttributeField.class); |
| 136 | 0 | String suffix = StringUtils.replaceOnce(component.getId(), component.getBaseId(), ""); |
| 137 | 0 | for (AttributeField field : fields) { |
| 138 | 0 | AttributeField origField = (AttributeField) form.getView().getViewIndex().getComponentById( |
| 139 | |
StringUtils.replaceOnce(field.getId(), field.getBaseId(), field.getBaseId() + suffix)); |
| 140 | 0 | if (origField != null) { |
| 141 | 0 | field.setBindingInfo(origField.getBindingInfo()); |
| 142 | 0 | field.setLabelFieldRendered(origField.isLabelFieldRendered()); |
| 143 | |
} |
| 144 | 0 | } |
| 145 | |
|
| 146 | 0 | List<CollectionGroup> collections = |
| 147 | |
ComponentUtils.getComponentsOfTypeDeep(component, CollectionGroup.class); |
| 148 | 0 | for (CollectionGroup collection : collections) { |
| 149 | 0 | CollectionGroup origField = (CollectionGroup) form.getView().getViewIndex().getComponentById(StringUtils |
| 150 | |
.replaceOnce(collection.getId(), collection.getBaseId(), collection.getBaseId() + suffix)); |
| 151 | 0 | if (origField != null) { |
| 152 | 0 | collection.setBindingInfo(origField.getBindingInfo()); |
| 153 | |
} |
| 154 | 0 | } |
| 155 | |
} |
| 156 | |
|
| 157 | 0 | form.getView().getViewIndex().indexComponent(component); |
| 158 | |
|
| 159 | 0 | return component; |
| 160 | |
} |
| 161 | |
|
| 162 | |
} |