1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.util.CmsMacroResolver; 36 import org.opencms.util.CmsStringUtil; 37 38 import java.util.ArrayList ; 39 import java.util.Collections ; 40 import java.util.Iterator ; 41 import java.util.List ; 42 43 55 public abstract class A_CmsSelectWidget extends A_CmsWidget { 56 57 58 private List m_selectOptions; 59 60 63 public A_CmsSelectWidget() { 64 65 super(); 67 } 68 69 78 public A_CmsSelectWidget(List configuration) { 79 80 super(); 81 m_selectOptions = configuration; 82 } 83 84 94 public A_CmsSelectWidget(String configuration) { 95 96 super(configuration); 97 } 98 99 104 public void addSelectOption(CmsSelectWidgetOption option) { 105 106 if (m_selectOptions == null) { 107 m_selectOptions = new ArrayList (); 108 } 109 m_selectOptions.add(option); 110 } 111 112 115 public String getConfiguration() { 116 117 if (super.getConfiguration() != null) { 118 return super.getConfiguration(); 119 } 120 return CmsSelectWidgetOption.createConfigurationString(m_selectOptions); 121 } 122 123 135 protected String getSelectedValue(CmsObject cms, I_CmsWidgetParameter param) { 136 137 String paramValue = param.getStringValue(cms); 138 if (CmsStringUtil.isEmpty(paramValue)) { 139 CmsSelectWidgetOption option = CmsSelectWidgetOption.getDefaultOption(m_selectOptions); 140 if (option != null) { 141 paramValue = option.getValue(); 142 } 143 } 144 return paramValue; 145 } 146 147 159 protected List getSelectedValues(CmsObject cms, I_CmsWidgetParameter param) { 160 161 List values = new ArrayList (); 162 String paramValue = param.getStringValue(cms); 163 if (CmsStringUtil.isEmpty(paramValue)) { 164 Iterator itOptions = CmsSelectWidgetOption.getDefaultOptions(m_selectOptions).iterator(); 165 while (itOptions.hasNext()) { 166 CmsSelectWidgetOption option = (CmsSelectWidgetOption)itOptions.next(); 167 values.add(option.getValue()); 168 } 169 } else { 170 values.addAll(CmsStringUtil.splitAsList(paramValue, ',', true)); 171 } 172 return values; 173 } 174 175 182 protected List getSelectOptions() { 183 184 return m_selectOptions; 185 } 186 187 201 protected List parseSelectOptions(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 202 203 if (m_selectOptions == null) { 204 String configuration = getConfiguration(); 205 if (configuration == null) { 206 configuration = param.getDefault(cms); 208 } 209 configuration = CmsMacroResolver.resolveMacros(configuration, cms, widgetDialog.getMessages()); 210 m_selectOptions = CmsSelectWidgetOption.parseOptions(configuration); 211 if (m_selectOptions == Collections.EMPTY_LIST) { 212 m_selectOptions = new ArrayList (); 213 } 214 } 215 return m_selectOptions; 216 } 217 218 225 protected void setSelectOptions(List selectOptions) { 226 227 m_selectOptions = new ArrayList (); 228 m_selectOptions.addAll(selectOptions); 229 } 230 } | Popular Tags |