001package jmri.jmrix.loconet.swing;
002
003import jmri.*;
004import jmri.implementation.DccSignalMast;
005import jmri.jmrit.beantable.signalmast.SignalMastAddPane;
006import jmri.jmrix.loconet.LNCPSignalMast;
007import jmri.jmrix.loconet.SlotManager;
008
009import javax.annotation.Nonnull;
010
011import org.openide.util.lookup.ServiceProvider;
012
013/**
014 * A pane for configuring LNCPSignalMast objects
015 *
016 * @see jmri.jmrit.beantable.signalmast.SignalMastAddPane
017 * @author Bob Jacobsen Copyright (C) 2018
018 * @since 4.11.2
019 */
020public class LNCPSignalMastAddPane extends jmri.jmrit.beantable.signalmast.DccSignalMastAddPane {
021
022    public LNCPSignalMastAddPane() {
023        super();
024    }
025    
026    /** {@inheritDoc} */
027    @Override
028    @Nonnull public String getPaneName() {
029        return Bundle.getMessage("LNCPMast");
030    }
031
032    /** {@inheritDoc} */
033    @Override
034    public boolean canHandleMast(@Nonnull SignalMast mast) {
035        return mast instanceof LNCPSignalMast;
036    }
037
038    /** {@inheritDoc} */
039    @Override
040    protected String getNamePrefix() {
041        return "F$lncpsm:";
042    }
043
044    /** {@inheritDoc} */
045    @Override
046    protected DccSignalMast constructMast(String name) {
047        return new LNCPSignalMast(name);
048    }
049
050    /** {@inheritDoc} */
051    @Override
052    protected boolean usableCommandStation(CommandStation cs) {
053        return cs instanceof jmri.jmrix.loconet.SlotManager;
054    }
055
056    @ServiceProvider(service = SignalMastAddPane.SignalMastAddPaneProvider.class)
057    static public class SignalMastAddPaneProvider extends SignalMastAddPane.SignalMastAddPaneProvider {
058        /**
059         * {@inheritDoc}
060         * Requires a valid LocoNet connection
061         */
062        @Override
063        public boolean isAvailable() {
064            for (CommandStation c : InstanceManager.getList(CommandStation.class)) {
065                if (c instanceof SlotManager) {
066                    return true;
067                }
068            }
069            return false;
070        }
071
072        /** {@inheritDoc} */
073        @Override
074        @Nonnull public String getPaneName() {
075            return Bundle.getMessage("LNCPMast");
076        }
077        /** {@inheritDoc} */
078        @Override
079        @Nonnull public SignalMastAddPane getNewPane() {
080            return new LNCPSignalMastAddPane();
081        }
082    }
083}