/** 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); } }
public void removeName(int row, int column) { NamedBean nBean = getBySystemName(sysNameList.get(row)); String msg = Bundle.getMessage("UpdateToSystemName", new Object[] {getBeanType()}); int optionPane = JOptionPane.showConfirmDialog( null, msg, Bundle.getMessage("UpdateToSystemNameTitle"), JOptionPane.YES_NO_OPTION); if (optionPane == JOptionPane.YES_OPTION) { nbMan.updateBeanFromUserToSystem(nBean); } nBean.setUserName(null); fireTableRowsUpdated(row, row); }
/** Generic method to remove the user name from a bean. */ public void removeName() { String msg = java.text.MessageFormat.format( Bundle.getMessage("UpdateToSystemName"), new Object[] {getBeanType()}); int optionPane = JOptionPane.showConfirmDialog( null, msg, Bundle.getMessage("UpdateToSystemNameTitle"), JOptionPane.YES_NO_OPTION); if (optionPane == JOptionPane.YES_OPTION) { nbMan.updateBeanFromUserToSystem(bean); } bean.setUserName(null); }
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); } }