1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.i18n.CmsEncoder; 36 import org.opencms.main.OpenCms; 37 import org.opencms.util.CmsStringUtil; 38 import org.opencms.workplace.CmsWorkplace; 39 import org.opencms.workplace.galleries.A_CmsGallery; 40 41 import java.util.ArrayList ; 42 import java.util.Collections ; 43 import java.util.HashMap ; 44 import java.util.Iterator ; 45 import java.util.List ; 46 import java.util.Map ; 47 48 59 public abstract class A_CmsHtmlWidget extends A_CmsWidget { 60 61 62 private CmsHtmlWidgetOption m_htmlWidgetOption; 63 64 67 public A_CmsHtmlWidget() { 68 69 super(); 71 } 72 73 78 public A_CmsHtmlWidget(CmsHtmlWidgetOption configuration) { 79 80 super(); 81 m_htmlWidgetOption = configuration; 82 } 83 84 89 public A_CmsHtmlWidget(String configuration) { 90 91 super(configuration); 92 } 93 94 97 public String getConfiguration() { 98 99 if (super.getConfiguration() != null) { 100 return super.getConfiguration(); 101 } 102 return CmsHtmlWidgetOption.createConfigurationString(getHtmlWidgetOption()); 103 } 104 105 110 public CmsHtmlWidgetOption getHtmlWidgetOption() { 111 112 return m_htmlWidgetOption; 113 } 114 115 118 public void setConfiguration(String configuration) { 119 120 super.setConfiguration(configuration); 121 m_htmlWidgetOption = new CmsHtmlWidgetOption(configuration); 122 } 123 124 127 public void setEditorValue( 128 CmsObject cms, 129 Map formParameters, 130 I_CmsWidgetDialog widgetDialog, 131 I_CmsWidgetParameter param) { 132 133 String [] values = (String [])formParameters.get(param.getId()); 134 if ((values != null) && (values.length > 0)) { 135 String val = CmsEncoder.decode(values[0], CmsEncoder.ENCODING_UTF_8); 136 param.setStringValue(cms, val); 137 } 138 } 139 140 145 public void setHtmlWidgetOption(CmsHtmlWidgetOption htmlWidgetOption) { 146 147 m_htmlWidgetOption = htmlWidgetOption; 148 } 149 150 164 protected String buildOpenCmsButtonRow(I_CmsWidgetDialog widgetDialog, String paramId) { 165 166 StringBuffer result = new StringBuffer (2048); 167 boolean buttonsActive = false; 169 170 result.append(buildOpenCmsButtonRow(CmsWorkplace.HTML_START, widgetDialog)); 172 173 if (getHtmlWidgetOption().showLinkDialog()) { 175 result.append(widgetDialog.button("javascript:setActiveEditor('" 176 + paramId 177 + "');openLinkDialog('" 178 + Messages.get().getBundle(widgetDialog.getLocale()).key(Messages.GUI_BUTTON_LINKTO_0) 179 + "');", null, "link", "button.linkto", widgetDialog.getButtonStyle())); 180 buttonsActive = true; 181 } 182 if (getHtmlWidgetOption().showAnchorDialog()) { 183 result.append(widgetDialog.button("javascript:setActiveEditor('" 184 + paramId 185 + "');openAnchorDialog('" 186 + Messages.get().getBundle(widgetDialog.getLocale()).key(Messages.ERR_EDITOR_MESSAGE_NOSELECTION_0) 187 + "');", null, "anchor", Messages.GUI_BUTTON_ANCHOR_0, widgetDialog.getButtonStyle())); 188 buttonsActive = true; 189 } 190 191 Map galleryMap = OpenCms.getWorkplaceManager().getGalleries(); 193 List galleries = new ArrayList (galleryMap.size()); 194 Map typeMap = new HashMap (galleryMap.size()); 195 196 Iterator i = galleryMap.keySet().iterator(); 197 while (i.hasNext()) { 198 String key = (String )i.next(); 199 A_CmsGallery currGallery = (A_CmsGallery)galleryMap.get(key); 200 galleries.add(currGallery); 201 typeMap.put(currGallery, key); 203 } 204 205 Collections.sort(galleries); 207 208 StringBuffer galleryResult = new StringBuffer (8); 209 boolean showGallery = false; 210 for (int k = 0; k < galleries.size(); k++) { 211 A_CmsGallery currGallery = (A_CmsGallery)galleries.get(k); 212 String galleryType = (String )typeMap.get(currGallery); 213 if (getHtmlWidgetOption().showGalleryDialog(galleryType)) { 214 galleryResult.append(widgetDialog.button("javascript:setActiveEditor('" 216 + paramId 217 + "');openGallery('" 218 + galleryType 219 + "');", null, galleryType, Messages.getButtonName(CmsStringUtil.substitute( 220 galleryType, 221 "gallery", 222 "")), widgetDialog.getButtonStyle())); 223 showGallery = true; 224 } 225 } 226 227 if (showGallery) { 228 if (buttonsActive) { 230 result.append(widgetDialog.buttonBarSeparator(5, 5)); 232 } 233 result.append(galleryResult); 234 buttonsActive = true; 235 } 236 237 if (!buttonsActive) { 238 return ""; 240 } 241 242 result.append(buildOpenCmsButtonRow(CmsWorkplace.HTML_END, widgetDialog)); 244 245 return result.toString(); 247 248 } 249 250 261 protected String buildOpenCmsButtonRow(int segment, I_CmsWidgetDialog widgetDialog) { 262 263 StringBuffer result = new StringBuffer (256); 264 265 if (segment == CmsWorkplace.HTML_START) { 266 result.append(widgetDialog.buttonBarHorizontalLine()); 268 result.append(widgetDialog.buttonBar(CmsWorkplace.HTML_START)); 269 result.append(widgetDialog.buttonBarStartTab(0, 0)); 270 } else { 271 result.append(widgetDialog.buttonBar(CmsWorkplace.HTML_END)); 273 result.append(widgetDialog.buttonBarHorizontalLine()); 274 } 275 276 return result.toString(); 277 } 278 } | Popular Tags |