1 /** 2 * This file Copyright (c) 2003-2010 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.cms.gui.controlx.search; 35 36 import org.apache.commons.lang.StringUtils; 37 38 39 /** 40 * @author Philipp Bracher 41 * @version $Revision: 34820 $ ($Author: gjoseph $) 42 */ 43 public class SearchControlDefinition { 44 45 /** 46 * The name of the definition 47 */ 48 private String name; 49 50 /** 51 * Normaly the same as the name of the field, but used to build the query 52 */ 53 private String column; 54 55 /** 56 * Display name 57 */ 58 private String label; 59 60 /** 61 * Used for the rendering in javascript. 62 */ 63 private String type; 64 65 /** 66 * Default type is edit. 67 */ 68 public SearchControlDefinition() { 69 setType("edit"); 70 } 71 72 public SearchControlDefinition(String name, String label) { 73 this(name, label, "edit"); 74 } 75 76 public SearchControlDefinition(String name, String label, String type) { 77 setName(name); 78 setLabel(label); 79 setType(type); 80 } 81 82 public String getJsField() { 83 return this.getName() 84 + ": {name:'" 85 + this.getName() 86 + "', label:'" 87 + this.getLabel() 88 + "', type:'" 89 + this.getType() 90 + "'}"; 91 } 92 93 public SearchControl getSearchControlInstance(String value, String constraint) { 94 if (this.type.equals("date")) { 95 return new DateSearchControl(this, value, constraint); 96 } 97 98 return new SearchControl(this, value, constraint); 99 } 100 101 /** 102 * @return Returns the type. 103 */ 104 public String getType() { 105 return this.type; 106 } 107 108 /** 109 * @param type The type to set. 110 */ 111 public void setType(String type) { 112 this.type = type; 113 } 114 115 /** 116 * @return Returns the label. 117 */ 118 public String getLabel() { 119 return this.label; 120 } 121 122 /** 123 * @param label The label to set. 124 */ 125 public void setLabel(String label) { 126 this.label = label; 127 } 128 129 /** 130 * @return Returns the name. 131 */ 132 public String getName() { 133 return this.name; 134 } 135 136 /** 137 * @param name The name to set. 138 */ 139 public void setName(String name) { 140 if (StringUtils.isEmpty(this.getColumn())) { 141 this.setColumn(name); 142 } 143 // avoid broken javascripts 144 this.name = StringUtils.replace(name, ":", "_"); 145 } 146 147 /** 148 * @return Returns the column. 149 */ 150 public String getColumn() { 151 return this.column; 152 } 153 154 /** 155 * @param column The column to set. 156 */ 157 public void setColumn(String column) { 158 this.column = column; 159 } 160 161 }