jp.xet.baseunits.wicket.CalendarMonthModel.java Source code

Java tutorial

Introduction

Here is the source code for jp.xet.baseunits.wicket.CalendarMonthModel.java

Source

/*
 * Copyright 2011 Daisuke Miyamoto. (http://d.hatena.ne.jp/daisuke-m)
 * Created on 2012/03/06
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package jp.xet.baseunits.wicket;

import java.util.TimeZone;

import jp.xet.baseunits.time.CalendarMonth;
import jp.xet.baseunits.time.TimePoint;

import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.lang.Args;

/**
 * {@link TimePoint}????????
 * 
 * @since 2.1
 */
@SuppressWarnings("serial")
public class CalendarMonthModel extends AbstractReadOnlyModel<CalendarMonth> {

    private final IModel<TimePoint> timePointModel;

    private final IModel<TimeZone> timeZoneModel;

    /**
     * ??
     * 
     * @param timePointModel ???{@link TimePoint}
     * @param timeZoneModel 
     * @throws IllegalArgumentException ?{@code null}???
     * @since 2.1
     */
    public CalendarMonthModel(IModel<TimePoint> timePointModel, IModel<TimeZone> timeZoneModel) {
        Args.notNull(timePointModel, "timePointModel");
        Args.notNull(timeZoneModel, "timeZoneModel");
        this.timePointModel = timePointModel;
        this.timeZoneModel = timeZoneModel;
    }

    /**
     * ??
     * 
     * @param timePointModel ???{@link TimePoint}
     * @param timeZone 
     * @throws IllegalArgumentException {@code timePointModel}?{@code null}???
     * @since 2.1
     */
    public CalendarMonthModel(IModel<TimePoint> timePointModel, TimeZone timeZone) {
        this(timePointModel, Model.of(timeZone));
        Args.notNull(timePointModel, "timePointModel");
    }

    /**
     * ??
     * 
     * @param timePoint ???{@link TimePoint}
     * @param timeZoneModel 
     * @throws IllegalArgumentException {@code timeZoneModel}?{@code null}???
     * @since 2.1
     */
    public CalendarMonthModel(TimePoint timePoint, IModel<TimeZone> timeZoneModel) {
        this(Model.of(timePoint), timeZoneModel);
        Args.notNull(timeZoneModel, "timeZoneModel");
    }

    /**
     * ??
     * 
     * @param timePoint ???{@link TimePoint}
     * @param timeZone 
     * @since 2.1
     */
    public CalendarMonthModel(TimePoint timePoint, TimeZone timeZone) {
        this(Model.of(timePoint), Model.of(timeZone));
    }

    @Override
    public void detach() {
        super.detach();
        if (timePointModel != null) {
            timePointModel.detach();
        }
        if (timeZoneModel != null) {
            timeZoneModel.detach();
        }
    }

    @Override
    public CalendarMonth getObject() {
        TimePoint timePoint = timePointModel.getObject();
        if (timePoint == null) {
            return null;
        }
        TimeZone timeZone = timeZoneModel.getObject();
        if (timeZone == null) {
            timeZone = TimeZone.getTimeZone("Universal");
        }
        return timePoint.asCalendarDate(timeZone).asCalendarMonth();
    }
}