use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription in project OpenTCS-4 by touchmii.
the class AttachmentManager method initAttachmentPool.
private void initAttachmentPool() {
vehicleEntryPool.getEntries().forEach((vehicleName, entry) -> {
List<VehicleCommAdapterDescription> availableCommAdapters = commAdapterRegistry.getFactories().stream().filter(f -> f.providesAdapterFor(entry.getVehicle())).map(f -> f.getDescription()).collect(Collectors.toList());
attachmentPool.put(vehicleName, new AttachmentInformation(entry.getVehicle().getReference(), availableCommAdapters, new DefaultVehicleCommAdapterDescription("-")));
});
}
use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription in project OpenTCS-4 by touchmii.
the class DriverGUI method createDriverMenu.
private void createDriverMenu() {
driverMenu.removeAll();
// Collect all available comm adapters/factories
Set<VehicleCommAdapterDescription> availableDescriptions = new HashSet<>();
vehicleEntryPool.getEntries().forEach((vehicleName, entry) -> {
availableDescriptions.addAll(entry.getAttachmentInformation().getAvailableCommAdapters());
});
for (VehicleCommAdapterDescription description : availableDescriptions) {
// If there's one vehicle not supported by this factory the selection can't be attached to it
boolean factorySupportsSelectedVehicles = getSelectedVehicleEntries().stream().map(entry -> entry.getAttachmentInformation().getAvailableCommAdapters()).allMatch(descriptions -> !Collections.disjoint(descriptions, availableDescriptions));
List<String> vehiclesToAttach = new ArrayList<>();
if (factorySupportsSelectedVehicles) {
vehiclesToAttach = getSelectedVehicleNames();
}
Action action = new AttachCommAdapterAction(vehiclesToAttach, description);
JMenuItem menuItem = driverMenu.add(action);
menuItem.setEnabled(!vehiclesToAttach.isEmpty());
}
}
use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription 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.drivers.vehicle.VehicleCommAdapterDescription 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);
}
use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription in project opentcs by openTCS.
the class AttachmentManager method initAttachmentPool.
private void initAttachmentPool() {
vehicleEntryPool.getEntries().forEach((vehicleName, entry) -> {
List<VehicleCommAdapterDescription> availableCommAdapters = commAdapterRegistry.getFactories().stream().filter(f -> f.providesAdapterFor(entry.getVehicle())).map(f -> f.getDescription()).collect(Collectors.toList());
attachmentPool.put(vehicleName, new AttachmentInformation(entry.getVehicle().getReference(), availableCommAdapters, new NullVehicleCommAdapterDescription()));
});
}
Aggregations