import sale.*;
import data.*;
import data.ooimpl.*;
import data.swing.*;
import data.events.*;
import util.swing.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class EditableVideoStockTED extends AbstractTableEntryDescriptor
{
private CountingStockImpl videoCountingStock;
private DataBasket db;
private TableCellRenderer tcrMoney;
private TableCellRenderer tcrName;
private TableCellRenderer tcrCount;
public EditableVideoStockTED(CountingStockImpl videoCountingStock,
DataBasket db)
{
super();
this.videoCountingStock = videoCountingStock;
this.db = db;
tcrMoney =
new CurrencyRenderer((Currency)Shop.getTheShop().getCatalog("DM"));
tcrName = new DefaultTableCellRenderer();
tcrCount = new DefaultTableCellRenderer();
((DefaultTableCellRenderer)tcrCount).setHorizontalAlignment(
SwingConstants.CENTER);
}
public int getColumnCount()
{
return 5;
}
public String getColumnName(int index)
{
return (new String[] {"Name",
"Buy",
"Sell",
"Pieces in Stock",
"Rent Pieces"})[index];
}
public TableCellRenderer getCellRenderer(int index)
{
switch (index) {
case 0: return tcrName;
case 3: return tcrCount;
case 4: return tcrCount;
default: return tcrMoney;
}
}
public Class getColumnClass(int index)
{
return null;
}
public Object getValueAt(Object record, int index)
{
VideoCassette videoCassette =
(VideoCassette)((data.swing.CountingStockTableModel.Record)
record).getDescriptor();
int count =
((data.swing.CountingStockTableModel.Record)record).getCount();
switch (index) {
case 0:
return videoCassette.getName();
case 1:
return ((QuoteValue)videoCassette.getValue()).getOffer();
case 2:
return ((QuoteValue)videoCassette.getValue()).getBid();
case 3:
return new IntegerValue(count);
case 4:
int rented = 0;
try {
Iterator i = VideoMachine.getAllCustomer().iterator();
while (i.hasNext()) {
rented = rented +
((Customer)i.next()).getStoringStock().countItems(
videoCassette.getName(), null);
}
}
catch (NullPointerException npe) {
}
return new IntegerValue(rented);
default:
return null;
}
}
public boolean isElementEditable(Object record, int index)
{
return ((index == 1) || (index == 2));
}
public TableCellEditor getCellEditor(int index)
{
if (index == 1 || index == 2)
return new DMCellEditor(new String[1], "");
else
return super.getCellEditor(index);
}
public void setValueAt(Object record, int index, Object value)
{
VideoCassette videoCassette =
(VideoCassette)((data.swing.CountingStockTableModel.Record)
record).getDescriptor();
try {
VideoCassette videoCassetteToEdit =
(VideoCassette)videoCountingStock.getCatalog(null).get(
videoCassette.getName(), db, true);
QuoteValue quoteValue = (QuoteValue)videoCassetteToEdit.getValue();
if (index == 1)
videoCassetteToEdit.setValue(new QuoteValue(quoteValue.getBid(),
(Value)value));
if (index == 2)
videoCassetteToEdit.setValue(new QuoteValue((Value)value,
quoteValue.getOffer()));
}
catch (VetoException ve) {
JOptionPane.showMessageDialog(null,
"The editing of that food item was vetoed. It might be in use.");
}
}
}