1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.util.CmsMacroResolver; 36 37 import java.util.Iterator ; 38 import java.util.List ; 39 40 59 public class CmsSelectWidget extends A_CmsSelectWidget { 60 61 64 public CmsSelectWidget() { 65 66 super(); 68 } 69 70 79 public CmsSelectWidget(List configuration) { 80 81 super(configuration); 82 } 83 84 89 public CmsSelectWidget(String configuration) { 90 91 super(configuration); 92 } 93 94 97 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 98 99 String id = param.getId(); 100 StringBuffer result = new StringBuffer (16); 101 102 result.append("<td class=\"xmlTd\" style=\"height: 25px;\"><select class=\"xmlInput"); 103 if (param.hasError()) { 104 result.append(" xmlInputError"); 105 } 106 result.append("\" name=\""); 107 result.append(id); 108 result.append("\" id=\""); 109 result.append(id); 110 result.append("\">"); 111 112 List options = parseSelectOptions(cms, widgetDialog, param); 114 String selected = getSelectedValue(cms, param); 115 Iterator i = options.iterator(); 116 while (i.hasNext()) { 117 CmsSelectWidgetOption option = (CmsSelectWidgetOption)i.next(); 118 result.append("<option value=\""); 120 result.append(option.getValue()); 121 result.append("\""); 122 if ((selected != null) && selected.equals(option.getValue())) { 123 result.append(" selected=\"selected\""); 124 } 125 result.append(">"); 126 result.append(option.getOption()); 127 result.append("</option>"); 128 } 129 130 result.append("</select>"); 131 result.append("</td>"); 132 133 return result.toString(); 134 } 135 136 139 public String getWidgetStringValue(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 140 141 String result = super.getWidgetStringValue(cms, widgetDialog, param); 142 String configuration = CmsMacroResolver.resolveMacros(getConfiguration(), cms, widgetDialog.getMessages()); 143 if (configuration == null) { 144 configuration = param.getDefault(cms); 145 } 146 List options = CmsSelectWidgetOption.parseOptions(configuration); 147 for (int m = 0; m < options.size(); m++) { 148 CmsSelectWidgetOption option = (CmsSelectWidgetOption)options.get(m); 149 if (result.equals(option.getValue())) { 150 result = option.getOption(); 151 break; 152 } 153 } 154 return result; 155 } 156 157 160 public I_CmsWidget newInstance() { 161 162 return new CmsSelectWidget(getConfiguration()); 163 } 164 } | Popular Tags |