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