View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.modifier;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
19  import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.kuali.rice.krad.uif.view.View;
22  import org.kuali.rice.krad.uif.component.Component;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * Base class for <code>ComponentModifier</code> implementations
29   *
30   * <p>
31   * Holds run phase property and defaults to the INITIALIZE phase, and the order
32   * property for setting the order in which the component modifier will be
33   * invoked
34   * </p>
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public abstract class ComponentModifierBase extends UifDictionaryBeanBase implements ComponentModifier {
39  	private static final long serialVersionUID = -8284332412469942130L;
40  
41  	private String runPhase;
42  	private String runCondition;
43  	private int order;
44  
45  	public ComponentModifierBase() {
46          super();
47  
48  		runPhase = UifConstants.ViewPhases.INITIALIZE;
49  		order = 0;
50  	}
51  
52      /**
53       * Default performInitialization impl (does nothing)
54       *
55       * @see org.kuali.rice.krad.uif.modifier.ComponentModifierBase#performInitialization
56       */
57      @Override
58      public void performInitialization(View view, Object model, Component component) {
59  
60      }
61  
62      /**
63       * @see org.kuali.rice.krad.uif.modifier.ComponentModifierBase#getComponentPrototypes()
64       */
65      public List<Component> getComponentPrototypes() {
66          List<Component> components = new ArrayList<Component>();
67  
68          return components;
69      }
70  
71      /**
72  	 * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#getRunPhase()
73  	 */
74      @BeanTagAttribute(name="runPhase")
75  	public String getRunPhase() {
76  		return this.runPhase;
77  	}
78  
79  	/**
80  	 * Setter for the component initializer run phase
81  	 *
82  	 * @param runPhase
83  	 */
84  	public void setRunPhase(String runPhase) {
85  		this.runPhase = runPhase;
86  	}
87  
88  	/**
89  	 * @see org.kuali.rice.krad.uif.modifier.ComponentModifier#getRunCondition()
90  	 */
91      @BeanTagAttribute(name="runCondition")
92  	public String getRunCondition() {
93  		return this.runCondition;
94  	}
95  
96  	/**
97  	 * Setter for the component modifiers run condition
98  	 *
99  	 * @param runCondition
100 	 */
101 	public void setRunCondition(String runCondition) {
102 		this.runCondition = runCondition;
103 	}
104 
105 	/**
106 	 * @see org.springframework.core.Ordered#getOrder()
107 	 */
108     @BeanTagAttribute(name="order")
109 	public int getOrder() {
110 		return this.order;
111 	}
112 
113 	/**
114 	 * @see org.kuali.rice.krad.uif.component.Ordered#setOrder(int)
115 	 */
116 	public void setOrder(int order) {
117 		this.order = order;
118 	}
119 
120     /**
121      * Returns a clone of the component.
122      *
123      * @return ComponentBase clone of the component
124      */
125     @Override
126     public <T extends ComponentModifier> T clone() {
127         try {
128             T clonedClass = (T)this.getClass().newInstance();
129             clonedClass = (T)copyProperties(clonedClass);
130 
131             return clonedClass;
132         }
133         catch(Exception exception) {
134             throw new RuntimeException();
135         }
136     }
137 
138     protected ComponentModifierBase copyProperties(Cloneable componentModifier) {
139         ((ComponentModifierBase)componentModifier).setOrder(this.order);
140         ((ComponentModifierBase)componentModifier).setRunCondition(this.runCondition);
141         ((ComponentModifierBase)componentModifier).setRunPhase(this.runPhase);
142 
143         return (ComponentModifierBase)componentModifier;
144     }
145 }