1 31 32 package org.opencms.widgets; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.main.OpenCms; 36 import org.opencms.util.CmsStringUtil; 37 import org.opencms.workplace.CmsWorkplace; 38 39 48 public class CmsGroupWidget extends A_CmsWidget { 49 50 51 public static final String CONFIGURATION_FLAGS = "flags"; 52 53 54 public static final String CONFIGURATION_USER = "user"; 55 56 57 private Integer m_flags; 58 59 60 private String m_userName; 61 62 65 public CmsGroupWidget() { 66 67 this(""); 69 } 70 71 77 public CmsGroupWidget(Integer flags, String userName) { 78 79 m_flags = flags; 80 m_userName = userName; 81 } 82 83 88 public CmsGroupWidget(String configuration) { 89 90 super(configuration); 91 } 92 93 96 public String getConfiguration() { 97 98 StringBuffer result = new StringBuffer (8); 99 100 if (m_flags != null) { 102 if (result.length() > 0) { 103 result.append("|"); 104 } 105 result.append(CONFIGURATION_FLAGS); 106 result.append("="); 107 result.append(m_flags); 108 } 109 if (m_userName != null) { 111 if (result.length() > 0) { 112 result.append("|"); 113 } 114 result.append(CONFIGURATION_USER); 115 result.append("="); 116 result.append(m_userName); 117 } 118 return result.toString(); 119 } 120 121 124 public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) { 125 126 StringBuffer result = new StringBuffer (16); 127 result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/groupselector.js")); 128 return result.toString(); 129 } 130 131 134 public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) { 135 136 String id = param.getId(); 137 StringBuffer result = new StringBuffer (128); 138 139 result.append("<td class=\"xmlTd\">"); 140 result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">"); 141 result.append("<input style=\"width: 99%;\" class=\"xmlInput"); 142 if (param.hasError()) { 143 result.append(" xmlInputError"); 144 } 145 result.append("\" value=\""); 146 result.append(param.getStringValue(cms)); 147 result.append("\" name=\""); 148 result.append(id); 149 result.append("\" id=\""); 150 result.append(id); 151 result.append("\"></td>"); 152 result.append(widgetDialog.dialogHorizontalSpacer(10)); 153 result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>"); 154 155 StringBuffer buttonJs = new StringBuffer (8); 156 buttonJs.append("javascript:openGroupWin('"); 157 buttonJs.append(OpenCms.getSystemInfo().getOpenCmsContext()); 158 buttonJs.append("/system/workplace/commons/group_selection.jsp"); 159 buttonJs.append("','EDITOR', '"); 160 buttonJs.append(id); 161 buttonJs.append("', document, '"); 162 if (m_flags != null) { 163 buttonJs.append(m_flags); 164 } else { 165 buttonJs.append("null"); 166 } 167 buttonJs.append("', '"); 168 if (m_userName != null) { 169 buttonJs.append(m_userName); 170 } else { 171 buttonJs.append("null"); 172 } 173 buttonJs.append("'"); 174 buttonJs.append(");"); 175 176 result.append(widgetDialog.button( 177 buttonJs.toString(), 178 null, 179 "group", 180 org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0, 181 widgetDialog.getButtonStyle())); 182 result.append("</tr></table>"); 183 result.append("</td></tr></table>"); 184 185 result.append("</td>"); 186 187 return result.toString(); 188 } 189 190 195 public Integer getFlags() { 196 197 return m_flags; 198 } 199 200 205 public String getUserName() { 206 207 return m_userName; 208 } 209 210 213 public I_CmsWidget newInstance() { 214 215 return new CmsGroupWidget(getConfiguration()); 216 } 217 218 221 public void setConfiguration(String configuration) { 222 223 m_userName = null; 224 m_flags = null; 225 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) { 226 int flagsIndex = configuration.indexOf(CONFIGURATION_FLAGS); 227 if (flagsIndex != -1) { 228 String flags = configuration.substring(CONFIGURATION_FLAGS.length() + 1); 230 if (flags.indexOf('|') != -1) { 231 flags = flags.substring(0, flags.indexOf('|')); 233 } 234 try { 235 m_flags = Integer.valueOf(flags); 236 } catch (Throwable t) { 237 } 239 } 240 int groupIndex = configuration.indexOf(CONFIGURATION_USER); 241 if (groupIndex != -1) { 242 String user = configuration.substring(CONFIGURATION_USER.length() + 1); 244 if (user.indexOf('|') != -1) { 245 user = user.substring(0, user.indexOf('|')); 247 } 248 m_userName = user; 249 } 250 } 251 super.setConfiguration(configuration); 252 } 253 } | Popular Tags |