001package jmri.jmrit.picker;
002
003import java.util.ArrayList;
004import java.util.HashMap;
005import java.util.List;
006import java.util.ResourceBundle;
007import java.util.TreeSet;
008import javax.annotation.CheckForNull;
009import javax.annotation.Nonnull;
010import javax.swing.JTable;
011import javax.swing.ListSelectionModel;
012import javax.swing.SortOrder;
013import javax.swing.table.TableColumn;
014import javax.swing.table.TableColumnModel;
015import javax.swing.table.TableRowSorter;
016import jmri.*;
017import jmri.jmrit.beantable.BeanTableDataModel;
018import jmri.jmrit.entryexit.*;
019import jmri.jmrit.logix.*;
020import jmri.swing.RowSorterUtil;
021import jmri.util.*;
022import jmri.util.swing.XTableColumnModel;
023import org.slf4j.Logger;
024import org.slf4j.LoggerFactory;
025
026/**
027 * Abstract class to make pick lists for NamedBeans; Table model for pick lists
028 * in IconAdder
029 * <p>
030 * Concrete pick list class for many beans are include at the end of this file.
031 * This class also has instantiation methods serve as a factory for those
032 * classes.
033 * <p>
034 * Note: Extensions of this class must call init() after instantiation.
035 *
036 * <hr>
037 * This file is part of JMRI.
038 * <p>
039 * JMRI is free software; you can redistribute it and/or modify it under the
040 * terms of version 2 of the GNU General Public License as published by the Free
041 * Software Foundation. See the "COPYING" file for a copy of this license.
042 * <p>
043 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
044 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
045 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
046 *
047 * @param <E> the supported type of NamedBean
048 * @author Pete Cressman Copyright (C) 2009, 2010
049 */
050public abstract class PickListModel<E extends NamedBean> extends BeanTableDataModel<E> {
051
052    protected ArrayList<E> _pickList;
053    protected String _name;
054    private JTable _table;       // table using this model
055    protected TableRowSorter<PickListModel<E>> _sorter;
056
057    public static final int SNAME_COLUMN = 0;
058    public static final int UNAME_COLUMN = 1;
059    public static final int POSITION_COL = 2;
060    public static final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.beantable.BeanTableBundle");
061
062    static HashMap<String, Integer> _listMap = new HashMap<String, Integer>();
063
064    static public int getNumInstances(@Nonnull String type) {
065        Integer num = _listMap.get(type.toLowerCase());
066        log.debug("getNumInstances of {} num={}", type, num);
067        if (num != null) {
068            return num;
069        }
070        return 0;
071    }
072
073    /**
074     * Default constructor makes a table sorted by System Name.
075     */
076    public PickListModel() {
077        super();
078    }
079
080    /**
081     * If table has been sorted table row no longer is the same as array index.
082     *
083     * @param index row of table
084     * @return bean at index or null if index is out of range
085     */
086    @CheckForNull
087    public E getBeanAt(int index) {
088        if (index >= _pickList.size()) {
089            return null;
090        }
091        return _pickList.get(index);
092    }
093
094    public int getIndexOf(@Nonnull E bean) {
095        for (int i = 0; i < _pickList.size(); i++) {
096            if (_pickList.get(i).equals(bean)) {
097                return i;
098            }
099        }
100        return -1;
101    }
102
103    @Nonnull
104    public List<E> getBeanList() {
105        return _pickList;
106    }
107
108    /**
109     * override BeanTableDataModel only lists SystemName
110     */
111    @Override
112    protected synchronized void updateNameList() {
113        makePickList();
114    }
115
116    private void makePickList() {
117        // Don't know who is added or deleted so remove all name change listeners
118        if (_pickList != null) {
119            for (E e : _pickList) {
120                e.removePropertyChangeListener(this);
121            }
122        }
123        TreeSet<E> ts = new TreeSet<>(new NamedBeanComparator<>());
124        ts.addAll(getManager().getNamedBeanSet());
125
126        _pickList = new ArrayList<>(getManager().getNamedBeanSet().size());
127
128        _pickList.addAll(ts);
129        // add name change listeners
130        for (E e : _pickList) {
131            e.addPropertyChangeListener(this);
132        }
133        log.debug("_pickList has {} beans", _pickList.size());
134    }
135
136    /** {@inheritDoc} */
137    @Override
138    @CheckForNull
139    public E getBySystemName(@Nonnull String name) {
140        return getManager().getBySystemName(name);
141    }
142
143    /** {@inheritDoc} */
144    @Override
145    @CheckForNull
146    protected E getByUserName(@Nonnull String name) {
147        return getManager().getByUserName(name);
148    }
149
150    /** {@inheritDoc} */
151    @Override
152    @Nonnull
153    abstract public Manager<E> getManager();
154
155    /**
156     * Return bean with name given in parameter. Create if needed and possible.
157     *
158     * @param name the System name for the Bean.
159     * @return the Bean or null if not made.
160     * @throws IllegalArgumentException with reason why Bean cannot be created.
161     */
162    @CheckForNull
163    abstract public E addBean(@Nonnull String name) throws IllegalArgumentException;
164
165    @CheckForNull
166    abstract public E addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException;
167
168    /**
169     * Check if beans can be added by this model.
170     *
171     * @return true if model can create beans; false otherwise
172     */
173    abstract public boolean canAddBean();
174
175    // these BeanTableDataModel abstract methods not needed
176    /** {@inheritDoc} */
177    @Override
178    protected String getMasterClassName() {
179        return "PickListModel";
180    }
181
182    /** {@inheritDoc} */
183    @Override
184    public void clickOn(E t) {
185    }
186
187    /** {@inheritDoc} */
188    @Override
189    public Class<?> getColumnClass(int c) {
190        return String.class;
191    }
192
193    /** {@inheritDoc} */
194    @Override
195    public int getColumnCount() {
196        return 2;
197    }
198
199    /** {@inheritDoc} */
200    @Override
201    public String getColumnName(int c) {
202        if (c == SNAME_COLUMN) {
203            return Bundle.getMessage("ColumnSystemName");
204        } else if (c == UNAME_COLUMN) {
205            return Bundle.getMessage("ColumnUserName");
206        }
207        return "";
208    }
209
210    /** {@inheritDoc} */
211    @Override
212    public boolean isCellEditable(int r, int c) {
213        return false;
214    }
215
216    /** {@inheritDoc} */
217    @Override
218    public int getRowCount() {
219        return _pickList.size();
220    }
221
222    /** {@inheritDoc} */
223    @Override
224    public Object getValueAt(int r, int c) {
225        // some error checking
226        if (r >= _pickList.size()) {
227            log.debug("row is greater than picklist size");
228            return null;
229        }
230        if (c == SNAME_COLUMN) {
231            return _pickList.get(r).getSystemName();
232        } else if (c == UNAME_COLUMN) {
233            return _pickList.get(r).getUserName();
234        }
235        return null;
236    }
237
238    /** {@inheritDoc} */
239    @Override
240    public void setValueAt(Object type, int r, int c) {
241    }
242
243    // these BeanTableDataModel abstract methods not needed
244    /** {@inheritDoc} */
245    @Override
246    public String getValue(String systemName) {
247        return systemName;
248    }
249
250    public String getName() {
251        return _name;
252    }
253
254    /** {@inheritDoc} */
255    @Override
256    protected String getBeanType() {
257        return _name;
258    }
259
260    /**
261     * Handle additions and deletions in the table and changes to beans within
262     * the table.
263     *
264     * @param e the change
265     */
266    @Override
267    public void propertyChange(java.beans.PropertyChangeEvent e) {
268        if (e.getPropertyName().equals("length")) {
269            // a NamedBean added or deleted
270            makePickList();
271            fireTableDataChanged();
272        }
273        if (e.getSource() instanceof NamedBean) {
274            NamedBean bean = (NamedBean) e.getSource();
275            for (int i = 0; i < _pickList.size(); i++) {
276                if (bean.equals(_pickList.get(i))) {
277                    fireTableRowsUpdated(i, i);
278                    break;
279                }
280            }
281        }
282        if (log.isDebugEnabled()) {
283            log.debug("propertyChange of \"{}\" for {}", e.getPropertyName(), e.getSource().toString());
284        }
285    }
286
287    /**
288     * Make pick table, DND enabled.
289     * @return the table
290     */
291    public JTable makePickTable() {
292        _sorter = new TableRowSorter<>(this);
293        _table = new JTable(this) {
294            /**
295             * Overridden to prevent empty cells from being selected
296             */
297            @Override
298            public void changeSelection(int row, int col, boolean toggle, boolean extend) {
299                if (super.getValueAt(row, col) != null) {
300                    super.changeSelection(row, col, toggle, extend);
301                }
302            }
303        };
304        _sorter.setComparator(SNAME_COLUMN, new jmri.util.AlphanumComparator());
305        _sorter.setComparator(UNAME_COLUMN, new jmri.util.AlphanumComparator());
306        RowSorterUtil.setSortOrder(_sorter, SNAME_COLUMN, SortOrder.ASCENDING);
307        _table.setRowSorter(_sorter);
308
309        _table.setRowSelectionAllowed(true);
310        _table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
311        _table.setPreferredScrollableViewportSize(new java.awt.Dimension(250, _table.getRowHeight() * 7));
312        _table.setDragEnabled(true);
313        _table.setTransferHandler(new DnDTableExportHandler());
314
315        _table.getTableHeader().setReorderingAllowed(true);
316        _table.setColumnModel(new XTableColumnModel());
317        _table.createDefaultColumnsFromModel();
318        TableColumnModel columnModel = _table.getColumnModel();
319
320        TableColumn sNameColumnT = columnModel.getColumn(SNAME_COLUMN);
321        sNameColumnT.setResizable(true);
322        sNameColumnT.setMinWidth(50);
323        //sNameColumnT.setMaxWidth(200);
324
325        TableColumn uNameColumnT = columnModel.getColumn(UNAME_COLUMN);
326        uNameColumnT.setResizable(true);
327        uNameColumnT.setMinWidth(100);
328        //uNameColumnT.setMaxWidth(300);
329
330        addMouseListenerToHeader(_table);
331        _table.setAutoCreateColumnsFromModel(false);
332
333        return _table;
334    }
335
336    public void makeSorter(@Nonnull JTable table) {
337        _sorter = new TableRowSorter<>(this);
338        _sorter.setComparator(SNAME_COLUMN, new jmri.util.AlphanumComparator());
339        _sorter.setComparator(UNAME_COLUMN, new jmri.util.AlphanumComparator());
340        RowSorterUtil.setSortOrder(_sorter, SNAME_COLUMN, SortOrder.ASCENDING);
341        table.setRowSorter(_sorter);
342    }
343
344    @Nonnull
345    public JTable getTable() {
346        return _table;
347    }
348
349    /** {@inheritDoc} */
350    @Override
351    public void dispose() {
352        getManager().removePropertyChangeListener(this);
353    }
354
355    @Nonnull
356    public static PickListModel<Turnout> turnoutPickModelInstance() {
357        Integer num = _listMap.get("turnout");
358        if (num != null) {
359            _listMap.put("turnout", num + 1);
360        } else {
361            _listMap.put("turnout", 1);
362        }
363        return new TurnoutPickModel();
364    }
365
366    @Nonnull
367    public static PickListModel<Sensor> sensorPickModelInstance() {
368        Integer num = _listMap.get("sensor");
369        if (num != null) {
370            _listMap.put("sensor", num + 1);
371        } else {
372            _listMap.put("sensor", 1);
373        }
374        return new SensorPickModel();
375    }
376
377    @Nonnull
378    public static PickListModel<Sensor> multiSensorPickModelInstance() {
379        Integer num = _listMap.get("multisensor");
380        if (num != null) {
381            _listMap.put("multisensor", num + 1);
382        } else {
383            _listMap.put("multisensor", 1);
384        }
385        return new MultiSensorPickModel();
386    }
387
388    @Nonnull
389    public static PickListModel<SignalHead> signalHeadPickModelInstance() {
390        Integer num = _listMap.get("signalhead");
391        if (num != null) {
392            _listMap.put("signalhead", num + 1);
393        } else {
394            _listMap.put("signalhead", 1);
395        }
396        return new SignalHeadPickModel();
397    }
398
399    @Nonnull
400    public static PickListModel<SignalMast> signalMastPickModelInstance() {
401        Integer num = _listMap.get("signalmast");
402        if (num != null) {
403            _listMap.put("signalmast", num + 1);
404        } else {
405            _listMap.put("signalmast", 1);
406        }
407        return new SignalMastPickModel();
408    }
409
410    @Nonnull
411    public static PickListModel<Memory> memoryPickModelInstance() {
412        Integer num = _listMap.get("memory");
413        if (num != null) {
414            _listMap.put("memory", num + 1);
415        } else {
416            _listMap.put("memory", 1);
417        }
418        return new MemoryPickModel();
419    }
420
421    @Nonnull
422    public static PickListModel<Block> blockPickModelInstance() {
423        Integer num = _listMap.get("block");
424        if (num != null) {
425            _listMap.put("block", num + 1);
426        } else {
427            _listMap.put("block", 1);
428        }
429        return new BlockPickModel();
430    }
431
432    @Nonnull
433    public static PickListModel<Reporter> reporterPickModelInstance() {
434        Integer num = _listMap.get("reporter");
435        if (num != null) {
436            _listMap.put("reporter", num + 1);
437        } else {
438            _listMap.put("reporter", 1);
439        }
440        return new ReporterPickModel();
441    }
442
443    @Nonnull
444    public static PickListModel<Light> lightPickModelInstance() {
445        Integer num = _listMap.get("light");
446        if (num != null) {
447            _listMap.put("light", num + 1);
448        } else {
449            _listMap.put("light", 1);
450        }
451        return new LightPickModel();
452    }
453
454    @Nonnull
455    public static PickListModel<OBlock> oBlockPickModelInstance() {
456        Integer num = _listMap.get("oBlock");
457        if (num != null) {
458            _listMap.put("oBlock", num + 1);
459        } else {
460            _listMap.put("oBlock", 1);
461        }
462        return new OBlockPickModel();
463    }
464
465    @Nonnull
466    public static PickListModel<Warrant> warrantPickModelInstance() {
467        Integer num = _listMap.get("warrant");
468        if (num != null) {
469            _listMap.put("warrant", num + 1);
470        } else {
471            _listMap.put("warrant", 1);
472        }
473        return new WarrantPickModel();
474    }
475
476    @Nonnull
477    public static PickListModel<DestinationPoints> entryExitPickModelInstance() {
478        Integer num = _listMap.get("entryExit");
479        if (num != null) {
480            _listMap.put("entryExit", num + 1);
481        } else {
482            _listMap.put("entryExit", 1);
483        }
484        return new EntryExitPickModel();
485    }
486
487    public static PickListModel<Logix> logixPickModelInstance() {
488        Integer num = _listMap.get("logix");
489        if (num != null) {
490            _listMap.put("logix", num + 1);
491        } else {
492            _listMap.put("logix", 1);
493        }
494        return new LogixPickModel();
495    }
496
497    private final static Logger log = LoggerFactory.getLogger(PickListModel.class);
498
499    static class TurnoutPickModel extends PickListModel<Turnout> {
500
501        TurnoutManager manager = InstanceManager.turnoutManagerInstance();
502
503        TurnoutPickModel() {
504            _name = rb.getString("TitleTurnoutTable");
505        }
506
507        /** {@inheritDoc} */
508        @Override
509        @Nonnull
510        public Manager<Turnout> getManager() {
511            manager = InstanceManager.turnoutManagerInstance();
512            return manager;
513        }
514
515        /** {@inheritDoc} */
516        @Override
517        public Turnout addBean(@Nonnull String name) throws IllegalArgumentException {
518            return manager.provideTurnout(name);
519        }
520
521        /** {@inheritDoc} */
522        @Override
523        public Turnout addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException {
524            return manager.newTurnout(sysName, userName);
525        }
526
527        /** {@inheritDoc} */
528        @Override
529        public boolean canAddBean() {
530            return true;
531        }
532    }
533
534    static class SensorPickModel extends PickListModel<Sensor> {
535
536        SensorManager manager = InstanceManager.getDefault(SensorManager.class);
537
538        SensorPickModel() {
539            _name = rb.getString("TitleSensorTable");
540        }
541
542        /** {@inheritDoc} */
543        @Override
544        @Nonnull
545        public Manager<Sensor> getManager() {
546            manager = InstanceManager.sensorManagerInstance();
547            return manager;
548        }
549
550        /** {@inheritDoc} */
551        @Override
552        public Sensor addBean(@Nonnull String name) throws IllegalArgumentException {
553            return manager.provideSensor(name);
554        }
555
556        /** {@inheritDoc} */
557        @Override
558        public Sensor addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException {
559            return manager.newSensor(sysName, userName);
560        }
561
562        /** {@inheritDoc} */
563        @Override
564        public boolean canAddBean() {
565            return true;
566        }
567    }
568
569    static class MultiSensorPickModel extends SensorPickModel {
570
571        private final HashMap<Integer, String> _position = new HashMap<>();
572
573        MultiSensorPickModel() {
574            super();
575        }
576
577        /** {@inheritDoc} */
578        @Override
579        public Object getValueAt(int r, int c) {
580            if (c == POSITION_COL) {
581                return _position.get(r);
582            }
583            return super.getValueAt(r, c);
584        }
585
586        /** {@inheritDoc} */
587        @Override
588        public void setValueAt(Object type, int r, int c) {
589            if (c == POSITION_COL) {
590                _position.put(r, (String) type);
591            }
592        }
593    }
594
595    static class SignalHeadPickModel extends PickListModel<SignalHead> {
596
597        SignalHeadManager manager = InstanceManager.getDefault(SignalHeadManager.class);
598
599        SignalHeadPickModel() {
600            _name = rb.getString("TitleSignalTable");
601        }
602
603        /** {@inheritDoc} */
604        @Override
605        @Nonnull
606        public Manager<SignalHead> getManager() {
607            manager = InstanceManager.getDefault(SignalHeadManager.class);
608            return manager;
609        }
610
611        /** {@inheritDoc} */
612        @Override
613        public SignalHead addBean(@Nonnull String name) {
614            return manager.getSignalHead(name);
615        }
616
617        /** {@inheritDoc} */
618        @Override
619        public SignalHead addBean(@Nonnull String sysName, String userName) {
620            SignalHead sh = manager.getSignalHead(userName);
621            if (sh == null) {
622                sh = manager.getSignalHead(sysName);
623            }
624            return sh;
625        }
626
627        /** {@inheritDoc} */
628        @Override
629        public boolean canAddBean() {
630            return false;
631        }
632    }
633
634    static class SignalMastPickModel extends PickListModel<SignalMast> {
635
636        SignalMastManager manager = InstanceManager.getDefault(SignalMastManager.class);
637
638        SignalMastPickModel() {
639            _name = rb.getString("TitleSignalMastTable");
640        }
641
642        /** {@inheritDoc} */
643        @Override
644        @Nonnull
645        public Manager<SignalMast> getManager() {
646            manager = InstanceManager.getDefault(SignalMastManager.class);
647            return manager;
648        }
649
650        /** {@inheritDoc} */
651        @Override
652        public SignalMast addBean(@Nonnull String name) throws IllegalArgumentException {
653            return manager.provideSignalMast(name);
654        }
655
656        /** {@inheritDoc} */
657        @Override
658        public SignalMast addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException {
659            SignalMast sm = manager.getSignalMast(userName);
660            if (sm == null) {
661                sm = manager.provideSignalMast(sysName);
662            }
663            return sm;
664        }
665
666        /** {@inheritDoc} */
667        @Override
668        public boolean canAddBean() {
669            return false;
670        }
671    }
672
673    static class MemoryPickModel extends PickListModel<Memory> {
674
675        MemoryManager manager = InstanceManager.memoryManagerInstance();
676
677        MemoryPickModel() {
678            _name = rb.getString("TitleMemoryTable");
679        }
680
681        /** {@inheritDoc} */
682        @Override
683        @Nonnull
684        public Manager<Memory> getManager() {
685            manager = InstanceManager.memoryManagerInstance();
686            return manager;
687        }
688
689        /** {@inheritDoc} */
690        @Override
691        public Memory addBean(@Nonnull String name) throws IllegalArgumentException {
692            return manager.provideMemory(name);
693        }
694
695        /** {@inheritDoc} */
696        @Override
697        public Memory addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException {
698            return manager.newMemory(sysName, userName);
699        }
700
701        /** {@inheritDoc} */
702        @Override
703        public boolean canAddBean() {
704            return true;
705        }
706    }
707
708    static class BlockPickModel extends PickListModel<Block> {
709
710        BlockManager manager = InstanceManager.getDefault(BlockManager.class);
711
712        BlockPickModel() {
713            _name = rb.getString("TitleBlockTable");
714        }
715
716        /** {@inheritDoc} */
717        @Override
718        @Nonnull
719        public Manager<Block> getManager() {
720            manager = InstanceManager.getDefault(BlockManager.class);
721            return manager;
722        }
723
724        /** {@inheritDoc} */
725        @Override
726        public Block addBean(@Nonnull String name) throws IllegalArgumentException {
727            return manager.provideBlock(name);
728        }
729
730        /** {@inheritDoc} */
731        @Override
732        public Block addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException {
733            return manager.createNewBlock(sysName, userName);
734        }
735
736        /** {@inheritDoc} */
737        @Override
738        public boolean canAddBean() {
739            return true;
740        }
741    }
742
743    static class ReporterPickModel extends PickListModel<Reporter> {
744
745        ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
746
747        ReporterPickModel() {
748            _name = rb.getString("TitleReporterTable");
749        }
750
751        /** {@inheritDoc} */
752        @Override
753        @Nonnull
754        public Manager<Reporter> getManager() {
755            manager = InstanceManager.getDefault(ReporterManager.class);
756            return manager;
757        }
758
759        /** {@inheritDoc} */
760        @Override
761        public Reporter addBean(@Nonnull String name) throws IllegalArgumentException {
762            return manager.provideReporter(name);
763        }
764
765        /** {@inheritDoc} */
766        @Override
767        public Reporter addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException {
768            return manager.newReporter(sysName, userName);
769        }
770
771        /** {@inheritDoc} */
772        @Override
773        public boolean canAddBean() {
774            return true;
775        }
776    }
777
778    static class LightPickModel extends PickListModel<Light> {
779
780        LightManager manager = InstanceManager.lightManagerInstance();
781
782        LightPickModel() {
783            _name = rb.getString("TitleLightTable");
784        }
785
786        /** {@inheritDoc} */
787        @Override
788        @Nonnull
789        public Manager<Light> getManager() {
790            manager = InstanceManager.lightManagerInstance();
791            return manager;
792        }
793
794        /** {@inheritDoc} */
795        @Override
796        public Light addBean(@Nonnull String name) throws IllegalArgumentException {
797            return manager.provideLight(name);
798        }
799
800        /** {@inheritDoc} */
801        @Override
802        public Light addBean(@Nonnull String sysName, String userName) throws IllegalArgumentException {
803            return manager.newLight(sysName, userName);
804        }
805
806        /** {@inheritDoc} */
807        @Override
808        public boolean canAddBean() {
809            return true;
810        }
811    }
812
813    static class OBlockPickModel extends PickListModel<OBlock> {
814
815        OBlockManager manager = InstanceManager.getDefault(OBlockManager.class);
816
817        OBlockPickModel() {
818            _name = rb.getString("TitleBlockTable");
819        }
820
821        /** {@inheritDoc} */
822        @Override
823        @Nonnull
824        public Manager<OBlock> getManager() {
825            manager = InstanceManager.getDefault(OBlockManager.class);
826            return manager;
827        }
828
829        /** {@inheritDoc} */
830        @Override
831        public OBlock addBean(@Nonnull String name) throws IllegalArgumentException {
832            return manager.provideOBlock(name);
833        }
834
835        /** {@inheritDoc} */
836        @Override
837        public OBlock addBean(@Nonnull String sysName, String userName) {
838            return manager.createNewOBlock(sysName, userName);
839        }
840
841        /** {@inheritDoc} */
842        @Override
843        public boolean canAddBean() {
844            return true;
845        }
846    }
847
848    static class WarrantPickModel extends PickListModel<Warrant> {
849
850        WarrantManager manager = InstanceManager.getDefault(WarrantManager.class);
851
852        WarrantPickModel() {
853            _name = rb.getString("TitleWarrantTable");
854        }
855
856        /** {@inheritDoc} */
857        @Override
858        @Nonnull
859        public Manager<Warrant> getManager() {
860            manager = InstanceManager.getDefault(WarrantManager.class);
861            return manager;
862        }
863
864        /** {@inheritDoc} */
865        @Override
866        public Warrant addBean(@Nonnull String name) throws IllegalArgumentException {
867            return manager.provideWarrant(name);
868        }
869
870        /** {@inheritDoc} */
871        @Override
872        public Warrant addBean(@Nonnull String sysName, String userName) {
873            return manager.createNewWarrant(sysName, userName, false, 0);
874        }
875
876        /** {@inheritDoc} */
877        @Override
878        public boolean canAddBean() {
879            return false;
880        }
881    }
882
883    static class EntryExitPickModel extends PickListModel<DestinationPoints> {
884
885        EntryExitPairs manager = InstanceManager.getDefault(EntryExitPairs.class);
886
887        EntryExitPickModel() {
888            _name = rb.getString("TitleEntryExitTable");
889        }
890
891        /** {@inheritDoc} */
892        @Override
893        @Nonnull
894        public Manager<DestinationPoints> getManager() {
895            manager = InstanceManager.getDefault(EntryExitPairs.class);
896            return manager;
897        }
898
899        /** {@inheritDoc} */
900        @Override
901        public DestinationPoints addBean(@Nonnull String name) {
902            return null;
903        }
904
905        /** {@inheritDoc} */
906        @Override
907        public DestinationPoints addBean(@Nonnull String sysName, String userName) {
908            return null;
909        }
910
911        /** {@inheritDoc} */
912        @Override
913        public boolean canAddBean() {
914            return false;
915        }
916
917        /** {@inheritDoc} */
918        @Override
919        public String getColumnName(int c) {
920            if (c == SNAME_COLUMN) {
921                return "Unique Id";
922            } else if (c == UNAME_COLUMN) {
923                return Bundle.getMessage("ColumnUserName");
924            }
925            return "";
926        }
927    }
928
929    static class LogixPickModel extends PickListModel<Logix> {
930
931        LogixManager manager;
932
933        LogixPickModel() {
934           _name = rb.getString("TitleLogixTable");
935        }
936
937        /** {@inheritDoc} */
938        @Override
939        @Nonnull
940        public Manager<Logix> getManager() {
941            manager = InstanceManager.getDefault(LogixManager.class);
942            return manager;
943        }
944
945        /** {@inheritDoc} */
946        @Override
947        public Logix addBean(@Nonnull String name) {
948            return null;
949        }
950
951        /** {@inheritDoc} */
952        @Override
953        public Logix addBean(@Nonnull String sysName, String userName) {
954            return null;
955        }
956
957        /** {@inheritDoc} */
958        @Override
959        public boolean canAddBean() {
960            return false;
961        }
962    }
963
964}