String name = ""; while (true) { name = (String) JOptionPane.showInputDialog(this, "Enter Experiment Name", "Experiment Name", JOptionPane.QUESTION_MESSAGE, null, null, name); if (name == null) return; if (!ExperimentDB.isExperimentNameInDatabase(name)) { experiment.setName(name); break; } int answer = JOptionPane.showConfirmDialog(this, "Use an unique name", "Experiment Name Not Unique", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (answer != JOptionPane.OK_OPTION) return; }
String name = csmart.getUniqueExperimentName(experiment.getShortName()); if (name == null) return; experiment.setName(name);
  public void save() {    if (false && !modified) {      JOptionPane.showMessageDialog(this, "No modifications were made.");      return;    }    modified = false;    if (experiment.isCloned()) {      experiment.saveToDb();      return;    }    // if experiment name is already unique, then don't ask user for new one    // TODO: make sure that name is unique in Organizer    if (ExperimentDB.isExperimentNameInDatabase(experiment.getShortName())) {      String name = "";      while (true) {        name = (String) JOptionPane.showInputDialog(this,                                                   "Enter Experiment Name",                                                  "Experiment Name",                                                  JOptionPane.QUESTION_MESSAGE,                                                  null, null, name);        if (name == null) return;        if (!ExperimentDB.isExperimentNameInDatabase(name)) {          experiment.setName(name);          break;        }        int answer = JOptionPane.showConfirmDialog(this,                                               "Use an unique name",                                               "Experiment Name Not Unique",                                               JOptionPane.OK_CANCEL_OPTION,                                               JOptionPane.ERROR_MESSAGE);        if (answer != JOptionPane.OK_OPTION) return;      }    }    experiment.saveToDb();    experiment.setCloned(true);  }