import sale.*;
import data.*;
import data.ooimpl.*;
import data.stdforms.*;
import data.swing.*;
import data.events.*;
import users.*;
import java.util.*;
import javax.swing.*;
public class SeeVideoStockProcess extends SaleProcess
{
protected UIGate selectionGate;
public SeeVideoStockProcess()
{
super ("SeeVideoProcess");
}
protected void setupMachine()
{
selectionGate = new UIGate(null, null);
final DataBasket db = getBasket();
final Catalog videoCatalog = Shop.getTheShop().getCatalog("Video-Catalog");
final CountingStockImpl videoStock = (CountingStockImpl)Shop.getTheShop().
getStock("Video-Countingstock");
final SingleTableFormSheet stfs =
SingleTableFormSheet.create("See videos in stock and edit Process",
videoStock,
selectionGate,
db,
true,
new EditableVideoStockTED(videoStock, db)
);
stfs.addContentCreator(
new FormSheetContentCreator()
{
protected void createFormSheetContent(FormSheet fs)
{
fs.removeAllButtons();
fs.addButton ("New", 100,
new sale.Action()
{
public void doAction (SaleProcess p, SalesPoint sp)
{
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JTextField jTextField4 = new JTextField();
JPanel jTextPanel = new JPanel();
jTextPanel.setLayout(new BoxLayout(jTextPanel,
BoxLayout.Y_AXIS));
jTextPanel.add(new JLabel("Name"));
jTextPanel.add(jTextField1);
jTextPanel.add(new JLabel("Buy (in Pf)"));
jTextPanel.add(jTextField2);
jTextPanel.add(new JLabel("Sell (in Pf)"));
jTextPanel.add(jTextField3);
jTextPanel.add(new JLabel("Amount"));
jTextPanel.add(jTextField4);
JOptionPane.showMessageDialog (null,
jTextPanel,
"New Video-Cassette",
JOptionPane.QUESTION_MESSAGE);
String name = jTextField1.getText();
int buy = 0;
try {
buy = (new Integer(jTextField2.getText())).intValue();
}
catch (NumberFormatException ne) {}
int sell = 0;
try {
sell = (new Integer(jTextField3.getText())).intValue();
}
catch (NumberFormatException ne) {}
int amount = 0;
try {
amount = (new Integer(jTextField4.getText())).intValue();
}
catch (NumberFormatException ne) {}
if (sell > 0 && buy > 0 && amount > 0 && !name.equals(""))
{
try {
videoCatalog.add(new VideoCassette(name, new QuoteValue
(new IntegerValue (sell), new IntegerValue (buy))), db);
videoStock.add(name, amount, db);
}
catch (DuplicateKeyException dke) {
JOptionPane.showMessageDialog(null, "Element exists");
}
}
else
{
JOptionPane.showMessageDialog(null,
"The given input was not correct!");
}
}
}
);
fs.addButton ("Remove", 101,
new sale.Action()
{
public void doAction (SaleProcess p, SalesPoint sp)
{
Object record = stfs.getSelectedRecord();
if (record != null)
{
VideoCassette videoCassette = (VideoCassette)
((data.swing.CountingStockTableModel.Record) record).getDescriptor();
int rented = 0;
if (VideoMachine.getAllCustomer() != null)
{
Iterator i = VideoMachine.getAllCustomer().iterator();
while (i.hasNext())
rented = rented +
((Customer)i.next()).getStoringStock().countItems(
videoCassette.getName(), null);
}
if (rented <= 0)
{
try {
videoCatalog.remove(videoCassette, db);
}
catch (VetoException ve) {
ve.printStackTrace();
JOptionPane.showMessageDialog(null,
"The selected item can't be removed!");
}
}
else
{
JOptionPane.showMessageDialog(null,
"There are still rented videos!");
}
}
}
}
);
fs.addButton ("Ok", 102,
new sale.Action()
{
public void doAction (SaleProcess p, SalesPoint sp)
{
selectionGate.setNextTransition(
GateChangeTransition.CHANGE_TO_COMMIT_GATE);
}
}
);
fs.addButton ("Cancel", 103,
new sale.Action()
{
public void doAction (SaleProcess p, SalesPoint sp)
{
selectionGate.setNextTransition(
GateChangeTransition.CHANGE_TO_ROLLBACK_GATE);
}
}
);
}
}
);
}
public Gate getInitialGate()
{
setupMachine();
return selectionGate;
}
public Gate getLogGate()
{
return getStopGate();
}
}