use of jmri.NamedBean in project JMRI by JMRI.
the class DefaultConditionalAction method getNamedBean.
@Override
public NamedBeanHandle<?> getNamedBean() {
if (_indirectAction) {
Memory m = (Memory) (_namedBean.getBean());
String actionName = (String) m.getValue();
NamedBean bean = getActionBean(actionName);
if (bean != null) {
return nbhm.getNamedBeanHandle(actionName, bean);
} else {
return null;
}
}
return _namedBean;
}
use of jmri.NamedBean in project JMRI by JMRI.
the class DefaultLogix method removeListener.
/**
* Removes a listener of the required type
*/
private void removeListener(JmriSimplePropertyListener listener) {
String msg = null;
NamedBean nb;
NamedBeanHandle<?> namedBeanHandle;
try {
switch(listener.getType()) {
case LISTENER_TYPE_FASTCLOCK:
Timebase tb = InstanceManager.getDefault(jmri.Timebase.class);
tb.removeMinuteChangeListener(listener);
return;
case LISTENER_TYPE_ENTRYEXIT:
NamedBean ex = jmri.InstanceManager.getDefault(jmri.jmrit.signalling.EntryExitPairs.class).getBySystemName(listener.getDevName());
if (ex == null) {
msg = "entryexit";
break;
}
ex.addPropertyChangeListener(listener);
return;
default:
namedBeanHandle = listener.getNamedBean();
if (namedBeanHandle == null) {
switch(listener.getType()) {
case LISTENER_TYPE_SENSOR:
msg = "sensor";
break;
case LISTENER_TYPE_TURNOUT:
msg = "turnout";
break;
case LISTENER_TYPE_LIGHT:
msg = "light";
break;
case LISTENER_TYPE_CONDITIONAL:
msg = "conditional";
break;
case LISTENER_TYPE_SIGNALHEAD:
msg = "signalhead";
break;
case LISTENER_TYPE_SIGNALMAST:
msg = "signalmast";
break;
case LISTENER_TYPE_MEMORY:
msg = "memory";
break;
case LISTENER_TYPE_WARRANT:
msg = "warrant";
break;
case LISTENER_TYPE_OBLOCK:
msg = "oblock";
break;
case LISTENER_TYPE_ENTRYEXIT:
msg = "entry exit";
break;
default:
msg = "unknown";
}
break;
}
nb = namedBeanHandle.getBean();
nb.removePropertyChangeListener(listener);
return;
}
} catch (Exception ex) {
log.error("Bad name for listener on \"{}\": ", listener.getDevName(), ex);
}
log.error("Bad name for " + msg + " listener on \"" + listener.getDevName() + "\" when removing");
}
use of jmri.NamedBean in project JMRI by JMRI.
the class BeanTableDataModel method removeName.
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);
}
use of jmri.NamedBean in project JMRI by JMRI.
the class BeanTableDataModel method renameBean.
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 = { Bundle.getMessage("ButtonCancel"), Bundle.getMessage("ButtonOK"), _newName };
int retval = JOptionPane.showOptionDialog(null, Bundle.getMessage("RenameFrom", oldName), Bundle.getMessage("RenameTitle", getBeanType()), 0, JOptionPane.INFORMATION_MESSAGE, null, renameBeanOption, renameBeanOption[2]);
if (retval != 1) {
return;
}
// N11N
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);
}
}
use of jmri.NamedBean in project JMRI by JMRI.
the class BeanTableDataModel method moveBean.
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[] { Bundle.getMessage("ButtonCancel"), Bundle.getMessage("ButtonOK"), box }, // TODO I18N
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"));
}
}
Aggregations