use of jmri.NamedBean in project JMRI by JMRI.
the class BeanTableDataModel method deleteBean.
protected void deleteBean(int row, int col) {
final NamedBean t = getBySystemName(sysNameList.get(row));
//int count = t.getNumPropertyChangeListeners()-1; // one is this table
DeleteBeanWorker worker = new DeleteBeanWorker(t);
worker.execute();
}
use of jmri.NamedBean in project JMRI by JMRI.
the class BeanTableDataModel method isCellEditable.
@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;
}
}
use of jmri.NamedBean in project JMRI by JMRI.
the class LogixTableAction method createModel.
// *********** Methods for Logix Table Window ********************
/**
* Create the JTable DataModel, along with the changes (overrides of
* BeanTableDataModel) for the specific case of a Logix table.
* <p>
* Note: Table Models for the Conditional table in the Edit Logix window,
* and the State Variable table in the Edit Conditional window are at
* the end of this module.
*/
@Override
protected void createModel() {
m = new BeanTableDataModel() {
// overlay the state column with the edit column
public static final int ENABLECOL = VALUECOL;
public static final int EDITCOL = DELETECOL;
protected String enabledString = Bundle.getMessage("ColumnHeadEnabled");
@Override
public String getColumnName(int col) {
if (col == EDITCOL) {
// no heading on "Edit"
return "";
}
if (col == ENABLECOL) {
return enabledString;
}
return super.getColumnName(col);
}
@Override
public Class<?> getColumnClass(int col) {
if (col == EDITCOL) {
return String.class;
}
if (col == ENABLECOL) {
return Boolean.class;
}
return super.getColumnClass(col);
}
@Override
public int getPreferredWidth(int col) {
// override default value for SystemName and UserName columns
if (col == SYSNAMECOL) {
return new JTextField(12).getPreferredSize().width;
}
if (col == USERNAMECOL) {
return new JTextField(17).getPreferredSize().width;
}
if (col == EDITCOL) {
return new JTextField(12).getPreferredSize().width;
}
if (col == ENABLECOL) {
return new JTextField(5).getPreferredSize().width;
}
return super.getPreferredWidth(col);
}
@Override
public boolean isCellEditable(int row, int col) {
if (col == EDITCOL) {
return true;
}
if (col == ENABLECOL) {
return true;
}
return super.isCellEditable(row, col);
}
@Override
public Object getValueAt(int row, int col) {
if (col == EDITCOL) {
return Bundle.getMessage("ButtonSelect");
} else if (col == ENABLECOL) {
Logix logix = (Logix) getBySystemName((String) getValueAt(row, SYSNAMECOL));
if (logix == null) {
return null;
}
return Boolean.valueOf(logix.getEnabled());
} else {
return super.getValueAt(row, col);
}
}
@Override
public void setValueAt(Object value, int row, int col) {
if (col == EDITCOL) {
// set up to edit
String sName = (String) getValueAt(row, SYSNAMECOL);
if (Bundle.getMessage("ButtonEdit").equals(value)) {
editPressed(sName);
} else if (rbx.getString("BrowserButton").equals(value)) {
conditionalRowNumber = row;
browserPressed(sName);
} else if (Bundle.getMessage("ButtonCopy").equals(value)) {
copyPressed(sName);
} else if (Bundle.getMessage("ButtonDelete").equals(value)) {
deletePressed(sName);
}
} else if (col == ENABLECOL) {
// alternate
Logix x = (Logix) getBySystemName((String) getValueAt(row, SYSNAMECOL));
boolean v = x.getEnabled();
x.setEnabled(!v);
} else {
super.setValueAt(value, row, col);
}
}
/**
* Delete the bean after all the checking has been done.
* <p>
* Deactivates the Logix and remove it's conditionals.
*
* @param bean of the Logix to delete
*/
@Override
void doDelete(NamedBean bean) {
Logix l = (Logix) bean;
l.deActivateLogix();
// delete the Logix and all its Conditionals
_logixManager.deleteLogix(l);
}
@Override
protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
if (e.getPropertyName().equals(enabledString)) {
return true;
}
return super.matchPropertyName(e);
}
@Override
public Manager getManager() {
return InstanceManager.getDefault(jmri.LogixManager.class);
}
@Override
public NamedBean getBySystemName(String name) {
return InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(name);
}
@Override
public NamedBean getByUserName(String name) {
return InstanceManager.getDefault(jmri.LogixManager.class).getByUserName(name);
}
@Override
protected String getMasterClassName() {
return getClassName();
}
@Override
public void configureTable(JTable table) {
table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
super.configureTable(table);
}
/**
* Replace delete button with comboBox to edit/delete/copy/select Logix.
*
* @param table name of the Logix JTable holding the column
*/
@Override
protected void configDeleteColumn(JTable table) {
JComboBox<String> editCombo = new JComboBox<String>();
editCombo.addItem(Bundle.getMessage("ButtonSelect"));
editCombo.addItem(Bundle.getMessage("ButtonEdit"));
editCombo.addItem(rbx.getString("BrowserButton"));
editCombo.addItem(Bundle.getMessage("ButtonCopy"));
editCombo.addItem(Bundle.getMessage("ButtonDelete"));
TableColumn col = table.getColumnModel().getColumn(BeanTableDataModel.DELETECOL);
col.setCellEditor(new DefaultCellEditor(editCombo));
}
// Not needed - here for interface compatibility
@Override
public void clickOn(NamedBean t) {
}
@Override
public String getValue(String s) {
return "";
}
@Override
protected String getBeanType() {
return Bundle.getMessage("BeanNameLogix");
}
};
}
use of jmri.NamedBean in project JMRI by JMRI.
the class SignalHeadTableAction method checkBeforeCreating.
boolean checkBeforeCreating(String sysName) {
String sName;
if (dccSignalDecoder.equals(typeBox.getSelectedItem())) {
sName = sysName;
try {
Integer.parseInt(sysName.substring(sysName.indexOf("$") + 1, sysName.length()));
} catch (Exception ex) {
String msg = Bundle.getMessage("ShouldBeNumber", new Object[] { "Hardware Address" });
JOptionPane.showMessageDialog(addFrame, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
} else {
sName = sysName.toUpperCase();
if ((sName.length() < 3) || (!sName.substring(1, 2).equals("H"))) {
String msg = Bundle.getMessage("InvalidSignalSystemName", new Object[] { sName });
JOptionPane.showMessageDialog(addFrame, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
}
// check for pre-existing signal head with same system name
SignalHead s = InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(sName);
// return true if signal head does not exist
if (s == null) {
//Need to check that the Systemname doesn't already exists as a UserName
NamedBean nB = InstanceManager.getDefault(jmri.SignalHeadManager.class).getByUserName(sName);
if (nB != null) {
log.error("System name is not unique " + sName + " It already exists as a User name");
String msg = Bundle.getMessage("WarningSystemNameAsUser", new Object[] { ("" + sName) });
JOptionPane.showMessageDialog(editFrame, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
// inform the user if signal head already exists, and return false so creation can be bypassed
log.warn("Attempt to create signal with duplicate system name " + sName);
String msg = Bundle.getMessage("DuplicateSignalSystemName", new Object[] { sName });
JOptionPane.showMessageDialog(addFrame, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
use of jmri.NamedBean in project JMRI by JMRI.
the class SignalHeadTableAction method checkUserName.
boolean checkUserName(String nam) {
if (!((nam == null) || (nam.equals("")))) {
// user name changed, check if new name already exists
NamedBean nB = InstanceManager.getDefault(jmri.SignalHeadManager.class).getByUserName(nam);
if (nB != null) {
log.error("User name is not unique " + nam);
String msg = Bundle.getMessage("WarningUserName", new Object[] { ("" + nam) });
JOptionPane.showMessageDialog(editFrame, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
//Check to ensure that the username doesn't exist as a systemname.
nB = InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(nam);
if (nB != null) {
log.error("User name is not unique " + nam + " It already exists as a System name");
String msg = Bundle.getMessage("WarningUserNameAsSystem", new Object[] { ("" + nam) });
JOptionPane.showMessageDialog(editFrame, msg, Bundle.getMessage("WarningTitle"), JOptionPane.ERROR_MESSAGE);
return false;
}
}
return true;
}
Aggregations