001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH (https://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.acacia.client.widgets.serialdate; 029 030import org.opencms.acacia.shared.I_CmsSerialDateValue.Month; 031import org.opencms.acacia.shared.I_CmsSerialDateValue.PatternType; 032import org.opencms.acacia.shared.I_CmsSerialDateValue.WeekDay; 033import org.opencms.acacia.shared.I_CmsSerialDateValue.WeekOfMonth; 034import org.opencms.ade.contenteditor.client.Messages; 035import org.opencms.gwt.client.ui.input.CmsRadioButton; 036import org.opencms.gwt.client.ui.input.CmsRadioButtonGroup; 037import org.opencms.gwt.client.ui.input.CmsSelectBox; 038 039import com.google.gwt.core.shared.GWT; 040import com.google.gwt.event.dom.client.FocusEvent; 041import com.google.gwt.event.logical.shared.ValueChangeEvent; 042import com.google.gwt.event.logical.shared.ValueChangeHandler; 043import com.google.gwt.uibinder.client.UiBinder; 044import com.google.gwt.uibinder.client.UiField; 045import com.google.gwt.uibinder.client.UiHandler; 046import com.google.gwt.user.client.ui.Composite; 047import com.google.gwt.user.client.ui.HTMLPanel; 048import com.google.gwt.user.client.ui.Label; 049 050/** 051 * The yearly pattern panel.<p> 052 */ 053public class CmsPatternPanelYearlyView extends Composite implements I_CmsSerialDatePatternView { 054 055 /** The UI binder interface. */ 056 interface I_CmsPatternPanelYearlyUiBinder extends UiBinder<HTMLPanel, CmsPatternPanelYearlyView> { 057 // nothing to do 058 } 059 060 /** Name of the "every x. day in month" radio button. */ 061 private static final String DAYS_RADIOBUTTON = "everyday"; 062 063 /** Name of the "at weeks" radio button. */ 064 private static final String WEEKS_RADIOBUTTON = "everyweek"; 065 066 /** The UI binder instance. */ 067 private static I_CmsPatternPanelYearlyUiBinder uiBinder = GWT.create(I_CmsPatternPanelYearlyUiBinder.class); 068 069 /* UI elements for "every x. day of month in year" */ 070 071 /** The text box for the date input. */ 072 @UiField 073 CmsFocusAwareTextBox m_everyDay; 074 /** The select box for the month selection. */ 075 @UiField 076 CmsSelectBox m_everyMonth; 077 078 /** The every radio button. */ 079 @UiField(provided = true) 080 CmsRadioButton m_everyRadioButton; 081 082 /* UI elements for "every x. weekday in month in year" */ 083 /** The select box for the day selection. */ 084 @UiField 085 CmsSelectBox m_atDay; 086 087 /** The select box for the month selection. */ 088 @UiField 089 CmsSelectBox m_atMonth; 090 /** The select box for the numeric selection. */ 091 @UiField 092 CmsSelectBox m_atNumber; 093 094 /** The at radio button. */ 095 @UiField(provided = true) 096 CmsRadioButton m_atRadioButton; 097 098 /** The in label. */ 099 @UiField 100 Label m_labelIn; 101 102 /** Group off all radio buttons. */ 103 private CmsRadioButtonGroup m_group; 104 105 /** The model to read the data from. */ 106 private final I_CmsObservableSerialDateValue m_model; 107 108 /** The controller to handle changes. */ 109 final CmsPatternPanelYearlyController m_controller; 110 111 /** Flag, indicating if change actions should not be triggered. */ 112 private boolean m_triggerChangeActions = true; 113 114 /** 115 * Default constructor to create the panel.<p> 116 * @param controller the controller that handles value changes. 117 * @param model the model that provides the values. 118 */ 119 public CmsPatternPanelYearlyView(CmsPatternPanelYearlyController controller, I_CmsObservableSerialDateValue model) { 120 121 m_controller = controller; 122 m_model = model; 123 m_model.registerValueChangeObserver(this); 124 125 m_group = new CmsRadioButtonGroup(); 126 m_everyRadioButton = new CmsRadioButton( 127 DAYS_RADIOBUTTON, 128 Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_EVERY_0)); 129 m_everyRadioButton.setGroup(m_group); 130 m_everyRadioButton.setChecked(true); 131 m_atRadioButton = new CmsRadioButton( 132 WEEKS_RADIOBUTTON, 133 Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_AT_0)); 134 m_atRadioButton.setGroup(m_group); 135 m_group.addValueChangeHandler(new ValueChangeHandler<String>() { 136 137 public void onValueChange(ValueChangeEvent<String> event) { 138 139 if (handleChange()) { 140 m_controller.setPatternScheme(event.getValue().equals(m_atRadioButton.getName())); 141 } 142 } 143 }); 144 initWidget(uiBinder.createAndBindUi(this)); 145 m_everyDay.setFormValueAsString("1"); 146 m_labelIn.setText(Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_IN_0)); 147 initSelectBoxes(); 148 } 149 150 /** 151 * @see org.opencms.acacia.client.widgets.serialdate.I_CmsSerialDateValueChangeObserver#onValueChange() 152 */ 153 public void onValueChange() { 154 155 if (m_model.getPatternType().equals(PatternType.YEARLY)) { 156 m_triggerChangeActions = false; 157 if (null == m_model.getWeekDay()) { 158 m_group.selectButton(m_everyRadioButton); 159 if (!m_everyDay.isFocused()) { 160 m_everyDay.setFormValueAsString(String.valueOf(m_model.getDayOfMonth())); 161 } 162 m_everyMonth.selectValue(String.valueOf(m_model.getMonth())); 163 m_atDay.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getWeekDay())); 164 m_atMonth.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getMonth())); 165 m_atNumber.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getWeekOfMonth())); 166 } else { 167 m_group.selectButton(m_atRadioButton); 168 m_atDay.selectValue(String.valueOf(m_model.getWeekDay())); 169 m_atMonth.selectValue(String.valueOf(m_model.getMonth())); 170 m_atNumber.selectValue(String.valueOf(m_model.getWeekOfMonth())); 171 m_everyDay.setFormValueAsString( 172 Integer.toString(m_controller.getPatternDefaultValues().getDayOfMonth())); 173 m_everyMonth.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getMonth())); 174 } 175 m_triggerChangeActions = true; 176 } 177 178 } 179 180 /** 181 * Returns a flag, indicating if change actions should be triggered. 182 * @return a flag, indicating if change actions should be triggered. 183 */ 184 boolean handleChange() { 185 186 return m_triggerChangeActions; 187 } 188 189 /** 190 * Handler for focus event of an "at" input field. 191 * @param event the focus event. 192 */ 193 @UiHandler({"m_atMonth", "m_atDay", "m_atNumber"}) 194 void onAtFocus(FocusEvent event) { 195 196 if (handleChange()) { 197 m_group.selectButton(m_atRadioButton); 198 } 199 } 200 201 /** 202 * Handle day of month change. 203 * @param event the value change event. 204 */ 205 @UiHandler("m_everyDay") 206 void onDayOfMonthChange(ValueChangeEvent<String> event) { 207 208 if (handleChange()) { 209 m_controller.setDayOfMonth(event.getValue()); 210 } 211 } 212 213 /** 214 * Handler for focus event of an "every" input field. 215 * @param event the focus event. 216 */ 217 @UiHandler({"m_everyMonth", "m_everyDay"}) 218 void onEveryFocus(FocusEvent event) { 219 220 if (handleChange()) { 221 m_group.selectButton(m_everyRadioButton); 222 } 223 } 224 225 /** 226 * Handler for month changes. 227 * @param event change event. 228 */ 229 @UiHandler({"m_atMonth", "m_everyMonth"}) 230 void onMonthChange(ValueChangeEvent<String> event) { 231 232 if (handleChange()) { 233 m_controller.setMonth(event.getValue()); 234 } 235 } 236 237 /** 238 * Handler for week day changes. 239 * @param event the change event. 240 */ 241 @UiHandler("m_atDay") 242 void onWeekDayChange(ValueChangeEvent<String> event) { 243 244 if (handleChange()) { 245 m_controller.setWeekDay(event.getValue()); 246 } 247 } 248 249 /** 250 * Handler for week of month changes. 251 * @param event the change event. 252 */ 253 @UiHandler("m_atNumber") 254 void onWeekOfMonthChange(ValueChangeEvent<String> event) { 255 256 if (handleChange()) { 257 m_controller.setWeekOfMonth(event.getValue()); 258 } 259 } 260 261 /** 262 * Creates the 'at' selection view.<p> 263 */ 264 private void initSelectBoxes() { 265 266 m_atNumber.getOpener().setStyleName( 267 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 268 m_atNumber.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 269 m_atNumber.setWidth("80px"); 270 m_atNumber.addOption( 271 WeekOfMonth.FIRST.toString(), 272 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_1_0)); 273 m_atNumber.addOption( 274 WeekOfMonth.SECOND.toString(), 275 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_2_0)); 276 m_atNumber.addOption( 277 WeekOfMonth.THIRD.toString(), 278 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_3_0)); 279 m_atNumber.addOption( 280 WeekOfMonth.FOURTH.toString(), 281 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_4_0)); 282 m_atNumber.addOption( 283 WeekOfMonth.LAST.toString(), 284 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_5_0)); 285 m_atDay.getOpener().setStyleName( 286 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 287 m_atDay.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 288 m_atDay.setWidth("100px"); 289 m_atDay.addOption(WeekDay.SUNDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_SUNDAY_0)); 290 m_atDay.addOption(WeekDay.MONDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_MONDAY_0)); 291 m_atDay.addOption(WeekDay.TUESDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_TUESDAY_0)); 292 m_atDay.addOption(WeekDay.WEDNESDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_WEDNESDAY_0)); 293 m_atDay.addOption(WeekDay.THURSDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_THURSDAY_0)); 294 m_atDay.addOption(WeekDay.FRIDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_FRIDAY_0)); 295 m_atDay.addOption(WeekDay.SATURDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_SATURDAY_0)); 296 297 m_atMonth.getOpener().setStyleName( 298 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 299 m_everyMonth.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 300 m_atMonth.setWidth("100px"); 301 m_atMonth.addOption(Month.JANUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JAN_0)); 302 m_atMonth.addOption(Month.FEBRUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_FEB_0)); 303 m_atMonth.addOption(Month.MARCH.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAR_0)); 304 m_atMonth.addOption(Month.APRIL.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_APR_0)); 305 m_atMonth.addOption(Month.MAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAY_0)); 306 m_atMonth.addOption(Month.JUNE.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUN_0)); 307 m_atMonth.addOption(Month.JULY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUL_0)); 308 m_atMonth.addOption(Month.AUGUST.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_AUG_0)); 309 m_atMonth.addOption(Month.SEPTEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_SEP_0)); 310 m_atMonth.addOption(Month.OCTOBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_OCT_0)); 311 m_atMonth.addOption(Month.NOVEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_NOV_0)); 312 m_atMonth.addOption(Month.DECEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_DEC_0)); 313 314 m_everyMonth.getOpener().setStyleName( 315 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 316 m_everyMonth.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 317 m_everyMonth.setWidth("100px"); 318 m_everyMonth.addOption(Month.JANUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JAN_0)); 319 m_everyMonth.addOption(Month.FEBRUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_FEB_0)); 320 m_everyMonth.addOption(Month.MARCH.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAR_0)); 321 m_everyMonth.addOption(Month.APRIL.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_APR_0)); 322 m_everyMonth.addOption(Month.MAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAY_0)); 323 m_everyMonth.addOption(Month.JUNE.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUN_0)); 324 m_everyMonth.addOption(Month.JULY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUL_0)); 325 m_everyMonth.addOption(Month.AUGUST.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_AUG_0)); 326 m_everyMonth.addOption(Month.SEPTEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_SEP_0)); 327 m_everyMonth.addOption(Month.OCTOBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_OCT_0)); 328 m_everyMonth.addOption(Month.NOVEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_NOV_0)); 329 m_everyMonth.addOption(Month.DECEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_DEC_0)); 330 331 } 332 333}