View Javadoc
1   package org.kuali.ole.krad;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.apache.log4j.Logger;
7   import org.kuali.rice.krad.uif.component.Component;
8   import org.kuali.rice.krad.uif.container.Group;
9   import org.kuali.rice.krad.uif.container.PageGroup;
10  import org.kuali.rice.krad.uif.view.FormView;
11  
12  public class OleFormView extends FormView {
13  
14  	private static final long serialVersionUID = 153071280080228636L;
15  	private static final Logger LOG = Logger.getLogger(OleFormView.class);
16  
17  	private List<? extends Group> originalItems;
18  
19  	@Override
20  	public List<Component> getComponentsForLifecycle() {
21  		List<Component> rv = super.getComponentsForLifecycle();
22  
23  		if (LOG.isDebugEnabled()) {
24  			StringBuilder sb = new StringBuilder("Components for lifecycle:");
25  			sb.append("\n  currentPageId = ").append(getCurrentPageId());
26  			sb.append("\n  singlePageView? ").append(isSinglePageView());
27  			if (rv == null)
28  				sb.append(" NULL!");
29  			else
30  				for (Component comp : rv)
31  					if (comp == null)
32  						sb.append("\n     NULL!");
33  					else
34  						sb.append("\n   - ").append(comp.getClass())
35  								.append(" ").append(comp.getId());
36  			sb.append("\nMy items are:");
37  			List<? extends Component> items = getItems();
38  			if (items == null)
39  				sb.append(" NULL!");
40  			else
41  				for (Component comp : items)
42  					if (comp == null)
43  						sb.append("\n     NULL!");
44  					else {
45  						sb.append("\n   - ").append(comp.getClass())
46  								.append(" ").append(comp.getId());
47  						if (rv != null)
48  							sb.append(" -> ").append(rv.contains(comp));
49  					}
50  			LOG.debug(sb);
51  		}
52  
53  		return rv;
54  	}
55  
56  	@Override
57  	public void setCurrentPageId(String currentPageId) {
58  		if (originalItems != null)
59  			setItems(new ArrayList<Group>());
60  		super.setCurrentPageId(currentPageId);
61  	}
62  
63  	private boolean itemsBusy = false;
64  
65  	@Override
66  	public List<? extends Group> getItems() {
67  		synchronized (this) {
68  			if (itemsBusy)
69  				return originalItems;
70  	
71  			List<? extends Group> rv = super.getItems();
72  			if ((rv == null || rv.isEmpty()) && originalItems != null) {
73  				itemsBusy = true;
74  				try {
75  					setItems(rv = OleComponentUtils.filterCurrentPage(
76  							getCurrentPageId(), originalItems));
77  				} finally {
78  					itemsBusy = false;
79  				}
80  	
81  				if (LOG.isDebugEnabled()) {
82  					StringBuilder sb = new StringBuilder("Lazy init items:");
83  					if (rv == null)
84  						sb.append(" NULL!");
85  					else
86  						for (Group comp : rv)
87  							if (comp == null)
88  								sb.append("\n     NULL!");
89  							else
90  								sb.append("\n   - ").append(comp.getClass())
91  										.append(" ").append(comp.getId());
92  					LOG.debug(sb, new Throwable());
93  				}
94  			}
95  			return rv;
96  		}
97  	}
98  
99  	/**
100 	 * Filters {@link PageGroup} instances based on the pageId property if an
101 	 * active form is available.
102 	 */
103 	@Override
104 	protected <T> void copyProperties(T component) {
105 		List<? extends Group> srcitems;
106 
107 		synchronized (this) {
108 			srcitems = getItems();
109 			try {
110 				setItems(null);
111 				super.copyProperties(component);
112 			} finally {
113 				setItems(srcitems);
114 			}
115 		}
116 
117 		OleFormView copyView = (OleFormView) component;
118 		copyView.setItems(new ArrayList<Group>());
119 		copyView.originalItems = srcitems;
120 	}
121 
122 }
123