View Javadoc

1   /**
2    * Copyright 2005-2014 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.core.api.exception.RiceIllegalArgumentException;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.kuali.rice.krad.uif.component.Component;
24  import org.kuali.rice.krad.uif.container.Group;
25  import org.kuali.rice.krad.uif.view.View;
26  
27  /**
28   * Allows client-side reordering of the group contents
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @BeanTag(name = "reorderer-bean", parent = "Uif-Reorderer")
33  public class Reorderer extends WidgetBase {
34      private static final long serialVersionUID = 6142957061046219120L;
35  
36      private String movableStyleClass;
37  
38      public Reorderer() {
39          super();
40      }
41  
42      /**
43       * The following initialization is performed:
44       *
45       * <ul>
46       * <li>Adds the movable style class to each group item</li>
47       * <li>Prepares the movable widget option based on the movable style class</li>
48       * </ul>
49       */
50      @Override
51      public void performFinalize(View view, Object model, Component component) {
52          super.performFinalize(view, model, component);
53  
54          if (!(component instanceof Group)) {
55              throw new RiceIllegalArgumentException("Parent component for Reorderer widget must be a group.");
56          }
57  
58          if (StringUtils.isNotBlank(movableStyleClass)) {
59              for (Component item : ((Group) component).getItems()) {
60                  item.addStyleClass(movableStyleClass);
61              }
62  
63              // add the default movable class to the selectors option if not already configured
64              if (!getTemplateOptions().containsKey(UifConstants.ReordererOptionKeys.SELECTORS)) {
65                  String selectorsOption =
66                          "{" + UifConstants.ReordererOptionKeys.MOVABLES + " : 'span." + movableStyleClass + "' }";
67                  getTemplateOptions().put(UifConstants.ReordererOptionKeys.SELECTORS, selectorsOption);
68              }
69          }
70      }
71  
72      /**
73       * Returns the style class for the item spans that will identify a movable element
74       *
75       * <p>
76       * Given style class will be used to build a jQuery selector that is then passed to the
77       * reorderer widget through the options
78       * </p>
79       *
80       * @return String style class
81       */
82      @BeanTagAttribute(name="movableStyleClass")
83      public String getMovableStyleClass() {
84          return movableStyleClass;
85      }
86  
87      /**
88       * Setter for the style class that identifies movable elements (spans)
89       *
90       * @param movableStyleClass
91       */
92      public void setMovableStyleClass(String movableStyleClass) {
93          this.movableStyleClass = movableStyleClass;
94      }
95  }