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);
}
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);
}
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);
}
Aggregations