/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.service.discount.levels;
import clips.delegate.directory.complex.DirectoryDiscountLevel;
import clips.delegate.directory.complex.DirectoryDiscountLevelItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;
/**
*
* @author axe
*/
public class TableModelDiscountLevels extends AbstractTableModel {
static final long serialVersionUID = 1L;
protected final static int COL_TITLE = 0;
protected final static int COL_LEVEL = 1;
protected final static int COL_COUNT = 2;
DirectoryDiscountLevel directory;
public TableModelDiscountLevels() throws ClipsException {
directory = DirectoryLocator.getDirectory(DirectoryDiscountLevel.class, false);
}
@Override
public int getRowCount() {
return directory.getItems().size();
}
@Override
public int getColumnCount() {
return COL_COUNT;
}
@Override
public Object getValueAt(int row, int col) {
DirectoryDiscountLevelItem item = directory.getItems().get(row);
switch (col) {
case COL_TITLE: {
return item;
}
case COL_LEVEL: {
return item.getLevel();
}
}
return null;
}
@Override
public Class<?> getColumnClass(int col) {
switch (col) {
case COL_TITLE:
return String.class;
case COL_LEVEL:
return Integer.class;
}
return super.getColumnClass(col);
}
@Override
public String getColumnName(int col) {
switch (col) {
case COL_TITLE:
return "Название уровня";
case COL_LEVEL:
return "Цена";
}
return null;
}
@Override
public void setValueAt(Object value, int row, int col) {
try {
DirectoryDiscountLevelItem item = (DirectoryDiscountLevelItem) directory.getItems().get(row);
switch (col) {
case COL_TITLE: {
item.setTitle((String)value);
break;
}
case COL_LEVEL: {
item.setLevel((Integer)value);
fireTableChanged(new TableModelEvent(this));
break;
}
}
} catch (ClipsException ex) {
ex.printStackTrace();
}
}
@Override
public boolean isCellEditable(int arg0, int arg1) {
return true;
}
}