001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (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.WeekDay;
032import org.opencms.acacia.shared.I_CmsSerialDateValue.WeekOfMonth;
033
034import com.google.gwt.user.client.Command;
035
036/** Controller for the yearly pattern panel. */
037public class CmsPatternPanelYearlyController extends A_CmsPatternPanelController {
038
039    /** The controlled view. */
040    private final CmsPatternPanelYearlyView m_view;
041
042    /**
043     * Constructor for the yearly pattern panel controller
044     * @param model the model to read data from.
045     * @param changeHandler the value change handler.
046     */
047    CmsPatternPanelYearlyController(CmsSerialDateValue model, I_ChangeHandler changeHandler) {
048        super(model, changeHandler);
049        m_view = new CmsPatternPanelYearlyView(this, m_model);
050    }
051
052    /**
053     * @see org.opencms.acacia.client.widgets.serialdate.A_CmsPatternPanelController#getView()
054     */
055    @Override
056    public I_CmsSerialDatePatternView getView() {
057
058        return m_view;
059    }
060
061    /**
062     * Set the month.
063     * @param monthStr the month to set.
064     */
065    public void setMonth(String monthStr) {
066
067        final Month month = Month.valueOf(monthStr);
068        if ((m_model.getMonth() == null) || !m_model.getMonth().equals(monthStr)) {
069            removeExceptionsOnChange(new Command() {
070
071                public void execute() {
072
073                    m_model.setMonth(month);
074                    onValueChange();
075
076                }
077            });
078        }
079    }
080
081    /**
082     * Set the pattern scheme.
083     * @param isWeekDayBased flag, indicating if the week day based scheme should be set.
084     */
085    public void setPatternScheme(final boolean isWeekDayBased) {
086
087        if (isWeekDayBased ^ (null != m_model.getWeekDay())) {
088            removeExceptionsOnChange(new Command() {
089
090                public void execute() {
091
092                    if (isWeekDayBased) {
093                        m_model.setWeekDay(getPatternDefaultValues().getWeekDay());
094                        m_model.setWeekOfMonth(getPatternDefaultValues().getWeekOfMonth());
095                    } else {
096                        m_model.setWeekDay(null);
097                        m_model.setWeekOfMonth(null);
098                    }
099                    m_model.setMonth(getPatternDefaultValues().getMonth());
100                    m_model.setDayOfMonth(getPatternDefaultValues().getDayOfMonth());
101                    m_model.setInterval(getPatternDefaultValues().getInterval());
102                    onValueChange();
103                }
104            });
105        }
106    }
107
108    /**
109     * Set the week day.
110     * @param weekDayStr the week day to set.
111     */
112    public void setWeekDay(String weekDayStr) {
113
114        final WeekDay weekDay = WeekDay.valueOf(weekDayStr);
115        if ((m_model.getWeekDay() != null) || !m_model.getWeekDay().equals(weekDay)) {
116            removeExceptionsOnChange(new Command() {
117
118                public void execute() {
119
120                    m_model.setWeekDay(weekDay);
121                    onValueChange();
122                }
123            });
124
125        }
126
127    }
128
129    /**
130     * Set the week of month.
131     * @param weekOfMonthStr the week of month to set.
132     */
133    public void setWeekOfMonth(String weekOfMonthStr) {
134
135        final WeekOfMonth weekOfMonth = WeekOfMonth.valueOf(weekOfMonthStr);
136        if ((null == m_model.getWeekOfMonth()) || !m_model.getWeekOfMonth().equals(weekOfMonth)) {
137            removeExceptionsOnChange(new Command() {
138
139                public void execute() {
140
141                    m_model.setWeekOfMonth(weekOfMonth);
142                    onValueChange();
143                }
144            });
145        }
146
147    }
148
149}