Save This Page
Home » openjdk-7 » net.sourceforge » neurosdbm » actions » [javadoc | source]
    1   //
    2   //  Neuros Database Manipulator
    3   //  Copyright (C) 2003  Neuros Database Manipulator
    4   //
    5   //  This program is free software; you can redistribute it and/or modify
    6   //  it under the terms of the GNU General Public License as published by
    7   //  the Free Software Foundation; either version 2 of the License, or
    8   //  (at your option) any later version.
    9   //
   10   //  This program is distributed in the hope that it will be useful,
   11   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13   //  GNU General Public License for more details.
   14   //
   15   //  You should have received a copy of the GNU General Public License
   16   //  along with this program; if not, write to the Free Software
   17   //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18   //
   19   //  For information about Neuros Database Manipulator and its authors,
   20   //  please contact the Neuros Database Manipulator Web Site at
   21   //  http://neurosdbm.sourceforge.net
   22   //
   23   //
   24   
   25   package net.sourceforge.neurosdbm.actions;
   26   
   27   
   28   import java.io.File;
   29   import java.io.FileNotFoundException;
   30   import java.io.IOException;
   31   import java.awt.event.WindowEvent;
   32   import javax.swing.JOptionPane;
   33   import javax.swing.JFileChooser;
   34   import javax.swing.filechooser.FileFilter;
   35   import net.sourceforge.neurosdbm.MainFrame;
   36   import net.sourceforge.neurosdbm.db.Database;
   37   
   38   
   39   public final class RestoreDatabase extends BaseAction {
   40   
   41     private Database database;
   42     
   43     public RestoreDatabase(MainFrame parent, Database database) {
   44       super(parent, "Restore Database");
   45       setToolTip("Restore Database");
   46       setIcon("restore2.gif");
   47       this.database = database;
   48     }
   49     
   50     void action() {
   51       JFileChooser dirChooser = new JFileChooser();
   52       dirChooser.setFileFilter(new RestoreDirectoryFileFilter());
   53       dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
   54       dirChooser.setCurrentDirectory(new File(database.getPath()));
   55       int returnVal = dirChooser.showDialog(parent, "Perform Restore");
   56       if (returnVal == JFileChooser.APPROVE_OPTION) {
   57         File backupDir = dirChooser.getSelectedFile();
   58         boolean success = true;
   59         try {
   60           database.restore(backupDir);
   61         } catch (FileNotFoundException exp) {
   62           success = false;
   63           String message =
   64             "Error: Restore Did Not Occur [" + exp.getMessage() + "]";
   65           JOptionPane.showMessageDialog(parent, message,
   66                                         "Restore Error",
   67                                         JOptionPane.ERROR_MESSAGE);
   68         } catch (IOException exp) {
   69           success = false;
   70           String message =
   71             "Error: Restore Did Not Occur [" + exp.getMessage() + "]";
   72           JOptionPane.showMessageDialog(parent, message,
   73                                         "Restore Error",
   74                                         JOptionPane.ERROR_MESSAGE);
   75         }
   76         if (success) {
   77           String message = "Restore successful from " + backupDir;
   78           JOptionPane.showMessageDialog(parent, message,
   79                                         "Restore Success",
   80                                         JOptionPane.INFORMATION_MESSAGE);
   81         }
   82       }
   83     }
   84   
   85     
   86     private class RestoreDirectoryFileFilter extends FileFilter {
   87       
   88       public boolean accept(File f) {
   89         if (f.isDirectory()) {
   90           return true;
   91         }
   92         return false;
   93       }
   94   
   95       public String getDescription() {
   96         return "Backup Directory Location";
   97       }
   98     }
   99   }

Save This Page
Home » openjdk-7 » net.sourceforge » neurosdbm » actions » [javadoc | source]