Ejemplo n.º 1
0
  void deleteBean(OBlock bean) {
    int count = bean.getNumPropertyChangeListeners() - 2; // one is this table, other is manager
    if (log.isDebugEnabled()) {
      log.debug("Delete with " + count + " remaining listenner");
      // java.beans.PropertyChangeSupport pcs = new java.beans.PropertyChangeSupport(bean);
      PropertyChangeListener[] listener =
          ((jmri.implementation.AbstractNamedBean) bean).getPropertyChangeListeners();
      for (int i = 0; i < listener.length; i++) {
        log.debug(i + ") " + listener[i].getClass().getName());
      }
    }
    if (!noWarnDelete) {
      String msg;
      if (count > 0) { // warn of listeners attached before delete
        msg =
            java.text.MessageFormat.format(Bundle.getMessage("DeletePrompt"), bean.getSystemName())
                + "\n"
                + java.text.MessageFormat.format(Bundle.getMessage("ReminderInUse"), count);
      } else {
        msg =
            java.text.MessageFormat.format(
                Bundle.getMessage("DeletePrompt"), new Object[] {bean.getSystemName()});
      }

      // verify deletion
      int val =
          JOptionPane.showOptionDialog(
              null,
              msg,
              Bundle.getMessage("WarningTitle"),
              JOptionPane.YES_NO_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              new Object[] {
                Bundle.getMessage("ButtonYes"),
                Bundle.getMessage("ButtonYesPlus"),
                Bundle.getMessage("ButtonNo")
              },
              Bundle.getMessage("ButtonNo"));
      if (val == 2) {
        return; // return without deleting
      }
      if (val == 1) { // suppress future warnings
        noWarnDelete = true;
      }
    }
    // finally OK, do the actual delete
    bean.dispose();
  }