Package clips.shedule.exception

Source Code of clips.shedule.exception.TableModelSheduleException

/*
* SheduleHolidayTableModel.java
*
*/

package clips.shedule.exception;

import TimeTable.Day;
import TimeTable.DayOfWeek;
import beans.shedule.week.TimeOffset;
import cli_fmw.main.ClipsException;
import clips.delegate.shedule.exception.SheduleExceptionData;
import clips.delegate.shedule.exception.SheduleExceptionLocal;
import cli_fmw.delegate.utils.TimeLocal;
import clips.delegate.shedule.SheduledDay;
import clips.delegate.shedule.holidays.SheduleHolidayData;
import clips.delegate.shedule.holidays.SheduleHolidayLocal;
import clips.delegate.shedule.week.SheduleWeekLocal;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.table.AbstractTableModel;

/**
*
* @author Axe Ilshat
*/
public class TableModelSheduleException extends AbstractTableModel {
   
    private final SheduleExceptionLocal sel;
    private final SheduleHolidayLocal shl;
    private final SheduleWeekLocal swl;
    private final int year;
    private final int month;
   
    public final static int COL_DATE = 0;
    public final static int COL_PLANNED = 1;
    public final static int COL_EXCEPTION = 2;
    public final static int COL_COUNT = 3;
   

    /**
     *
     * @param sel
     * @param shl
     * @param swl
     * @param year
     * @param month 1-12
     * @throws ClipsException
     */
    public TableModelSheduleException(SheduleExceptionLocal sel,
            SheduleHolidayLocal shl, SheduleWeekLocal swl, int year, int month) throws ClipsException {
        this.sel = sel;
        this.shl = shl;
        this.swl = swl;
        this.year = year;
        this.month = month;
    }
   

    @Override
    public int getColumnCount() {
        return COL_COUNT;
    }
    @Override
    public int getRowCount() {
        GregorianCalendar cal = new GregorianCalendar();
        cal.set(Calendar.YEAR, getTableYear());
        cal.set(Calendar.MONTH, getTableMonth() - 1);
       
        return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    }
   
    @Override
    public String getColumnName(int column) {
        switch(column) {
            case COL_DATE: return "Дата";
            case COL_PLANNED: return "Запланированная работа";
            case COL_EXCEPTION: return "Исключения";
        }
        return null;
    }
   
    @Override
    public Class getColumnClass(int c) {
        if(c == COL_EXCEPTION) {
            return String.class;
        }
        return Object.class;
    }
   
    @Override
    public Object getValueAt(int row, int col) {
        try {
            //SheduleDayInfo day = sel.getDayInfo(row+1, getTableMonth(), getTableYear());
            Day day = new Day(getTableYear(), getTableMonth()-1, row+1);

            if(col == COL_DATE) {
                return day.toString() + " " + day.getDayOfWeek().getShortTitle();
               
            } else if(col == COL_PLANNED) {
                SheduleHolidayData holiday = shl.getHoliday(day.getDay(), getTableMonth());
                if(holiday != null) {
                    return "Праздничный день: " + holiday.getDescription();
                }
                DayOfWeek dow = day.getDayOfWeek();
                TimeOffset timeBegin = swl.getTimeBegin(dow);
                TimeOffset timeEnd = swl.getTimeEnd(dow);
                if(timeBegin.getRaw() == 0) {
                    return "Выходной день";
                }
                return timeBegin + " - " + timeEnd;
               
            } else if(col == COL_EXCEPTION) {
                Date date = day.getCalendar().getTime();
                SheduleExceptionData exception = sel.getException(date);
                if(exception != null) {
                    return "Исключение: " + exception;
                }
                return "";
            }
        } catch(ClipsException e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public boolean isCellEditable(int row,int col) {
        return false;
    }
   
    private int getTableYear() {
        return year;
    }

    /**
     *
     * @return 1-12
     */
    private int getTableMonth() {
        return month;
    }
}
TOP

Related Classes of clips.shedule.exception.TableModelSheduleException

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.