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.JspException ; 52 import javax.servlet.jsp.PageContext ; 53 54 64 public class CmsAdminWidgetDemo6 extends CmsWidgetDialog { 65 66 67 public static final int ACTION_DISPLAY_PAGE_1 = 301; 68 69 70 public static final int ACTION_DISPLAY_PAGE_2 = 302; 71 72 73 public static final String DIALOG_TYPE = "widgetdemo6"; 74 75 76 public static final String [] PAGE_ARRAY = {"page1", "page2"}; 77 78 79 public static final List PAGE_LIST = Arrays.asList(PAGE_ARRAY); 80 81 82 CmsContextInfo m_contextInfo; 83 84 85 CmsScheduledJobInfo m_jobInfo; 86 87 92 public CmsAdminWidgetDemo6(CmsJspActionElement jsp) { 93 94 super(jsp); 95 } 96 97 104 public CmsAdminWidgetDemo6(PageContext context, HttpServletRequest req, HttpServletResponse res) { 105 106 this(new CmsJspActionElement(context, req, res)); 107 } 108 109 112 public void actionCommit() { 113 114 116 } 117 118 123 public String buildDialogForm() { 124 125 StringBuffer result = new StringBuffer (1024); 126 127 try { 128 result.append(createDialogHtml()); 130 } catch (Throwable t) { 131 t.printStackTrace(); 133 } 134 return result.toString(); 135 } 136 137 142 public String dialogButtonsCustom() { 143 144 if (PAGE_ARRAY[1].equals(getParamPage())) { 145 return dialogButtons(new int[] {BUTTON_OK, BUTTON_BACK, BUTTON_CANCEL}, new String [3]); 147 } else { 148 return dialogButtons(new int[] {BUTTON_CONTINUE, BUTTON_CANCEL}, new String [2]); 149 } 150 } 151 152 155 public String getCancelAction() { 156 157 setParamPage(PAGE_ARRAY[0]); 159 160 return DIALOG_SET; 161 } 162 163 166 protected void defineWidgets() { 167 168 Object o = getSettings().getDialogObject(); 169 if (!(o instanceof CmsScheduledJobInfo)) { 170 m_jobInfo = new CmsScheduledJobInfo(); 172 m_contextInfo = new CmsContextInfo(); 173 m_jobInfo.setContextInfo(m_contextInfo); 174 } else { 175 m_jobInfo = (CmsScheduledJobInfo)o; 177 m_contextInfo = m_jobInfo.getContextInfo(); 178 } 179 180 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "jobName", PAGE_ARRAY[0], new CmsInputWidget())); 181 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "className", PAGE_ARRAY[0], new CmsInputWidget())); 182 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "cronExpression", PAGE_ARRAY[0], new CmsInputWidget())); 183 184 addWidget(new CmsWidgetDialogParameter(m_contextInfo, "userName", PAGE_ARRAY[0], new CmsInputWidget())); 185 addWidget(new CmsWidgetDialogParameter(m_contextInfo, "projectName", PAGE_ARRAY[0], new CmsInputWidget())); 186 addWidget(new CmsWidgetDialogParameter(m_contextInfo, "siteRoot", PAGE_ARRAY[0], new CmsVfsFileWidget())); 187 addWidget(new CmsWidgetDialogParameter(m_contextInfo, "requestedUri", PAGE_ARRAY[0], new CmsVfsFileWidget())); 188 addWidget(new CmsWidgetDialogParameter(m_contextInfo, "localeName", PAGE_ARRAY[1], new CmsInputWidget())); 189 addWidget(new CmsWidgetDialogParameter(m_contextInfo, "encoding", PAGE_ARRAY[1], new CmsInputWidget())); 190 addWidget(new CmsWidgetDialogParameter(m_contextInfo, "remoteAddr", PAGE_ARRAY[1], new CmsInputWidget())); 191 192 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "reuseInstance", PAGE_ARRAY[1], new CmsCheckboxWidget())); 193 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "active", PAGE_ARRAY[1], new CmsCheckboxWidget())); 194 } 195 196 199 protected String [] getPageArray() { 200 201 return PAGE_ARRAY; 202 } 203 204 207 protected void initMessages() { 208 209 addMessages(Messages.get().getBundleName()); 211 addMessages(org.opencms.workplace.demos.Messages.get().getBundleName()); 213 super.initMessages(); 214 } 215 216 219 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 220 221 setParamDialogtype(DIALOG_TYPE); 223 224 fillParamValues(request); 226 227 if (CmsStringUtil.isEmptyOrWhitespaceOnly(getParamPage()) || !PAGE_LIST.contains(getParamPage())) { 228 setParamPage(PAGE_ARRAY[0]); 230 } 231 232 defineWidgets(); 234 fillWidgetValues(request); 235 236 if (DIALOG_SAVE.equals(getParamAction())) { 238 setAction(ACTION_SAVE); 240 List errors = commitWidgetValues(); 241 if (errors.size() > 0) { 242 Iterator i = errors.iterator(); 243 while (i.hasNext()) { 244 Exception e = (Exception )i.next(); 245 System.err.println(e.getMessage()); 246 if (e.getCause() != null) { 247 System.err.println("Cause: " + e.getCause().getMessage()); 248 } 249 } 250 setAction(ACTION_DEFAULT); 251 } 252 } else if (DIALOG_OK.equals(getParamAction())) { 253 setAction(ACTION_CANCEL); 255 } else if (DIALOG_CANCEL.equals(getParamAction())) { 256 setAction(ACTION_CANCEL); 258 } else if (EDITOR_ACTION_ELEMENT_ADD.equals(getParamAction())) { 259 setAction(ACTION_ELEMENT_ADD); 260 actionToggleElement(); 261 setAction(ACTION_DEFAULT); 262 } else if (EDITOR_ACTION_ELEMENT_REMOVE.equals(getParamAction())) { 263 setAction(ACTION_ELEMENT_REMOVE); 264 actionToggleElement(); 265 setAction(ACTION_DEFAULT); 266 } else if (DIALOG_BACK.equals(getParamAction())) { 267 268 setAction(ACTION_DEFAULT); 269 List errors = commitWidgetValues(PAGE_ARRAY[1]); 270 271 if (errors.size() > 0) { 272 setAction(ACTION_ERROR); 273 try { 274 includeErrorpage(this, (Throwable )errors.get(0)); 275 } catch (JspException e) { 276 } 278 return; 279 } 280 281 setParamPage(PAGE_ARRAY[0]); 282 283 } else if (DIALOG_CONTINUE.equals(getParamAction())) { 284 285 setAction(ACTION_DEFAULT); 286 List errors = commitWidgetValues(PAGE_ARRAY[0]); 287 288 if (errors.size() > 0) { 289 setAction(ACTION_ERROR); 290 try { 291 includeErrorpage(this, (Throwable )errors.get(0)); 292 } catch (JspException e) { 293 } 295 return; 296 } 297 298 setParamPage(PAGE_ARRAY[1]); 299 300 } else { 301 setAction(ACTION_DEFAULT); 303 } 304 305 getSettings().setDialogObject(m_jobInfo); 307 } 308 } 309 | Popular Tags |