001    package videoautomat;
002    import java.io.FileInputStream;
003    import java.io.FileNotFoundException;
004    import java.io.IOException;
005    
006    import log.LogInputStream;
007    import sale.Action;
008    import sale.FormSheet;
009    import sale.FormSheetContentCreator;
010    import sale.Gate;
011    import sale.GateChangeTransition;
012    import sale.SaleProcess;
013    import sale.SalesPoint;
014    import sale.UIGate;
015    import sale.stdforms.MsgForm;
016    import videoautomat.gui.LogFileFormSheet;
017    /**
018     * This class implements a <code>SaleProcess</code> for the administrative work.
019     *  
020     */
021    public class SaleProcessAdmin extends SaleProcess {
022            /*
023             * the initial Gate, where the global logfile is shown.
024             */
025            private UIGate uig_logfile = new UIGate(null, null);
026    
027            /**
028             * Constructs a new SaleProcessAdmin.
029             *  
030             */
031            public SaleProcessAdmin() {
032                    super("SaleProcessAdmin");
033            }
034            /**
035             * Implementation of the inherited abstract method. At this <code>Gate</code> the user will see the content of
036             * the global logfile.
037             * 
038             * @return the <code>Gate</code> this process will first switch to.
039             * 
040             * @see sale.SaleProcess#getInitialGate()
041             */
042            protected Gate getInitialGate() {
043                    try {
044                            FileInputStream fis = new FileInputStream(VideoShop.FILENAME);
045                            LogInputStream lis = new LogInputStream(fis, new LogEntryFilterImpl());
046    
047                            LogFileFormSheet lfsf = new LogFileFormSheet(lis);
048                            lfsf.addContentCreator(new FormSheetContentCreator() {
049                                    public void createFormSheetContent(FormSheet fs) {
050                                            fs.getButton(LogFileFormSheet.FB_CLOSE).setAction(new Action() {
051                                                    public void doAction(SaleProcess p, SalesPoint sp) {
052                                                            uig_logfile.setNextTransition(
053                                                                    GateChangeTransition.CHANGE_TO_STOP_GATE);
054                                                    }
055                                            });
056                                    }
057                            });
058                            uig_logfile.setFormSheet(lfsf);
059                    } catch (FileNotFoundException e) {
060                            getStopGate();
061                            e.printStackTrace();
062                    } catch (IOException e) {
063                            MsgForm msf = new MsgForm("Empty-LogFile!",
064                                    "The log file was found empty.\n"
065                                    + "Nothing to administrate here.");
066                            msf.getButton(MsgForm.BTNID_OK).setAction(new Action() 
067                            {
068                                    public void doAction(SaleProcess p, SalesPoint sp) 
069                                    {
070                                            uig_logfile.setNextTransition(GateChangeTransition.CHANGE_TO_QUIT_GATE);
071                                    }});
072                            uig_logfile.setFormSheet(msf);
073                    }
074                    return uig_logfile;
075            }
076    }