コード例 #1
0
 /** We expected to find a db file, but nothing was there. Ask. */
 private static String getDatabaseLocationWhenExpectedFileWasNotFound(
     final String expectedDatabasePath, final IWindowUtils windowUtils) {
   LOG.warn("Expected database  " + expectedDatabasePath + " not found!");
   final int response =
       windowUtils.showQuestionMessage(
           "Could not find a database file!\nWould you like to initialize a new new (emtpy) one, or locate a database file yourself?\nNote that the database location can be changed at any time.",
           new String[] {"New", "Find Existing"},
           "No Database Found");
   if (response == 0) {
     return expectedDatabasePath;
   } else {
     return chooseDatabaseLocation(windowUtils);
   }
 }
コード例 #2
0
 /**
  * Initializes the database (showing various popups and warnings if the location is not ok) and
  * creates the {@link Injector}
  */
 private static Injector initializeDependencies(
     final String databasePath, final IWindowUtils windowUtils) {
   EmbeddedObjectContainer container = null;
   try {
     container = Db4oEmbedded.openFile(databasePath);
   } catch (final Db4oException e) {
     windowUtils.showErrorMessage(
         "Either your database is currently being used, or is seriouly corrupted, or you didn't choose a database file!\nYou need to either select or create a database.",
         "Database Load Error");
     return initializeDependencies(chooseDatabaseLocation(windowUtils), windowUtils);
   }
   return Guice.createInjector(
       new GuiceConfigBackend(container, databasePath), new GuiceConfigGui());
 }
コード例 #3
0
 /** Uses a {@link JFileChooser} to get a database location */
 private static String chooseDatabaseLocation(final IWindowUtils windowUtils) {
   final JFileChooser fileChooser = new JFileChooser();
   fileChooser.setDialogTitle("Select Database");
   fileChooser.setApproveButtonText("Use this Database");
   final int result = fileChooser.showDialog(null, null);
   if (result == JFileChooser.APPROVE_OPTION) {
     return fileChooser.getSelectedFile().getAbsolutePath();
   } else {
     if (windowUtils.showWarningQuestionMessage(
         "Apprentice needs a database!\nDo you want to go back and select or create a new one?\nOtherwise the program will terminate.",
         "Database")) {
       return chooseDatabaseLocation(windowUtils);
     } else {
       LOG.info("Shut down due to lack of database.");
       System.exit(0);
     }
   }
   return ""; // kinda unreachable
 }