/*
* TableModelSheduleHoliday.java
*
*/
package clips.shedule.holidays;
import cli_fmw.main.ClipsException;
import clips.delegate.shedule.holidays.SheduleHolidayData;
import clips.delegate.shedule.holidays.SheduleHolidayLocal;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import javax.swing.table.AbstractTableModel;
/**
*
* @author Axe Ilshat
*/
class TableModelSheduleHoliday extends AbstractTableModel {
private SheduleHolidayLocal shl;
private boolean canEdit;
public final static int COL_DATE = 0;
public final static int COL_DESC = 1;
public final static int COL_COUNT = 2;
/** Creates a new instance of TableModelSheduleHoliday */
public TableModelSheduleHoliday(boolean canEdit, SheduleHolidayLocal shl) {
this.shl = shl;
this.canEdit = canEdit;
}
@Override
public int getColumnCount() {
return COL_COUNT;
}
@Override
public int getRowCount() {
try {
return shl.iterator().size();
} catch (ClipsException ex) {
ex.printStackTrace();
}
return 0;
}
@Override
public String getColumnName(int column) {
switch (column) {
case COL_DATE:
return "День/Месяц";
case COL_DESC:
return "Описание";
}
return null;
}
@Override
public Object getValueAt(int row, int col) {
try {
SheduleHolidayData holiday = shl.iterator().get(row);
if (col == COL_DATE) {
Calendar cal = GregorianCalendar.getInstance();
cal.set(Calendar.MONTH, holiday.getMonth() - 1);
return String.format("%02d %s", holiday.getDay(),
cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, new Locale("RU")));
} else if (col == COL_DESC) {
return holiday.getDescription();
}
} catch (ClipsException e) {
return new ErrorValue(e);
}
return null;
}
@Override
public boolean isCellEditable(int row, int col) {
if (canEdit && col == COL_DESC) {
return true;
}
return false;
}
@Override
public void setValueAt(Object obj, int row, int col) {
try {
SheduleHolidayData day = shl.iterator().get(row);
if (col == COL_DESC) {
day.setDescription((String) obj);
}
} catch (ClipsException e) {
MessageBox.showException(e);
}
}
}