001package jmri.jmrit.operations.setup; 002 003import java.awt.event.ActionEvent; 004import java.io.IOException; 005 006import javax.swing.AbstractAction; 007 008import jmri.InstanceManager; 009import jmri.ShutDownManager; 010import jmri.jmrit.operations.OperationsManager; 011import jmri.jmrit.operations.OperationsXml; 012import jmri.util.swing.ExceptionContext; 013import jmri.util.swing.ExceptionDisplayFrame; 014import jmri.util.swing.JmriJOptionPane; 015 016/** 017 * Swing action to load the operation demo files. 018 * 019 * @author Bob Jacobsen Copyright (C) 2001 020 * @author Daniel Boudreau Copyright (C) 2008 021 * @author Gregory Madsen Copyright(C) 2012 022 */ 023public class LoadDemoAction extends AbstractAction { 024 025// private final static Logger log = LoggerFactory.getLogger(LoadDemoAction.class); 026 027 public LoadDemoAction() { 028 super(Bundle.getMessage("LoadDemo")); 029 } 030 031 @Override 032 public void actionPerformed(ActionEvent e) { 033 // check to see if files are dirty 034 if (OperationsXml.areFilesDirty()) { 035 if (JmriJOptionPane.showConfirmDialog(null, Bundle.getMessage("OperationsFilesModified"), 036 Bundle.getMessage("SaveOperationFiles"), JmriJOptionPane.YES_NO_OPTION) == JmriJOptionPane.YES_OPTION) { 037 OperationsXml.save(); 038 } 039 } 040 041 int results = JmriJOptionPane.showConfirmDialog(null, Bundle.getMessage("AreYouSureDemoFiles"), 042 Bundle.getMessage("LoadDemo"), JmriJOptionPane.OK_CANCEL_OPTION); 043 if (results != JmriJOptionPane.OK_OPTION) { 044 return; 045 } 046 047 AutoBackup backup = new AutoBackup(); 048 049 try { 050 backup.autoBackup(); 051 052 backup.loadDemoFiles(); 053 054 // now deregister shut down task 055 // If Trains window was opened, then task is active 056 // otherwise it is normal to not have the task running 057 InstanceManager.getDefault(OperationsManager.class).setShutDownTask(null); 058 059 JmriJOptionPane.showMessageDialog(null, Bundle.getMessage("YouMustRestartAfterLoadDemo"), 060 Bundle.getMessage("LoadDemoSuccessful"), JmriJOptionPane.INFORMATION_MESSAGE); 061 062 InstanceManager.getDefault(ShutDownManager.class).restart(); 063 064 } catch (IOException ex) { 065 ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("LoadingDemoFiles"), 066 Bundle.getMessage("LoadingDemoMakeSure")); 067 ExceptionDisplayFrame.displayExceptionDisplayFrame(null, context); 068 } 069 } 070} 071 072