1 31 32 package org.opencms.workplace.demos.widget; 33 34 import org.opencms.jsp.CmsJspActionElement; 35 import org.opencms.main.CmsContextInfo; 36 import org.opencms.scheduler.CmsScheduledJobInfo; 37 import org.opencms.util.CmsStringUtil; 38 import org.opencms.widgets.CmsCheckboxWidget; 39 import org.opencms.widgets.CmsInputWidget; 40 import org.opencms.widgets.CmsVfsFileWidget; 41 import org.opencms.workplace.CmsWidgetDialog; 42 import org.opencms.workplace.CmsWidgetDialogParameter; 43 import org.opencms.workplace.CmsWorkplaceSettings; 44 45 import java.util.Arrays ; 46 import java.util.Iterator ; 47 import java.util.List ; 48 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 51 import javax.servlet.jsp.PageContext ; 52 53 63 public class CmsAdminWidgetDemo8 extends CmsWidgetDialog { 64 65 66 public static final int ACTION_DISPLAY_PAGE_1 = 301; 67 68 69 public static final int ACTION_DISPLAY_PAGE_2 = 302; 70 71 72 public static final String DIALOG_TYPE = "widgetdemo8"; 73 74 75 public static final String [] PAGES = {"page1", "page2"}; 76 77 78 public static final List PAGE_LIST = Arrays.asList(PAGES); 79 80 81 protected CmsScheduledJobInfo m_jobInfo; 82 83 88 public CmsAdminWidgetDemo8(CmsJspActionElement jsp) { 89 90 super(jsp); 91 } 92 93 100 public CmsAdminWidgetDemo8(PageContext context, HttpServletRequest req, HttpServletResponse res) { 101 102 this(new CmsJspActionElement(context, req, res)); 103 } 104 105 108 public void actionCommit() { 109 110 112 } 113 114 119 public String buildDialogForm() { 120 121 StringBuffer result = new StringBuffer (1024); 122 123 try { 124 125 result.append(createDialogHtml(getParamPage())); 127 128 } catch (Throwable t) { 129 } 131 return result.toString(); 132 } 133 134 139 public String dialogButtonsCustom() { 140 141 if (PAGES[1].equals(getParamPage())) { 142 return dialogButtons(new int[] {BUTTON_OK, BUTTON_BACK, BUTTON_CANCEL}, new String [3]); 144 } else { 145 return dialogButtons(new int[] {BUTTON_CONTINUE, BUTTON_CANCEL}, new String [2]); 146 } 147 } 148 149 152 public String getCancelAction() { 153 154 setParamPage(PAGES[0]); 156 157 return DIALOG_SET; 158 } 159 160 163 protected void defineWidgets() { 164 165 Object o = getDialogObject(); 166 167 CmsContextInfo dC = new CmsContextInfo(); 169 170 if (!(o instanceof CmsScheduledJobInfo)) { 171 m_jobInfo = new CmsScheduledJobInfo(); 173 m_jobInfo.setContextInfo(dC); 174 175 m_jobInfo.getParameters().put("key1", "value1"); 177 m_jobInfo.getParameters().put("key2", "value2"); 178 179 } else { 180 m_jobInfo = (CmsScheduledJobInfo)o; 182 } 183 184 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "jobName", PAGES[0], new CmsInputWidget())); 185 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "className", PAGES[0], new CmsInputWidget())); 186 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "cronExpression", PAGES[0], new CmsInputWidget())); 187 188 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "contextInfo.userName", PAGES[0], new CmsInputWidget())); 189 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "contextInfo.projectName", PAGES[0], new CmsInputWidget())); 190 addWidget(new CmsWidgetDialogParameter( 191 m_jobInfo, 192 "contextInfo.siteRoot", 193 dC.getSiteRoot(), 194 PAGES[0], 195 new CmsVfsFileWidget(), 196 0, 197 1)); 198 addWidget(new CmsWidgetDialogParameter( 199 m_jobInfo, 200 "contextInfo.requestedUri", 201 dC.getRequestedUri(), 202 PAGES[0], 203 new CmsVfsFileWidget(), 204 0, 205 1)); 206 addWidget(new CmsWidgetDialogParameter( 207 m_jobInfo, 208 "contextInfo.localeName", 209 dC.getLocaleName(), 210 PAGES[0], 211 new CmsInputWidget(), 212 0, 213 1)); 214 addWidget(new CmsWidgetDialogParameter( 215 m_jobInfo, 216 "contextInfo.encoding", 217 dC.getEncoding(), 218 PAGES[0], 219 new CmsInputWidget(), 220 0, 221 1)); 222 addWidget(new CmsWidgetDialogParameter( 223 m_jobInfo, 224 "contextInfo.remoteAddr", 225 dC.getRemoteAddr(), 226 PAGES[0], 227 new CmsInputWidget(), 228 0, 229 1)); 230 231 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "reuseInstance", PAGES[0], new CmsCheckboxWidget())); 232 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "active", PAGES[0], new CmsCheckboxWidget())); 233 234 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "parameters", PAGES[1], new CmsInputWidget())); 235 } 236 237 240 protected String [] getPageArray() { 241 242 return PAGES; 243 } 244 245 248 protected void initMessages() { 249 250 addMessages(Messages.get().getBundleName()); 252 addMessages(org.opencms.workplace.demos.Messages.get().getBundleName()); 254 super.initMessages(); 255 } 256 257 260 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 261 262 setParamDialogtype(DIALOG_TYPE); 264 265 fillParamValues(request); 267 268 if (CmsStringUtil.isEmptyOrWhitespaceOnly(getParamPage()) || !PAGE_LIST.contains(getParamPage())) { 269 setParamPage(PAGES[0]); 271 } 272 273 defineWidgets(); 275 fillWidgetValues(request); 276 277 if (DIALOG_SAVE.equals(getParamAction())) { 279 setAction(ACTION_SAVE); 281 List errors = commitWidgetValues(); 282 if (errors.size() > 0) { 283 Iterator i = errors.iterator(); 284 while (i.hasNext()) { 285 Exception e = (Exception )i.next(); 286 System.err.println(e.getMessage()); 287 if (e.getCause() != null) { 288 System.err.println("Cause: " + e.getCause().getMessage()); 289 } 290 } 291 setAction(ACTION_DEFAULT); 292 } 293 } else if (DIALOG_OK.equals(getParamAction())) { 294 setAction(ACTION_CANCEL); 296 } else if (DIALOG_CANCEL.equals(getParamAction())) { 297 setAction(ACTION_CANCEL); 299 } else if (EDITOR_ACTION_ELEMENT_ADD.equals(getParamAction())) { 300 setAction(ACTION_ELEMENT_ADD); 301 actionToggleElement(); 302 setAction(ACTION_DEFAULT); 303 } else if (EDITOR_ACTION_ELEMENT_REMOVE.equals(getParamAction())) { 304 setAction(ACTION_ELEMENT_REMOVE); 305 actionToggleElement(); 306 setAction(ACTION_DEFAULT); 307 } else if (DIALOG_BACK.equals(getParamAction())) { 308 309 setAction(ACTION_DEFAULT); 310 List errors = commitWidgetValues(PAGES[1]); 311 if (errors.size() > 0) { 312 return; 313 } 314 315 setParamPage(PAGES[0]); 316 317 } else if (DIALOG_CONTINUE.equals(getParamAction())) { 318 319 setAction(ACTION_DEFAULT); 320 List errors = commitWidgetValues(PAGES[0]); 321 if (errors.size() > 0) { 322 return; 323 } 324 325 setParamPage(PAGES[1]); 326 327 } else { 328 setAction(ACTION_DEFAULT); 330 } 331 332 setDialogObject(m_jobInfo); 334 } 335 336 } 337 | Popular Tags |