Search in sources :

Example 1 with BoundsPopupMenuListener

use of org.opentcs.util.gui.BoundsPopupMenuListener in project opentcs by openTCS.

the class DriverGUI method initCommAdaptersComboBox.

private void initCommAdaptersComboBox(LocalVehicleEntry vehicleEntry, int rowIndex, SingleCellEditor adapterCellEditor) {
    final CommAdapterComboBox comboBox = new CommAdapterComboBox();
    AttachmentInformation ai;
    try {
        ai = callWrapper.call(() -> servicePortal.getVehicleService().fetchAttachmentInformation(vehicleEntry.getAttachmentInformation().getVehicleReference()));
    } catch (Exception ex) {
        LOG.warn("Error fetching attachment information for {}", vehicleEntry.getVehicleName(), ex);
        return;
    }
    ai.getAvailableCommAdapters().forEach(factory -> comboBox.addItem(factory));
    // Set the selection to the attached comm adapter, (The vehicle is already attached to a comm
    // adapter due to auto attachment on startup.)
    comboBox.setSelectedItem(vehicleEntry.getAttachmentInformation().getAttachedCommAdapter());
    comboBox.setRenderer(new AdapterFactoryCellRenderer());
    comboBox.addPopupMenuListener(new BoundsPopupMenuListener());
    comboBox.addItemListener((ItemEvent evt) -> {
        if (evt.getStateChange() == ItemEvent.DESELECTED) {
            return;
        }
        // If we selected a comm adapter that's already attached, do nothing.
        if (Objects.equals(evt.getItem(), vehicleEntry.getAttachedCommAdapterDescription())) {
            LOG.debug("{} is already attached to: {}", vehicleEntry.getVehicleName(), evt.getItem());
            return;
        }
        int reply = JOptionPane.showConfirmDialog(null, bundle.getString("driverGui.optionPane_driverChangeConfirmation.message"), bundle.getString("driverGui.optionPane_driverChangeConfirmation.title"), JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.NO_OPTION) {
            return;
        }
        VehicleCommAdapterDescription factory = comboBox.getSelectedItem();
        try {
            callWrapper.call(() -> servicePortal.getVehicleService().attachCommAdapter(vehicleEntry.getAttachmentInformation().getVehicleReference(), factory));
        } catch (Exception ex) {
            LOG.warn("Error attaching adapter {} to vehicle {}", factory, vehicleEntry.getVehicleName(), ex);
            return;
        }
        LOG.info("Attaching comm adapter {} to {}", factory, vehicleEntry.getVehicleName());
    });
    adapterCellEditor.setEditorAt(rowIndex, new DefaultCellEditor(comboBox));
    vehicleEntry.addPropertyChangeListener(comboBox);
}
Also used : ItemEvent(java.awt.event.ItemEvent) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) BoundsPopupMenuListener(org.opentcs.util.gui.BoundsPopupMenuListener) Point(org.opentcs.data.model.Point) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 2 with BoundsPopupMenuListener

use of org.opentcs.util.gui.BoundsPopupMenuListener in project OpenTCS-4 by touchmii.

the class DriverGUI method initCommAdaptersComboBox.

private void initCommAdaptersComboBox(VehicleEntry vehicleEntry, int rowIndex, SingleCellEditor adapterCellEditor) {
    final CommAdapterComboBox comboBox = new CommAdapterComboBox();
    commAdapterRegistry.findFactoriesFor(vehicleEntry.getVehicle()).forEach(factory -> comboBox.addItem(factory));
    // Set the selection to the attached comm adapter, (The vehicle is already attached to a comm
    // adapter due to auto attachment on startup.)
    comboBox.setSelectedItem(vehicleEntry.getCommAdapterFactory());
    comboBox.setRenderer(new AdapterFactoryCellRenderer());
    comboBox.addPopupMenuListener(new BoundsPopupMenuListener());
    comboBox.addItemListener((ItemEvent evt) -> {
        if (evt.getStateChange() == ItemEvent.DESELECTED) {
            return;
        }
        // If we selected a comm adapter that's already attached, do nothing.
        if (Objects.equals(evt.getItem(), vehicleEntry.getCommAdapterFactory())) {
            LOG.debug("{} is already attached to: {}", vehicleEntry.getVehicleName(), evt.getItem());
            return;
        }
        int reply = JOptionPane.showConfirmDialog(null, bundle.getString("CommAdapterComboBox.confirmation.driverChange.text"), bundle.getString("CommAdapterComboBox.confirmation.driverChange.title"), JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.NO_OPTION) {
            return;
        }
        attachManager.attachAdapterToVehicle(getSelectedVehicleName(), (VehicleCommAdapterFactory) comboBox.getSelectedItem());
    });
    adapterCellEditor.setEditorAt(rowIndex, new DefaultCellEditor(comboBox));
    vehicleEntry.addPropertyChangeListener(comboBox);
}
Also used : ItemEvent(java.awt.event.ItemEvent) BoundsPopupMenuListener(org.opentcs.util.gui.BoundsPopupMenuListener) Point(org.opentcs.data.model.Point) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 3 with BoundsPopupMenuListener

use of org.opentcs.util.gui.BoundsPopupMenuListener in project OpenTCS-4 by touchmii.

the class DriverGUI method initCommAdaptersComboBox.

private void initCommAdaptersComboBox(LocalVehicleEntry vehicleEntry, int rowIndex, SingleCellEditor adapterCellEditor) {
    final CommAdapterComboBox comboBox = new CommAdapterComboBox();
    AttachmentInformation ai;
    try {
        ai = callWrapper.call(() -> servicePortal.getVehicleService().fetchAttachmentInformation(vehicleEntry.getAttachmentInformation().getVehicleReference()));
    } catch (Exception ex) {
        LOG.warn("Error fetching attachment information for {}", vehicleEntry.getVehicleName(), ex);
        return;
    }
    ai.getAvailableCommAdapters().forEach(factory -> comboBox.addItem(factory));
    // Set the selection to the attached comm adapter, (The vehicle is already attached to a comm
    // adapter due to auto attachment on startup.)
    comboBox.setSelectedItem(vehicleEntry.getAttachmentInformation().getAttachedCommAdapter());
    comboBox.setRenderer(new AdapterFactoryCellRenderer());
    comboBox.addPopupMenuListener(new BoundsPopupMenuListener());
    comboBox.addItemListener((ItemEvent evt) -> {
        if (evt.getStateChange() == ItemEvent.DESELECTED) {
            return;
        }
        // If we selected a comm adapter that's already attached, do nothing.
        if (Objects.equals(evt.getItem(), vehicleEntry.getAttachedCommAdapterDescription())) {
            LOG.debug("{} is already attached to: {}", vehicleEntry.getVehicleName(), evt.getItem());
            return;
        }
        int reply = JOptionPane.showConfirmDialog(null, bundle.getString("driverGui.optionPane_driverChangeConfirmation.message"), bundle.getString("driverGui.optionPane_driverChangeConfirmation.title"), JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.NO_OPTION) {
            return;
        }
        VehicleCommAdapterDescription factory = comboBox.getSelectedItem();
        try {
            callWrapper.call(() -> servicePortal.getVehicleService().attachCommAdapter(vehicleEntry.getAttachmentInformation().getVehicleReference(), factory));
        } catch (Exception ex) {
            LOG.warn("Error attaching adapter {} to vehicle {}", factory, vehicleEntry.getVehicleName(), ex);
            return;
        }
        LOG.info("Attaching comm adapter {} to {}", factory, vehicleEntry.getVehicleName());
    });
    adapterCellEditor.setEditorAt(rowIndex, new DefaultCellEditor(comboBox));
    vehicleEntry.addPropertyChangeListener(comboBox);
}
Also used : ItemEvent(java.awt.event.ItemEvent) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) BoundsPopupMenuListener(org.opentcs.util.gui.BoundsPopupMenuListener) Point(org.opentcs.data.model.Point) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

ItemEvent (java.awt.event.ItemEvent)3 DefaultCellEditor (javax.swing.DefaultCellEditor)3 Point (org.opentcs.data.model.Point)3 BoundsPopupMenuListener (org.opentcs.util.gui.BoundsPopupMenuListener)3 VehicleCommAdapterDescription (org.opentcs.drivers.vehicle.VehicleCommAdapterDescription)2 AttachmentInformation (org.opentcs.drivers.vehicle.management.AttachmentInformation)2