// For new applications, change the names of the databases in the lines below.
 @Override
 public void initializeDefaultPreferences() {
   IPreferenceStore store = ApplicationControllers.getApplication().getPreferenceStore();
   super.initializeDefaultPreferences();
   store.setDefault(
       DatabasePreferenceConstants.MYSQL_DATABASE_CONNECTION_URL,
       "jdbc:mysql://localhost:3306/pediatricVentilator");
   store.setDefault(
       DatabasePreferenceConstants.TARGET_DATABASE_CONNECTION_URL,
       "jdbc:mysql://localhost:3306/targetPediatricVentilator");
 }
  public boolean performOk() {
    String oldDatabasePreference =
        ApplicationControllers.getApplication()
            .getPreferenceStore()
            .getString(DatabasePreferenceConstants.DATABASE_CHOICE);
    if (super.performOk()) { // super.performOk stores all the fields into the preference store
      String databasePreference =
          ApplicationControllers.getApplication()
              .getPreferenceStore()
              .getString(DatabasePreferenceConstants.DATABASE_CHOICE);
      if (oldDatabasePreference.equals(databasePreference)) {
        return true;
      }

      // Database preference has changed:
      HibernateUtil.injectDatabasePreference(
          ApplicationControllers.getDatabaseController().getDatabasePreferenceMap());
      if (databasePreference.equals("hsqldb")
          && ApplicationControllers.getHsqldbController().getHsqldbIsRunning() == false) {
        ApplicationControllers.getApplication().startServer();
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        try {
          session.beginTransaction();
          SchemaUpdate su = new SchemaUpdate(HibernateUtil.getConfiguration());
          su.execute(false, true);
          session.getTransaction().commit();
        } catch (RuntimeException e) {
          throw new UtahToolboxException(ErrorCode.SCHEMA_UPDATE_ERROR, e);
        }
      }

      if (databasePreference.equals("mysql")) {
        if (ApplicationControllers.getApplication().testMySQLConnection(this)) {
          // mySQL is running
          Session session = HibernateUtil.getSessionFactory().getCurrentSession();
          try {
            session.beginTransaction();
            SchemaUpdate su = new SchemaUpdate(HibernateUtil.getConfiguration());
            su.execute(false, true);
            session.getTransaction().commit();
          } catch (RuntimeException e) {
            throw new UtahToolboxException(ErrorCode.SCHEMA_UPDATE_ERROR, e);
          }

          if (ApplicationControllers.getHsqldbController().getHsqldbIsRunning()) {
            // turn off HSQLDB if running
            try {
              ApplicationControllers.getApplication().stopHsqldb();
            } catch (ClassNotFoundException e) {
              e.printStackTrace();
            } catch (SQLException e) {
              e.printStackTrace();
            }
          }
        } else {
          // mySQL is not running so revert to HSQLDB
          ApplicationControllers.getApplication()
              .getPreferenceStore()
              .setValue(DatabasePreferenceConstants.DATABASE_CHOICE, "hsqldb");
          HibernateUtil.injectDatabasePreference(
              ApplicationControllers.getDatabaseController().getDatabasePreferenceMap());
          if (ApplicationControllers.getHsqldbController().getHsqldbIsRunning() == false) {
            ApplicationControllers.getApplication().startServer();
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            try {
              session.beginTransaction();
              SchemaUpdate su = new SchemaUpdate(HibernateUtil.getConfiguration());
              su.execute(false, true);
              session.getTransaction().commit();
            } catch (RuntimeException e) {
              throw new UtahToolboxException(ErrorCode.SCHEMA_UPDATE_ERROR, e);
            }
          }
        }
      }

      ApplicationControllers.getDatabaseController().fireDatabaseChanged();
      ApplicationControllers.getDecisionController()
          .addDecisionFiredListener(ApplicationControllers.getClockJob());
      ApplicationControllers.getPatientController().updatePatientList();
      ApplicationControllers.getPatientController().setActivePatient(null);
      ApplicationControllers.getPatientController().firePatientsChanged(null);
      return true;
    }
    return false;
  }
 public void init(IWorkbench workbench) {
   setPreferenceStore(ApplicationControllers.getApplication().getPreferenceStore());
   setDescription("Preference settings for decision support database:");
 }