name = JOptionPane.showInputDialog(prompt); if (name == null || name.equals("")) return null; if (!uniqueNames.contains(name)) break; int result = JOptionPane.showConfirmDialog(this, "Use an unique name", errorMsgTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (result != JOptionPane.OK_OPTION) return null; } return name;
String inputPrompt = "Enter " + prompt + " Name"; String title = prompt + " Name"; name = (String) JOptionPane.showInputDialog(this, inputPrompt, title, JOptionPane.QUESTION_MESSAGE, null, null, originalName); if (name == null) return null; if (name.equals(originalName) && allowExistingName) return name;   if (names.contains(name)) { title = prompt + " Name Not Unique"; int answer = JOptionPane.showConfirmDialog(this, "Use an unique name", title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (answer != JOptionPane.OK_OPTION) return null; } else {  if (databaseCheck == null) return name;  if (dbCheckMethod == null) { Class[] paramClasses = { String.class }; try { dbCheckMethod = ExperimentDB.class.getMethod(databaseCheck, paramClasses); } catch (NoSuchMethodException e) { if(log.isErrorEnabled()) { log.error("No such method", e); } } if (dbCheckMethod == null) return name; }   boolean inDatabase = false; Object[] args = new Object[1]; args[0] = name; try { Object result = dbCheckMethod.invoke(null, args); if (result instanceof Boolean) inDatabase = ((Boolean)result).booleanValue(); else if(log.isErrorEnabled()) { log.error("In Database Check returned unexpected result: " + inDatabase); } } catch (Exception e) { if(log.isErrorEnabled()) { log.error("Exception checking for unique name in database", e); } } if (inDatabase) { title = prompt + " Name Not Unique"; int answer = JOptionPane.showConfirmDialog(this, "This name is in the database; use an unique name", title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (answer != JOptionPane.OK_OPTION) return null; } else return name; } }
  private String getUniqueName(String prompt, String errorMsgTitle,                               UniqueNameSet uniqueNames) {    String name;    while (true) {      name = JOptionPane.showInputDialog(prompt);      if (name == null || name.equals(""))        return null;      if (!uniqueNames.contains(name)) break;      int result = JOptionPane.showConfirmDialog(this,                                                 "Use an unique name",                                                 errorMsgTitle,                                                 JOptionPane.OK_CANCEL_OPTION,                                                 JOptionPane.ERROR_MESSAGE);      if (result != JOptionPane.OK_OPTION)        return null;    }    return name;  }