View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by bobhurt on 8/23/12
16   */
17  package org.kuali.student.common.ui.krad.uif.element;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.element.Action;
22  import org.kuali.rice.krad.uif.element.Image;
23  import org.kuali.rice.krad.uif.view.View;
24  
25  import java.text.MessageFormat;
26  
27  /**
28   * Field in the form of an image-only button that presents an action that
29   * can be taken on the UI such as submitting the form or invoking a script
30   *
31   * @author Kuali Student Team
32   */
33  public class ActionImageButton extends Action {
34  
35      private String imageSource;
36      private String imageSourceOnHover;
37  
38      @Override
39      public void performFinalize(View view, Object model, Component parent) {
40          super.performFinalize(view, model, parent);
41  
42          Image img = this.getActionImage();
43          if (null == img) {  // Spring config should always include "actionImage" property
44              throw new RuntimeException("Implementation of "+ this.getClass() +" did not instantiate \"actionImage\" property.");
45          }
46  
47          if (StringUtils.isBlank(img.getSource()) && StringUtils.isNotBlank(this.imageSource)) {
48              img.setSource(this.imageSource);
49          }
50  
51          if (StringUtils.isNotBlank(this.imageSourceOnHover)) {
52              String script = MessageFormat.format("ksButtonImageChanger(this,\"{0}\");", this.imageSourceOnHover);
53              if (StringUtils.isNotBlank(this.getOnMouseOverScript())) {
54                  script += this.getOnMouseOverScript();
55              }
56              this.setOnMouseOverScript(script);
57  
58              script = MessageFormat.format("ksButtonImageChanger(this,\"{0}\");", img.getSource());
59              if (StringUtils.isNotBlank(this.getOnMouseOutScript())) {
60                  script += this.getOnMouseOutScript();
61              }
62              this.setOnMouseOutScript(script);
63          }
64      }
65  
66      public String getImageSource() {
67          return imageSource;
68      }
69      public void setImageSource(String imageSource) {
70          this.imageSource = imageSource;
71      }
72  
73      public String getImageSourceOnHover() {
74          return imageSourceOnHover;
75      }
76      public void setImageSourceOnHover(String imageSourceOnHover) {
77          this.imageSourceOnHover = imageSourceOnHover;
78      }
79  
80  }