View Javadoc
1   package org.kuali.ole.describe.bo.marc.structuralfields;
2   
3   import java.util.Iterator;
4   import java.util.List;
5   
6   import org.apache.log4j.Logger;
7   import org.kuali.ole.describe.form.EditorForm;
8   import org.kuali.ole.krad.OleComponent;
9   import org.kuali.ole.krad.OleComponentUtils;
10  import org.kuali.ole.krad.OleFilteredCopyGroup;
11  import org.kuali.rice.krad.uif.component.Component;
12  import org.kuali.rice.krad.uif.container.Group;
13  import org.kuali.rice.krad.uif.field.FieldGroup;
14  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
15  import org.kuali.rice.krad.uif.view.View;
16  import org.springframework.util.StringUtils;
17  
18  /**
19   * Created with IntelliJ IDEA.
20   * User: rajeshbabuk
21   * Date: 4/18/14
22   * Time: 8:12 PM
23   * To change this template use File | Settings | File Templates.
24   */
25  public class OleControlFieldGroup extends FieldGroup implements OleComponent {
26  
27      private static final long serialVersionUID = -6929025512918369521L;
28      private static final Logger LOG = Logger
29              .getLogger(OleControlFieldGroup.class);
30  
31      private String displayFieldProperty;
32      private String fieldLinkId;
33      private String controlFieldGroupId;
34  
35      @Override
36  	public String getFilterModelProperty() {
37          return ((OleFilteredCopyGroup) getGroup()).getFilterModelProperty();
38  	}
39  
40  	public void setFilterModelProperty(String filterModelProperty) {
41          ((OleFilteredCopyGroup) getGroup()).setFilterModelProperty(filterModelProperty);
42  	}
43  
44  	@Override
45      public void performInitialization(View view, Object form) {
46          super.performInitialization(view, form);
47  
48          boolean editable = "true".equals(((EditorForm) form).getEditable());
49          boolean displayField = "true".equals(ObjectPropertyUtils.getPropertyValue(form,
50                  displayFieldProperty));
51          LOG.info("editable " + editable + " displayField " + displayField);
52  
53          List<? extends Component> items = getItems();
54          LOG.info("initialize " + displayFieldProperty + " "
55                  + fieldLinkId + " " + controlFieldGroupId);
56          if (StringUtils.isEmpty(displayFieldProperty)) {
57              LOG.info("skip iterator");
58          } else {
59  
60              Iterator<? extends Component> itemIterator = items.iterator();
61              while (itemIterator.hasNext()) {
62                  Component component = itemIterator.next();
63                  if (component == null) {
64                      continue;
65                  }
66  
67                  LOG.info("checking component " + component.getId());
68  
69                  // @{editable eq 'true' and displayField008 eq 'false'}
70                  if (fieldLinkId != null
71                          && fieldLinkId.equals(component.getId())
72                          && (!editable || displayField)) {
73                      LOG.info("Omitting " + fieldLinkId + " from lifecycle");
74                      itemIterator.remove();
75                  }
76  
77                  // @{editable eq 'true' and displayField008 eq 'true'}
78                  if (controlFieldGroupId != null
79                          && controlFieldGroupId.equals(component.getId())
80                          && (!editable || !displayField)) {
81                      LOG.info("Omitting " + controlFieldGroupId
82                              + " from lifecycle");
83                      itemIterator.remove();
84                  }
85              }
86          }
87      }
88  
89      public String getDisplayFieldProperty() {
90          return displayFieldProperty;
91      }
92  
93      public void setDisplayFieldProperty(String displayFieldProperty) {
94          this.displayFieldProperty = displayFieldProperty;
95      }
96  
97      public String getFieldLinkId() {
98          return fieldLinkId;
99      }
100 
101     public void setFieldLinkId(String fieldLinkId) {
102         this.fieldLinkId = fieldLinkId;
103     }
104 
105     public String getControlFieldGroupId() {
106         return controlFieldGroupId;
107     }
108 
109     public void setControlFieldGroupId(String controlFieldGroupId) {
110         this.controlFieldGroupId = controlFieldGroupId;
111     }
112 
113     @Override
114     protected <T> void copyProperties(T component) {
115         super.copyProperties(component);
116 
117         OleControlFieldGroup copy = (OleControlFieldGroup) component;
118         copy.displayFieldProperty = displayFieldProperty;
119         copy.fieldLinkId = fieldLinkId;
120         copy.controlFieldGroupId = controlFieldGroupId;
121     }
122 
123 }