Search in sources :

Example 11 with NamedBean

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();
}
Also used : NamedBean(jmri.NamedBean)

Example 12 with NamedBean

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;
    }
}
Also used : NamedBean(jmri.NamedBean)

Example 13 with NamedBean

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");
        }
    };
}
Also used : NamedBean(jmri.NamedBean) LogixManager(jmri.LogixManager) JTextField(javax.swing.JTextField) LightManager(jmri.LightManager) InstanceManager(jmri.InstanceManager) MemoryManager(jmri.MemoryManager) LogixManager(jmri.LogixManager) ConditionalManager(jmri.ConditionalManager) TurnoutManager(jmri.TurnoutManager) UserPreferencesManager(jmri.UserPreferencesManager) OBlockManager(jmri.jmrit.logix.OBlockManager) SensorManager(jmri.SensorManager) WarrantManager(jmri.jmrit.logix.WarrantManager) Manager(jmri.Manager) SignalHeadManager(jmri.SignalHeadManager) SignalMastManager(jmri.SignalMastManager) JComboBox(javax.swing.JComboBox) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) Logix(jmri.Logix) JTable(javax.swing.JTable)

Example 14 with NamedBean

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;
}
Also used : NamedBean(jmri.NamedBean) QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) DccSignalHead(jmri.implementation.DccSignalHead) DoubleTurnoutSignalHead(jmri.implementation.DoubleTurnoutSignalHead) TripleTurnoutSignalHead(jmri.implementation.TripleTurnoutSignalHead) SignalHead(jmri.SignalHead) SingleTurnoutSignalHead(jmri.implementation.SingleTurnoutSignalHead) TripleOutputSignalHead(jmri.implementation.TripleOutputSignalHead)

Example 15 with NamedBean

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;
}
Also used : NamedBean(jmri.NamedBean)

Aggregations

NamedBean (jmri.NamedBean)104 ArrayList (java.util.ArrayList)18 JTextField (javax.swing.JTextField)12 JmriException (jmri.JmriException)12 SignalMast (jmri.SignalMast)12 JTable (javax.swing.JTable)11 Manager (jmri.Manager)9 Sensor (jmri.Sensor)9 JButton (javax.swing.JButton)8 InstanceManager (jmri.InstanceManager)8 JComboBox (javax.swing.JComboBox)7 MouseEvent (java.awt.event.MouseEvent)6 Hashtable (java.util.Hashtable)6 SignalHead (jmri.SignalHead)6 Turnout (jmri.Turnout)6 OBlock (jmri.jmrit.logix.OBlock)5 File (java.io.File)4 JLabel (javax.swing.JLabel)4 TableCellEditor (javax.swing.table.TableCellEditor)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4