View Javadoc

1   /**
2    * Copyright 2005-2015 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.widget;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  /**
26   * Growls sets up settings for growls global to the current view and its pages
27   *
28   * <p>
29   * Some basic options of the plugin are exposed through this class, however additional options
30   * can be passed through setComponentOptions as usual. However, the header and theme option is set
31   * by the growl processing in PageGroup automatically. See the jquery jGrowl plugin for more details.
32   * </p>
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @BeanTag(name = "growls-bean", parent = "Uif-Growls")
37  public class Growls extends WidgetBase {
38      private static final long serialVersionUID = -8701090110933484411L;
39  
40      private boolean sticky;
41      private int timeShown;
42      private String position;
43  
44      public Growls() {
45          super();
46      }
47  
48      /**
49       * Override to add property values to the template options
50       *
51       * @see org.kuali.rice.krad.uif.component.Component#getTemplateOptions()
52       */
53      @Override
54      public Map<String, String> getTemplateOptions() {
55          Map<String, String> templateOptions = super.getTemplateOptions();
56  
57          if (templateOptions == null) {
58              super.setTemplateOptions(templateOptions = new HashMap<String, String>());
59          }
60  
61          if (!templateOptions.containsKey("sticky")) {
62              templateOptions.put("sticky", Boolean.toString(sticky));
63          }
64          if (!templateOptions.containsKey("life")) {
65              templateOptions.put("life", Integer.toString(timeShown));
66          }
67          if (StringUtils.isNotBlank(position) && !templateOptions.containsKey("position")) {
68              templateOptions.put("position", position);
69          }
70  
71          return templateOptions;
72      }
73  
74      /**
75       * If true, the growl will stick to the page until the user dismisses it
76       *
77       * @return the sticky
78       */
79      @BeanTagAttribute(name="sticky")
80      public boolean isSticky() {
81          return this.sticky;
82      }
83  
84      /**
85       * @param sticky the sticky to set
86       */
87      public void setSticky(boolean sticky) {
88          this.sticky = sticky;
89      }
90  
91      /**
92       * The time growls are shown in milliseconds
93       *
94       * @return the timeShown
95       */
96      @BeanTagAttribute(name="timeShown")
97      public int getTimeShown() {
98          return this.timeShown;
99      }
100 
101     /**
102      * @param timeShown the timeShown to set
103      */
104     public void setTimeShown(int timeShown) {
105         this.timeShown = timeShown;
106     }
107 
108     /**
109      * The position for the growls to appear in the window
110      * There are five options available: top-left, top-right, bottom-left, bottom-right, center.
111      *
112      * @return the position
113      */
114     @BeanTagAttribute(name="position")
115     public String getPosition() {
116         return this.position;
117     }
118 
119     /**
120      * @param position the position to set
121      */
122     public void setPosition(String position) {
123         this.position = position;
124     }
125 
126     /**
127      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
128      */
129     @Override
130     protected <T> void copyProperties(T component) {
131         super.copyProperties(component);
132         Growls growlsCopy = (Growls) component;
133         growlsCopy.setSticky(this.isSticky());
134         growlsCopy.setTimeShown(this.getTimeShown());
135         growlsCopy.setPosition(this.getPosition());
136     }
137 }