001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH (http://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: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://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 m_controller = controller; 121 m_model = model; 122 m_model.registerValueChangeObserver(this); 123 124 m_group = new CmsRadioButtonGroup(); 125 m_everyRadioButton = new CmsRadioButton( 126 DAYS_RADIOBUTTON, 127 Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_EVERY_0)); 128 m_everyRadioButton.setGroup(m_group); 129 m_everyRadioButton.setChecked(true); 130 m_atRadioButton = new CmsRadioButton( 131 WEEKS_RADIOBUTTON, 132 Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_AT_0)); 133 m_atRadioButton.setGroup(m_group); 134 m_group.addValueChangeHandler(new ValueChangeHandler<String>() { 135 136 public void onValueChange(ValueChangeEvent<String> event) { 137 138 if (handleChange()) { 139 m_controller.setPatternScheme(event.getValue().equals(m_atRadioButton.getName())); 140 } 141 } 142 }); 143 initWidget(uiBinder.createAndBindUi(this)); 144 m_everyDay.setFormValueAsString("1"); 145 m_labelIn.setText(Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_IN_0)); 146 initSelectBoxes(); 147 } 148 149 /** 150 * @see org.opencms.acacia.client.widgets.serialdate.I_CmsSerialDateValueChangeObserver#onValueChange() 151 */ 152 public void onValueChange() { 153 154 if (m_model.getPatternType().equals(PatternType.YEARLY)) { 155 m_triggerChangeActions = false; 156 if (null == m_model.getWeekDay()) { 157 m_group.selectButton(m_everyRadioButton); 158 if (!m_everyDay.isFocused()) { 159 m_everyDay.setFormValueAsString(String.valueOf(m_model.getDayOfMonth())); 160 } 161 m_everyMonth.selectValue(String.valueOf(m_model.getMonth())); 162 m_atDay.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getWeekDay())); 163 m_atMonth.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getMonth())); 164 m_atNumber.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getWeekOfMonth())); 165 } else { 166 m_group.selectButton(m_atRadioButton); 167 m_atDay.selectValue(String.valueOf(m_model.getWeekDay())); 168 m_atMonth.selectValue(String.valueOf(m_model.getMonth())); 169 m_atNumber.selectValue(String.valueOf(m_model.getWeekOfMonth())); 170 m_everyDay.setFormValueAsString( 171 Integer.toString(m_controller.getPatternDefaultValues().getDayOfMonth())); 172 m_everyMonth.selectValue(String.valueOf(m_controller.getPatternDefaultValues().getMonth())); 173 } 174 m_triggerChangeActions = true; 175 } 176 177 } 178 179 /** 180 * Returns a flag, indicating if change actions should be triggered. 181 * @return a flag, indicating if change actions should be triggered. 182 */ 183 boolean handleChange() { 184 185 return m_triggerChangeActions; 186 } 187 188 /** 189 * Handler for focus event of an "at" input field. 190 * @param event the focus event. 191 */ 192 @UiHandler({"m_atMonth", "m_atDay", "m_atNumber"}) 193 void onAtFocus(FocusEvent event) { 194 195 if (handleChange()) { 196 m_group.selectButton(m_atRadioButton); 197 } 198 } 199 200 /** 201 * Handle day of month change. 202 * @param event the value change event. 203 */ 204 @UiHandler("m_everyDay") 205 void onDayOfMonthChange(ValueChangeEvent<String> event) { 206 207 if (handleChange()) { 208 m_controller.setDayOfMonth(event.getValue()); 209 } 210 } 211 212 /** 213 * Handler for focus event of an "every" input field. 214 * @param event the focus event. 215 */ 216 @UiHandler({"m_everyMonth", "m_everyDay"}) 217 void onEveryFocus(FocusEvent event) { 218 219 if (handleChange()) { 220 m_group.selectButton(m_everyRadioButton); 221 } 222 } 223 224 /** 225 * Handler for month changes. 226 * @param event change event. 227 */ 228 @UiHandler({"m_atMonth", "m_everyMonth"}) 229 void onMonthChange(ValueChangeEvent<String> event) { 230 231 if (handleChange()) { 232 m_controller.setMonth(event.getValue()); 233 } 234 } 235 236 /** 237 * Handler for week day changes. 238 * @param event the change event. 239 */ 240 @UiHandler("m_atDay") 241 void onWeekDayChange(ValueChangeEvent<String> event) { 242 243 if (handleChange()) { 244 m_controller.setWeekDay(event.getValue()); 245 } 246 } 247 248 /** 249 * Handler for week of month changes. 250 * @param event the change event. 251 */ 252 @UiHandler("m_atNumber") 253 void onWeekOfMonthChange(ValueChangeEvent<String> event) { 254 255 if (handleChange()) { 256 m_controller.setWeekOfMonth(event.getValue()); 257 } 258 } 259 260 /** 261 * Creates the 'at' selection view.<p> 262 * */ 263 private void initSelectBoxes() { 264 265 m_atNumber.getOpener().setStyleName( 266 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 267 m_atNumber.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 268 m_atNumber.setWidth("80px"); 269 m_atNumber.addOption( 270 WeekOfMonth.FIRST.toString(), 271 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_1_0)); 272 m_atNumber.addOption( 273 WeekOfMonth.SECOND.toString(), 274 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_2_0)); 275 m_atNumber.addOption( 276 WeekOfMonth.THIRD.toString(), 277 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_3_0)); 278 m_atNumber.addOption( 279 WeekOfMonth.FOURTH.toString(), 280 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_4_0)); 281 m_atNumber.addOption( 282 WeekOfMonth.LAST.toString(), 283 Messages.get().key(Messages.GUI_SERIALDATE_WEEKDAYNUMBER_5_0)); 284 m_atDay.getOpener().setStyleName( 285 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 286 m_atDay.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 287 m_atDay.setWidth("100px"); 288 m_atDay.addOption(WeekDay.SUNDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_SUNDAY_0)); 289 m_atDay.addOption(WeekDay.MONDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_MONDAY_0)); 290 m_atDay.addOption(WeekDay.TUESDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_TUESDAY_0)); 291 m_atDay.addOption(WeekDay.WEDNESDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_WEDNESDAY_0)); 292 m_atDay.addOption(WeekDay.THURSDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_THURSDAY_0)); 293 m_atDay.addOption(WeekDay.FRIDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_FRIDAY_0)); 294 m_atDay.addOption(WeekDay.SATURDAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_DAY_SATURDAY_0)); 295 296 m_atMonth.getOpener().setStyleName( 297 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 298 m_everyMonth.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 299 m_atMonth.setWidth("100px"); 300 m_atMonth.addOption(Month.JANUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JAN_0)); 301 m_atMonth.addOption(Month.FEBRUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_FEB_0)); 302 m_atMonth.addOption(Month.MARCH.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAR_0)); 303 m_atMonth.addOption(Month.APRIL.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_APR_0)); 304 m_atMonth.addOption(Month.MAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAY_0)); 305 m_atMonth.addOption(Month.JUNE.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUN_0)); 306 m_atMonth.addOption(Month.JULY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUL_0)); 307 m_atMonth.addOption(Month.AUGUST.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_AUG_0)); 308 m_atMonth.addOption(Month.SEPTEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_SEP_0)); 309 m_atMonth.addOption(Month.OCTOBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_OCT_0)); 310 m_atMonth.addOption(Month.NOVEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_NOV_0)); 311 m_atMonth.addOption(Month.DECEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_DEC_0)); 312 313 m_everyMonth.getOpener().setStyleName( 314 org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().selectBoxSelected()); 315 m_everyMonth.getSelectorPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.globalWidgetCss().selectBoxPopup()); 316 m_everyMonth.setWidth("100px"); 317 m_everyMonth.addOption(Month.JANUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JAN_0)); 318 m_everyMonth.addOption(Month.FEBRUARY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_FEB_0)); 319 m_everyMonth.addOption(Month.MARCH.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAR_0)); 320 m_everyMonth.addOption(Month.APRIL.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_APR_0)); 321 m_everyMonth.addOption(Month.MAY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_MAY_0)); 322 m_everyMonth.addOption(Month.JUNE.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUN_0)); 323 m_everyMonth.addOption(Month.JULY.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_JUL_0)); 324 m_everyMonth.addOption(Month.AUGUST.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_AUG_0)); 325 m_everyMonth.addOption(Month.SEPTEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_SEP_0)); 326 m_everyMonth.addOption(Month.OCTOBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_OCT_0)); 327 m_everyMonth.addOption(Month.NOVEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_NOV_0)); 328 m_everyMonth.addOption(Month.DECEMBER.toString(), Messages.get().key(Messages.GUI_SERIALDATE_YEARLY_DEC_0)); 329 330 } 331 332}