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.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 104 m_controller = controller; 105 m_model = model; 106 m_model.registerValueChangeObserver(this); 107 108 // init radio buttons 109 m_group = new CmsRadioButtonGroup(); 110 m_everyRadioButton = new CmsRadioButton( 111 EVERYDAY_RADIOBUTTON, 112 Messages.get().key(Messages.GUI_SERIALDATE_DAILY_EVERY_0)); 113 114 m_everyRadioButton.setGroup(m_group); 115 m_everyRadioButton.setChecked(true); 116 m_workingRadioButton = new CmsRadioButton( 117 WORKINGDAY_RADIOBUTTON, 118 Messages.get().key(Messages.GUI_SERIALDATE_DAILY_EVERYWORKINGDAY_0)); 119 m_workingRadioButton.setGroup(m_group); 120 m_group.addValueChangeHandler(new ValueChangeHandler<String>() { 121 122 public void onValueChange(ValueChangeEvent<String> event) { 123 124 if (handleChange()) { 125 m_controller.setEveryWorkingDay(m_workingRadioButton.isChecked()); 126 } 127 } 128 }); 129 initWidget(uiBinder.createAndBindUi(this)); 130 m_labelDays.setInnerText(Messages.get().key(Messages.GUI_SERIALDATE_DAILY_DAYS_0)); 131 m_everyDay.setFormValueAsString(m_model.getInterval() < 1 ? "" : "" + m_model.getInterval()); 132 m_everyDay.setTriggerChangeOnKeyPress(true); 133 } 134 135 /** 136 * @see org.opencms.acacia.client.widgets.serialdate.I_CmsSerialDateValueChangeObserver#onValueChange() 137 */ 138 public void onValueChange() { 139 140 if (m_model.getPatternType().equals(PatternType.DAILY)) { 141 m_triggerChangeActions = false; 142 if (m_model.isEveryWorkingDay()) { 143 m_group.selectButton(m_workingRadioButton); 144 m_everyDay.setFormValueAsString(""); 145 } else { 146 m_group.selectButton(m_everyRadioButton); 147 if (!m_everyDay.isFocused()) { 148 m_everyDay.setFormValueAsString(String.valueOf(m_model.getInterval())); 149 } 150 } 151 m_triggerChangeActions = true; 152 } 153 154 } 155 156 /** 157 * Returns a flag, indicating if change actions should be triggered. 158 * @return a flag, indicating if change actions should be triggered. 159 */ 160 boolean handleChange() { 161 162 return m_triggerChangeActions; 163 } 164 165 /** 166 * Handle interval change. 167 * @param event the change event. 168 */ 169 @UiHandler("m_everyDay") 170 void onEveryDayChange(ValueChangeEvent<String> event) { 171 172 if (handleChange()) { 173 m_controller.setInterval(m_everyDay.getFormValueAsString()); 174 } 175 176 } 177 178 /** 179 * Handle interval field focus. 180 * @param event the focus event. 181 */ 182 @UiHandler("m_everyDay") 183 void onEveryDayFocus(FocusEvent event) { 184 185 if (handleChange()) { 186 m_group.selectButton(m_everyRadioButton); 187 } 188 189 } 190}