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.PatternType; 031import org.opencms.ade.contenteditor.client.Messages; 032import org.opencms.gwt.client.ui.input.CmsRadioButton; 033import org.opencms.gwt.client.ui.input.CmsRadioButtonGroup; 034 035import com.google.gwt.core.shared.GWT; 036import com.google.gwt.dom.client.Element; 037import com.google.gwt.event.dom.client.FocusEvent; 038import com.google.gwt.event.logical.shared.ValueChangeEvent; 039import com.google.gwt.event.logical.shared.ValueChangeHandler; 040import com.google.gwt.uibinder.client.UiBinder; 041import com.google.gwt.uibinder.client.UiField; 042import com.google.gwt.uibinder.client.UiHandler; 043import com.google.gwt.user.client.ui.Composite; 044import com.google.gwt.user.client.ui.HTMLPanel; 045 046/** 047 * The daily pattern panel.<p> 048 * */ 049public class CmsPatternPanelDailyView extends Composite implements I_CmsSerialDatePatternView { 050 051 /** The UI binder interface. */ 052 interface I_CmsPatternPanelDailyUiBinder extends UiBinder<HTMLPanel, CmsPatternPanelDailyView> { 053 // nothing to do 054 } 055 056 /** Name of the "every day" radio button. */ 057 private static final String EVERYDAY_RADIOBUTTON = "everyday"; 058 059 /** Name of the "working day" radio button. */ 060 private static final String WORKINGDAY_RADIOBUTTON = "workingday"; 061 062 /** The UI binder instance. */ 063 private static I_CmsPatternPanelDailyUiBinder uiBinder = GWT.create(I_CmsPatternPanelDailyUiBinder.class); 064 065 /* UI elements for "every day". */ 066 067 /** The every day radio button. */ 068 @UiField(provided = true) 069 CmsRadioButton m_everyRadioButton; 070 071 /** The text box for the date input. */ 072 @UiField 073 CmsFocusAwareTextBox m_everyDay; 074 075 /** The days label. */ 076 @UiField 077 Element m_labelDays; 078 079 /* UI elements for "every working day" */ 080 081 /** The every working day radio button. */ 082 @UiField(provided = true) 083 CmsRadioButton m_workingRadioButton; 084 085 /** Group off all radio buttons. */ 086 CmsRadioButtonGroup m_group; 087 088 /** The model to read the data from. */ 089 private final I_CmsObservableSerialDateValue m_model; 090 091 /** The controller to handle changes. */ 092 final CmsPatternPanelDailyController m_controller; 093 094 /** Flag, indicating if change actions should not be triggered. */ 095 private boolean m_triggerChangeActions = true; 096 097 /** 098 * Constructor to create the daily pattern panel. 099 * @param controller the controller that handles value changes. 100 * @param model the model that provides the values. 101 */ 102 public CmsPatternPanelDailyView(CmsPatternPanelDailyController controller, I_CmsObservableSerialDateValue model) { 103 m_controller = controller; 104 m_model = model; 105 m_model.registerValueChangeObserver(this); 106 107 // init radio buttons 108 m_group = new CmsRadioButtonGroup(); 109 m_everyRadioButton = new CmsRadioButton( 110 EVERYDAY_RADIOBUTTON, 111 Messages.get().key(Messages.GUI_SERIALDATE_DAILY_EVERY_0)); 112 113 m_everyRadioButton.setGroup(m_group); 114 m_everyRadioButton.setChecked(true); 115 m_workingRadioButton = new CmsRadioButton( 116 WORKINGDAY_RADIOBUTTON, 117 Messages.get().key(Messages.GUI_SERIALDATE_DAILY_EVERYWORKINGDAY_0)); 118 m_workingRadioButton.setGroup(m_group); 119 m_group.addValueChangeHandler(new ValueChangeHandler<String>() { 120 121 public void onValueChange(ValueChangeEvent<String> event) { 122 123 if (handleChange()) { 124 m_controller.setEveryWorkingDay(m_workingRadioButton.isChecked()); 125 } 126 } 127 }); 128 initWidget(uiBinder.createAndBindUi(this)); 129 m_labelDays.setInnerText(Messages.get().key(Messages.GUI_SERIALDATE_DAILY_DAYS_0)); 130 m_everyDay.setFormValueAsString(m_model.getInterval() < 1 ? "" : "" + m_model.getInterval()); 131 m_everyDay.setTriggerChangeOnKeyPress(true); 132 } 133 134 /** 135 * @see org.opencms.acacia.client.widgets.serialdate.I_CmsSerialDateValueChangeObserver#onValueChange() 136 */ 137 public void onValueChange() { 138 139 if (m_model.getPatternType().equals(PatternType.DAILY)) { 140 m_triggerChangeActions = false; 141 if (m_model.isEveryWorkingDay()) { 142 m_group.selectButton(m_workingRadioButton); 143 m_everyDay.setFormValueAsString(""); 144 } else { 145 m_group.selectButton(m_everyRadioButton); 146 if (!m_everyDay.isFocused()) { 147 m_everyDay.setFormValueAsString(String.valueOf(m_model.getInterval())); 148 } 149 } 150 m_triggerChangeActions = true; 151 } 152 153 } 154 155 /** 156 * Returns a flag, indicating if change actions should be triggered. 157 * @return a flag, indicating if change actions should be triggered. 158 */ 159 boolean handleChange() { 160 161 return m_triggerChangeActions; 162 } 163 164 /** 165 * Handle interval change. 166 * @param event the change event. 167 */ 168 @UiHandler("m_everyDay") 169 void onEveryDayChange(ValueChangeEvent<String> event) { 170 171 if (handleChange()) { 172 m_controller.setInterval(m_everyDay.getFormValueAsString()); 173 } 174 175 } 176 177 /** 178 * Handle interval field focus. 179 * @param event the focus event. 180 */ 181 @UiHandler("m_everyDay") 182 void onEveryDayFocus(FocusEvent event) { 183 184 if (handleChange()) { 185 m_group.selectButton(m_everyRadioButton); 186 } 187 188 } 189}