Search in sources :

Example 1 with ExceptionContext

use of jmri.jmrit.operations.ExceptionContext in project JMRI by JMRI.

the class RestoreDialog method do_restoreButton_actionPerformed.

protected void do_restoreButton_actionPerformed(ActionEvent e) {
    log.debug("restore button activated");
    // check to see if files are dirty
    if (OperationsXml.areFilesDirty()) {
        if (JOptionPane.showConfirmDialog(this, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            OperationsXml.save();
        }
    }
    // first backup the users data in case they forgot
    try {
        AutoBackup auto = new AutoBackup();
        auto.autoBackup();
        // now delete the current operations files in case the restore isn't a full set of files
        backup.deleteOperationsFiles();
        setName = ((BackupSet) comboBox.getSelectedItem()).getSetName();
        // The restore method should probably be overloaded to accept a
        // BackupSet instead of a simple string. Later.
        backup.restoreFilesFromSetName(setName);
        // now deregister shut down task
        // If Trains window was opened, then task is active
        // otherwise it is normal to not have the task running
        OperationsManager.getInstance().setShutDownTask(null);
        JOptionPane.showMessageDialog(this, Bundle.getMessage("YouMustRestartAfterRestore"), Bundle.getMessage("RestoreSuccessful"), JOptionPane.INFORMATION_MESSAGE);
        dispose();
        Apps.handleRestart();
    }// auto or default.
     catch (IOException ex) {
        ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("RestoreDialog.restoring") + " " + setName, // NOI18N
        "Hint about checking valid names, etc.");
        new ExceptionDisplayFrame(context);
    } catch (Exception ex) {
        log.error("Doing restore from " + setName, ex);
        UnexpectedExceptionContext context = new UnexpectedExceptionContext(ex, Bundle.getMessage("RestoreDialog.restoring") + " " + setName);
        new ExceptionDisplayFrame(context);
    }
}
Also used : ExceptionDisplayFrame(jmri.jmrit.operations.ExceptionDisplayFrame) UnexpectedExceptionContext(jmri.jmrit.operations.UnexpectedExceptionContext) ExceptionContext(jmri.jmrit.operations.ExceptionContext) UnexpectedExceptionContext(jmri.jmrit.operations.UnexpectedExceptionContext) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with ExceptionContext

use of jmri.jmrit.operations.ExceptionContext in project JMRI by JMRI.

the class BackupDialog method do_backupButton_actionPerformed.

protected void do_backupButton_actionPerformed(ActionEvent e) {
    // Do the backup of the files...
    String setName = null;
    try {
        log.debug("backup button activated");
        setName = setNameTextField.getText();
        if (!OperationsXml.checkFileName(setName)) {
            // NOI18N
            log.error("Back up set name must not contain reserved characters");
            JOptionPane.showMessageDialog(this, // NOI18N
            Bundle.getMessage("NameResChar") + "\n" + Bundle.getMessage("ReservedChar"), Bundle.getMessage("CanNotUseName"), JOptionPane.ERROR_MESSAGE);
            return;
        }
        // check to see if files are dirty
        if (OperationsXml.areFilesDirty()) {
            if (JOptionPane.showConfirmDialog(this, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                OperationsXml.save();
            }
        }
        // check to see if directory already exists
        if (backup.checkIfBackupSetExists(setName)) {
            int result = JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("DirectoryAreadyExists"), new Object[] { setName }), Bundle.getMessage("OverwriteBackupDirectory"), JOptionPane.OK_CANCEL_OPTION);
            if (result != JOptionPane.OK_OPTION) {
                return;
            }
        }
        backup.backupFilesToSetName(setName);
        dispose();
    } catch (IOException ex) {
        ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("BackupDialog.BackingUp") + " " + setName, Bundle.getMessage("BackupDialog.Ensure"));
        new ExceptionDisplayFrame(context);
    } catch (RuntimeException ex) {
        // ex.printStackTrace();
        log.error("Doing backup...", ex);
        UnexpectedExceptionContext context = new UnexpectedExceptionContext(ex, Bundle.getMessage("BackupDialog.BackingUp") + " " + setName);
        new ExceptionDisplayFrame(context);
    } catch (Exception ex) {
        // ex.printStackTrace();
        log.error("Doing backup...", ex);
        UnexpectedExceptionContext context = new UnexpectedExceptionContext(ex, Bundle.getMessage("BackupDialog.BackingUp") + " " + setName);
        new ExceptionDisplayFrame(context);
    }
}
Also used : ExceptionDisplayFrame(jmri.jmrit.operations.ExceptionDisplayFrame) UnexpectedExceptionContext(jmri.jmrit.operations.UnexpectedExceptionContext) ExceptionContext(jmri.jmrit.operations.ExceptionContext) UnexpectedExceptionContext(jmri.jmrit.operations.UnexpectedExceptionContext) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with ExceptionContext

use of jmri.jmrit.operations.ExceptionContext in project JMRI by JMRI.

the class LoadDemoAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // check to see if files are dirty
    if (OperationsXml.areFilesDirty()) {
        if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            OperationsXml.save();
        }
    }
    int results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("AreYouSureDemoFiles"), Bundle.getMessage("LoadDemo"), JOptionPane.OK_CANCEL_OPTION);
    if (results != JOptionPane.OK_OPTION) {
        return;
    }
    AutoBackup backup = new AutoBackup();
    try {
        backup.autoBackup();
        backup.loadDemoFiles();
        // now deregister shut down task
        // If Trains window was opened, then task is active
        // otherwise it is normal to not have the task running
        OperationsManager.getInstance().setShutDownTask(null);
        JOptionPane.showMessageDialog(null, Bundle.getMessage("YouMustRestartAfterLoadDemo"), Bundle.getMessage("LoadDemoSuccessful"), JOptionPane.INFORMATION_MESSAGE);
        Apps.handleRestart();
    } catch (IOException ex) {
        ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("LoadingDemoFiles"), Bundle.getMessage("LoadingDemoMakeSure"));
        new ExceptionDisplayFrame(context);
    }
}
Also used : ExceptionDisplayFrame(jmri.jmrit.operations.ExceptionDisplayFrame) ExceptionContext(jmri.jmrit.operations.ExceptionContext) IOException(java.io.IOException)

Example 4 with ExceptionContext

use of jmri.jmrit.operations.ExceptionContext in project JMRI by JMRI.

the class RestoreFilesAction method restore.

private void restore() {
    // check to see if files are dirty
    if (OperationsXml.areFilesDirty()) {
        if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            OperationsXml.save();
        }
    }
    // first backup the users data in case they forgot
    BackupBase backup = new DefaultBackup();
    // get file to write to
    JFileChooser fc = new JFileChooser(backup.getBackupRoot());
    fc.addChoosableFileFilter(new fileFilter());
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int retVal = fc.showOpenDialog(null);
    if (retVal != JFileChooser.APPROVE_OPTION) {
        // Canceled
        return;
    }
    if (fc.getSelectedFile() == null) {
        // Canceled
        return;
    }
    // now backup files
    AutoBackup autoBackup = new AutoBackup();
    try {
        autoBackup.autoBackup();
        File directory = fc.getSelectedFile();
        // now delete the current operations files in case the restore isn't a full set of files
        backup.deleteOperationsFiles();
        backup.restoreFilesFromDirectory(directory);
        JOptionPane.showMessageDialog(null, Bundle.getMessage("YouMustRestartAfterRestore"), Bundle.getMessage("RestoreSuccessful"), JOptionPane.INFORMATION_MESSAGE);
        // now deregister shut down task
        // If Trains window was opened, then task is active
        // otherwise it is normal to not have the task running
        OperationsManager.getInstance().setShutDownTask(null);
        Apps.handleRestart();
    } catch (IOException ex) {
        ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("RestoreDialog.restore.files"), Bundle.getMessage("RestoreDialog.makeSure"));
        new ExceptionDisplayFrame(context);
    }
}
Also used : ExceptionDisplayFrame(jmri.jmrit.operations.ExceptionDisplayFrame) JFileChooser(javax.swing.JFileChooser) ExceptionContext(jmri.jmrit.operations.ExceptionContext) IOException(java.io.IOException) File(java.io.File)

Aggregations

IOException (java.io.IOException)4 ExceptionContext (jmri.jmrit.operations.ExceptionContext)4 ExceptionDisplayFrame (jmri.jmrit.operations.ExceptionDisplayFrame)4 UnexpectedExceptionContext (jmri.jmrit.operations.UnexpectedExceptionContext)2 File (java.io.File)1 JFileChooser (javax.swing.JFileChooser)1