View Javadoc

1   /**
2    * Copyright 2005-2012 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.util;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.web.form.UifFormBase;
20  
21  import java.io.Serializable;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  /**
26   * Manages Uif form objects for a session
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class UifFormManager implements Serializable {
31      private static final long serialVersionUID = -6323378881342207080L;
32  
33      private UifFormBase currentForm;
34      private Map<String, UifFormBase> uifForms;
35  
36      public UifFormManager() {
37          this.uifForms = new HashMap<String, UifFormBase>();
38      }
39  
40      public UifFormBase getCurrentForm() {
41          return currentForm;
42      }
43  
44      public void setCurrentForm(UifFormBase currentForm) {
45          this.currentForm = currentForm;
46          addForm(currentForm);
47      }
48  
49      public void addForm(UifFormBase form) {
50          if (form == null) {
51              return;
52          }
53  
54          uifForms.put(form.getFormKey(), form);
55      }
56  
57      public UifFormBase getForm(String formKey) {
58          if (uifForms.containsKey(formKey)) {
59              return uifForms.get(formKey);
60          }
61  
62          return null;
63      }
64  
65      public void removeForm(UifFormBase form) {
66          if (form == null) {
67              return;
68          }
69  
70          removeFormByKey(form.getFormKey());
71      }
72  
73      public void removeFormByKey(String formKey) {
74          if (uifForms.containsKey(formKey)) {
75              uifForms.remove(formKey);
76          }
77  
78          if ((currentForm != null) && StringUtils.equals(currentForm.getFormKey(), formKey)) {
79              currentForm = null;
80          }
81      }
82  }