1 13 package info.magnolia.cms.gui.control; 14 15 import info.magnolia.cms.core.Content; 16 17 import java.util.ArrayList ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 21 import org.apache.commons.lang.StringUtils; 22 23 24 28 public class ButtonSet extends ControlImpl { 29 30 private static final String HTML_PRE_DIVIDED = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; 33 private static final String HTML_POST_DIVIDED = "</table>"; 35 private static final String BUTTONHTML_PRE_DIVIDED = "<tr><td>"; 37 private static final String BUTTONHTML_INTER_DIVIDED = "</td><td>"; 39 private static final String BUTTONHTML_POST_DIVIDED = "</td></tr>"; 41 43 private static final String HTML_INTER_PUSH = " "; 45 private List buttons = new ArrayList (); 46 47 private int buttonType = BUTTONTYPE_RADIO; 48 49 private String buttonHtmlPre; 51 private String buttonHtmlInter; 53 private String buttonHtmlPost; 55 public ButtonSet() { 56 } 57 58 public ButtonSet(String name, String value) { 59 super(name, value); 60 } 61 62 public ButtonSet(String name, List values) { 63 super(name, values); 64 } 65 66 public ButtonSet(String name, Content websiteNode) { 67 super(name, websiteNode); 68 } 69 70 public void setButtons(List buttons) { 71 this.buttons = buttons; 72 } 73 74 public void setButtons(Button button) { 75 this.getButtons().add(button); 76 } 77 78 public List getButtons() { 79 return this.buttons; 80 } 81 82 public void setButtonHtmlPre(String s) { 83 this.buttonHtmlPre = s; 84 } 85 86 public String getButtonHtmlPre() { 87 if (this.buttonHtmlPre == null) { 88 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 89 return StringUtils.EMPTY; 90 } 91 return BUTTONHTML_PRE_DIVIDED; 92 } 93 return this.buttonHtmlPre; 94 } 95 96 public void setButtonHtmlInter(String s) { 97 this.buttonHtmlInter = s; 98 } 99 100 public String getButtonHtmlInter() { 101 if (this.buttonHtmlInter == null) { 102 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 103 return StringUtils.EMPTY; 104 } 105 return BUTTONHTML_INTER_DIVIDED; 106 } 107 return this.buttonHtmlInter; 108 } 109 110 public void setButtonHtmlPost(String s) { 111 this.buttonHtmlPost = s; 112 } 113 114 public String getButtonHtmlPost() { 115 if (this.buttonHtmlPost == null) { 116 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 117 return StringUtils.EMPTY; 118 } 119 return BUTTONHTML_POST_DIVIDED; 120 } 121 return buttonHtmlPost; 122 123 } 124 125 public String getHtmlPre() { 126 if (super.getHtmlPre(null) == null) { 127 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 128 return StringUtils.EMPTY; 129 } 130 return HTML_PRE_DIVIDED; 131 } 132 return super.getHtmlPre(); 133 } 134 135 public String getHtmlInter() { 136 if (super.getHtmlInter(null) == null) { 137 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 138 return HTML_INTER_PUSH; 139 } 140 return StringUtils.EMPTY; 141 } 142 return super.getHtmlInter(); 143 } 144 145 public String getHtmlPost() { 146 if (super.getHtmlPost(null) == null) { 147 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 148 return StringUtils.EMPTY; 149 } 150 return HTML_POST_DIVIDED; 151 } 152 return super.getHtmlPost(); 153 154 } 155 156 public void setButtonType(int i) { 157 this.buttonType = i; 158 } 159 160 public int getButtonType() { 161 return this.buttonType; 162 } 163 164 public String getHtml() { 165 StringBuffer html = new StringBuffer (); 166 html.append(this.getHtmlPre()); 167 Iterator it = this.getButtons().iterator(); 168 int i = 0; 169 while (it.hasNext()) { 170 Button b = (Button) it.next(); 171 if (b.getName() == null) { 172 b.setName(this.getName()); 173 } 174 b.setButtonType(this.getButtonType()); 175 b.setSaveInfo(false); 176 if (b.getHtmlPre(null) == null) { 177 b.setHtmlPre(this.getButtonHtmlPre()); 178 } 179 if (b.getHtmlInter(null) == null) { 180 b.setHtmlInter(this.getButtonHtmlInter()); 181 } 182 if (b.getHtmlPost(null) == null) { 183 b.setHtmlPost(this.getButtonHtmlPost()); 184 } 185 if (StringUtils.isEmpty(b.getCssClass())) { 186 b.setCssClass(this.getCssClass()); 187 } 188 b.setId(this.getName() + "_SETBUTTON_" + i); if (this.getValueType() == ControlImpl.VALUETYPE_MULTIPLE) { 190 if (this.getValues().size() != 0) { 191 if (this.getValues().contains(b.getValue())) { 192 b.setState(BUTTONSTATE_PUSHED); 193 } 194 else { 195 b.setState(BUTTONSTATE_NORMAL); 196 } 197 } 198 } 199 else { 200 if (StringUtils.isNotEmpty(this.getValue())) { 201 if (this.getValue().equals(b.getValue())) { 202 b.setState(BUTTONSTATE_PUSHED); 203 } 204 else { 205 b.setState(BUTTONSTATE_NORMAL); 206 } 207 } 208 } 209 html.append(b.getHtml()); 210 if (it.hasNext()) { 211 html.append(this.getHtmlInter()); 212 } 213 i++; 214 } 215 html.append(this.getHtmlPost()); 216 html.append(this.getHtmlSaveInfo()); 217 return html.toString(); 218 } 219 } 220 | Popular Tags |