Esempio n. 1
0
  /** Generic method to change the user name of a Bean */
  public void renameBean(String _newName) {
    NamedBean nBean = bean;
    String oldName = nBean.getUserName();

    String value = _newName;

    if (value.equals(oldName)) {
      // name not changed.
      return;
    } else {
      NamedBean nB = getByUserName(value);
      if (nB != null) {
        log.error("User name is not unique " + value); // NOI18N
        String msg;
        msg =
            java.text.MessageFormat.format(
                Bundle.getMessage("WarningUserName"), new Object[] {("" + value)});
        JOptionPane.showMessageDialog(
            null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
        return;
      }
    }

    nBean.setUserName(value);
    if (!value.equals("")) {
      if (oldName == null || oldName.equals("")) {
        if (!nbMan.inUse(nBean.getSystemName(), nBean)) {
          return;
        }
        String msg =
            java.text.MessageFormat.format(
                Bundle.getMessage("UpdateToUserName"),
                new Object[] {getBeanType(), value, nBean.getSystemName()});
        int optionPane =
            JOptionPane.showConfirmDialog(
                null, msg, Bundle.getMessage("UpdateToUserNameTitle"), JOptionPane.YES_NO_OPTION);
        if (optionPane == JOptionPane.YES_OPTION) {
          // This will update the bean reference from the systemName to the userName
          try {
            nbMan.updateBeanFromSystemToUser(nBean);
          } catch (jmri.JmriException ex) {
            // We should never get an exception here as we already check that the username is not
            // valid
          }
        }

      } else {
        nbMan.renameBean(oldName, value, nBean);
      }

    } else {
      // This will update the bean reference from the old userName to the SystemName
      nbMan.updateBeanFromUserToSystem(nBean);
    }
  }
Esempio n. 2
0
 protected void saveBasicItems(ActionEvent e) {
   String uname = bean.getUserName();
   if (uname == null && !userNameField.getText().equals("")) {
     renameBean(userNameField.getText());
   } else if (uname != null && !uname.equals(userNameField.getText())) {
     if (userNameField.getText().equals("")) {
       removeName();
     } else {
       renameBean(userNameField.getText());
     }
   }
   bean.setComment(commentField.getText());
 }
Esempio n. 3
0
 @Override
 public boolean isCellEditable(int row, int col) {
   String uname;
   switch (col) {
     case VALUECOL:
     case COMMENTCOL:
     case DELETECOL:
       return true;
     case USERNAMECOL:
       NamedBean b = getBySystemName(sysNameList.get(row));
       uname = b.getUserName();
       if ((uname == null) || uname.equals("")) {
         return true;
       }
       // $FALL-THROUGH$
     default:
       return false;
   }
 }
Esempio n. 4
0
 @Override
 public Object getValueAt(int row, int col) {
   NamedBean b;
   switch (col) {
     case SYSNAMECOL: // slot number
       return sysNameList.get(row);
     case USERNAMECOL: // return user name
       // sometimes, the TableSorter invokes this on rows that no longer exist, so we check
       b = getBySystemName(sysNameList.get(row));
       return (b != null) ? b.getUserName() : null;
     case VALUECOL: //
       return getValue(sysNameList.get(row));
     case COMMENTCOL:
       b = getBySystemName(sysNameList.get(row));
       return (b != null) ? b.getComment() : null;
     case DELETECOL: //
       return Bundle.getMessage("ButtonDelete");
     default:
       log.error("internal state inconsistent with table requst for " + row + " " + col);
       return null;
   }
 }
Esempio n. 5
0
  public void moveBean(int row, int column) {
    final NamedBean t = getBySystemName(sysNameList.get(row));
    String currentName = t.getUserName();
    NamedBean oldNameBean = getBySystemName(sysNameList.get(row));

    if ((currentName == null) || currentName.equals("")) {
      JOptionPane.showMessageDialog(null, "Can not move an empty UserName");
      return;
    }

    JComboBox<String> box = new JComboBox<>();
    List<String> nameList = getManager().getSystemNameList();
    for (int i = 0; i < nameList.size(); i++) {
      NamedBean nb = getBySystemName(nameList.get(i));
      // Only add items that do not have a username assigned.
      if (nb.getDisplayName().equals(nameList.get(i))) {
        box.addItem(nameList.get(i));
      }
    }

    int retval =
        JOptionPane.showOptionDialog(
            null,
            "Move " + getBeanType() + " " + currentName + " from " + oldNameBean.getSystemName(),
            "Move UserName",
            0,
            JOptionPane.INFORMATION_MESSAGE,
            null,
            new Object[] {"Cancel", "OK", box},
            null);
    log.debug(
        "Dialog value "
            + retval
            + " selected "
            + box.getSelectedIndex()
            + ":"
            + box.getSelectedItem());
    if (retval != 1) {
      return;
    }
    String entry = (String) box.getSelectedItem();
    NamedBean newNameBean = getBySystemName(entry);
    if (oldNameBean != newNameBean) {
      oldNameBean.setUserName("");
      newNameBean.setUserName(currentName);
      InstanceManager.getDefault(NamedBeanHandleManager.class)
          .moveBean(oldNameBean, newNameBean, currentName);
      if (nbMan.inUse(newNameBean.getSystemName(), newNameBean)) {
        String msg =
            Bundle.getMessage(
                "UpdateToUserName",
                new Object[] {getBeanType(), currentName, sysNameList.get(row)});
        int optionPane =
            JOptionPane.showConfirmDialog(
                null, msg, Bundle.getMessage("UpdateToUserNameTitle"), JOptionPane.YES_NO_OPTION);
        if (optionPane == JOptionPane.YES_OPTION) {
          try {
            nbMan.updateBeanFromSystemToUser(newNameBean);
          } catch (JmriException ex) {
            // We should never get an exception here as we already check that the username is not
            // valid
          }
        }
      }
      fireTableRowsUpdated(row, row);
      InstanceManager.getDefault(UserPreferencesManager.class)
          .showInfoMessage(
              "Reminder",
              getBeanType() + " " + Bundle.getMessage("UpdateComplete"),
              getMasterClassName(),
              "remindSaveReLoad");
      // JOptionPane.showMessageDialog(null, getBeanType() + " " +
      // Bundle.getMessage("UpdateComplete"));
    }
  }
Esempio n. 6
0
  public void renameBean(int row, int column) {
    NamedBean nBean = getBySystemName(sysNameList.get(row));
    String oldName = nBean.getUserName();
    JTextField _newName = new JTextField(20);
    _newName.setText(oldName);
    Object[] renameBeanOption = {"Cancel", "OK", _newName};
    int retval =
        JOptionPane.showOptionDialog(
            null,
            "Rename UserName From " + oldName,
            "Rename " + getBeanType(),
            0,
            JOptionPane.INFORMATION_MESSAGE,
            null,
            renameBeanOption,
            renameBeanOption[2]);

    if (retval != 1) {
      return;
    }
    String value = _newName.getText().trim();

    if (value.equals(oldName)) {
      // name not changed.
      return;
    } else {
      NamedBean nB = getByUserName(value);
      if (nB != null) {
        log.error("User name is not unique " + value);
        String msg = Bundle.getMessage("WarningUserName", new Object[] {("" + value)});
        JOptionPane.showMessageDialog(
            null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
        return;
      }
    }

    nBean.setUserName(value);
    fireTableRowsUpdated(row, row);
    if (!value.equals("")) {
      if (oldName == null || oldName.equals("")) {
        if (!nbMan.inUse(sysNameList.get(row), nBean)) {
          return;
        }
        String msg =
            Bundle.getMessage(
                "UpdateToUserName", new Object[] {getBeanType(), value, sysNameList.get(row)});
        int optionPane =
            JOptionPane.showConfirmDialog(
                null, msg, Bundle.getMessage("UpdateToUserNameTitle"), JOptionPane.YES_NO_OPTION);
        if (optionPane == JOptionPane.YES_OPTION) {
          // This will update the bean reference from the systemName to the userName
          try {
            nbMan.updateBeanFromSystemToUser(nBean);
          } catch (JmriException ex) {
            // We should never get an exception here as we already check that the username is not
            // valid
          }
        }

      } else {
        nbMan.renameBean(oldName, value, nBean);
      }

    } else {
      // This will update the bean reference from the old userName to the SystemName
      nbMan.updateBeanFromUserToSystem(nBean);
    }
  }
Esempio n. 7
0
 public void copyName(int row, int column) {
   NamedBean nBean = getBySystemName(sysNameList.get(row));
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   StringSelection name = new StringSelection(nBean.getUserName());
   clipboard.setContents(name, null);
 }
Esempio n. 8
0
 protected void resetBasicItems(ActionEvent e) {
   userNameField.setText(bean.getUserName());
   commentField.setText(bean.getComment());
 }